Skip to content

Commit

Permalink
Add snapshot testing for statement parsing
Browse files Browse the repository at this point in the history
For statements it is hard to write any unit tests, as a statement is a rather complex struct also containing some meta information. It is much easier to test the statement parsing, looking at the generated statement and review it instead.
  • Loading branch information
Kraemii committed Dec 17, 2024
1 parent f7eabb4 commit bfd0ad2
Show file tree
Hide file tree
Showing 32 changed files with 401 additions and 5 deletions.
62 changes: 62 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ members = ["crates/smoketest", "crates/nasl-function-proc-macro"]
tracing-test = "0.2.5"
criterion = "0"
once_cell = "1.20.1"
insta = { version = "1.41.1", features = ["ron"] }

[features]
dep-graph-parallel = ["rayon", "crossbeam-channel"]
Expand Down
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_add.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a + 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_array.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a[1]
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_assign.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a = 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_assign_return.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
--a
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_block.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
{ ... }
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_break.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
break
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_call.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a();
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_continue.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
continue
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_declare.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
local_var a
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_div.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a / 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_exit.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
exit(0);
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_for.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
for (i = 0; i < 10; i++) { a }
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_foreach.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
foreach a(b) {c}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
function a((b)) { ... }
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_if.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
if (a) b else c
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_include.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
include("test.inc");
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_modulo.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a % 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_mul.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a * 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_named_parameter.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a: b
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_no_op.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
NoOp
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_parameter.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
(a, b)
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_primitive.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_repeat.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
repeat a until b
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_return.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
return 0;
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_return_assign.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a++
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_sub.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a - 1
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_variable.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
a
6 changes: 6 additions & 0 deletions rust/src/nasl/syntax/snapshots/statement_while.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/nasl/syntax/statement.rs
expression: stmt
snapshot_kind: text
---
while (a) {b}
Loading

0 comments on commit bfd0ad2

Please sign in to comment.