-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add snapshot testing for statement parsing
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
Showing
32 changed files
with
1,380 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
source: src/nasl/syntax/statement.rs | ||
expression: stmt | ||
snapshot_kind: text | ||
--- | ||
Statement( | ||
start: Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 1), | ||
position: (0, 1), | ||
), | ||
end: Some(Token( | ||
category: Semicolon, | ||
line_column: (1, 6), | ||
position: (5, 6), | ||
)), | ||
kind: Operator(Plus, [ | ||
Statement( | ||
start: Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 1), | ||
position: (0, 1), | ||
), | ||
end: Some(Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 1), | ||
position: (0, 1), | ||
)), | ||
kind: Variable, | ||
), | ||
Statement( | ||
start: Token( | ||
category: Number(1), | ||
line_column: (1, 5), | ||
position: (4, 5), | ||
), | ||
end: Some(Token( | ||
category: Semicolon, | ||
line_column: (1, 6), | ||
position: (5, 6), | ||
)), | ||
kind: Primitive, | ||
), | ||
]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
source: src/nasl/syntax/statement.rs | ||
expression: stmt | ||
snapshot_kind: text | ||
--- | ||
Statement( | ||
start: Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 1), | ||
position: (0, 1), | ||
), | ||
end: Some(Token( | ||
category: Semicolon, | ||
line_column: (1, 5), | ||
position: (4, 5), | ||
)), | ||
kind: Array(Some(Statement( | ||
start: Token( | ||
category: Number(1), | ||
line_column: (1, 3), | ||
position: (2, 3), | ||
), | ||
end: Some(Token( | ||
category: RightBrace, | ||
line_column: (1, 4), | ||
position: (3, 4), | ||
)), | ||
kind: Primitive, | ||
))), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
source: src/nasl/syntax/statement.rs | ||
expression: stmt | ||
snapshot_kind: text | ||
--- | ||
Statement( | ||
start: Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 1), | ||
position: (0, 1), | ||
), | ||
end: Some(Token( | ||
category: Semicolon, | ||
line_column: (1, 6), | ||
position: (5, 6), | ||
)), | ||
kind: Assign(Equal, AssignReturn, Statement( | ||
start: Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 1), | ||
position: (0, 1), | ||
), | ||
end: Some(Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 1), | ||
position: (0, 1), | ||
)), | ||
kind: Variable, | ||
), Statement( | ||
start: Token( | ||
category: Number(1), | ||
line_column: (1, 5), | ||
position: (4, 5), | ||
), | ||
end: Some(Token( | ||
category: Semicolon, | ||
line_column: (1, 6), | ||
position: (5, 6), | ||
)), | ||
kind: Primitive, | ||
)), | ||
) |
38 changes: 38 additions & 0 deletions
38
rust/src/nasl/syntax/snapshots/statement_assign_return.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
source: src/nasl/syntax/statement.rs | ||
expression: stmt | ||
snapshot_kind: text | ||
--- | ||
Statement( | ||
start: Token( | ||
category: MinusMinus, | ||
line_column: (1, 1), | ||
position: (0, 2), | ||
), | ||
end: Some(Token( | ||
category: Semicolon, | ||
line_column: (1, 4), | ||
position: (3, 4), | ||
)), | ||
kind: Assign(MinusMinus, AssignReturn, Statement( | ||
start: Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 3), | ||
position: (2, 3), | ||
), | ||
end: Some(Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 3), | ||
position: (2, 3), | ||
)), | ||
kind: Variable, | ||
), Statement( | ||
start: Token( | ||
category: UnknownSymbol, | ||
line_column: (0, 0), | ||
position: (0, 0), | ||
), | ||
end: None, | ||
kind: NoOp, | ||
)), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
source: src/nasl/syntax/statement.rs | ||
expression: stmt | ||
snapshot_kind: text | ||
--- | ||
Statement( | ||
start: Token( | ||
category: LeftCurlyBracket, | ||
line_column: (1, 1), | ||
position: (0, 1), | ||
), | ||
end: Some(Token( | ||
category: RightCurlyBracket, | ||
line_column: (1, 6), | ||
position: (5, 6), | ||
)), | ||
kind: Block([ | ||
Statement( | ||
start: Token( | ||
category: Identifier(Undefined("a")), | ||
line_column: (1, 3), | ||
position: (2, 3), | ||
), | ||
end: Some(Token( | ||
category: Semicolon, | ||
line_column: (1, 4), | ||
position: (3, 4), | ||
)), | ||
kind: Variable, | ||
), | ||
]), | ||
) |
Oops, something went wrong.