-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(parser): few tests for function declaration.
- Loading branch information
Showing
6 changed files
with
469 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
crates/fuse-parser/tests/cases/pass/function-declaration-02/ast.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,100 @@ | ||
--- | ||
source: crates/fuse-parser/tests/cases/mod.rs | ||
expression: parsed.chunk | ||
input_file: crates/fuse-parser/tests/cases/pass/function-declaration-02/case.fuse | ||
--- | ||
Some(Chunk( | ||
span: Span( | ||
start: 0, | ||
end: 31, | ||
), | ||
body: Block( | ||
statements: [ | ||
FunctionDeclaration(Function( | ||
span: Span( | ||
start: 0, | ||
end: 26, | ||
), | ||
identifier: Some(Identifier( | ||
span: Span( | ||
start: 9, | ||
end: 13, | ||
), | ||
name: Atom("test"), | ||
)), | ||
params: FunctionParameters( | ||
span: Span( | ||
start: 13, | ||
end: 23, | ||
), | ||
items: [ | ||
FunctionParameter( | ||
span: Span( | ||
start: 14, | ||
end: 15, | ||
), | ||
pattern: BindingPattern( | ||
kind: Identifier(BindingIdentifier( | ||
span: Span( | ||
start: 14, | ||
end: 15, | ||
), | ||
atom: Atom("a"), | ||
)), | ||
type_annotation: None, | ||
optional: false, | ||
), | ||
), | ||
FunctionParameter( | ||
span: Span( | ||
start: 17, | ||
end: 18, | ||
), | ||
pattern: BindingPattern( | ||
kind: Identifier(BindingIdentifier( | ||
span: Span( | ||
start: 17, | ||
end: 18, | ||
), | ||
atom: Atom("b"), | ||
)), | ||
type_annotation: None, | ||
optional: false, | ||
), | ||
), | ||
FunctionParameter( | ||
span: Span( | ||
start: 20, | ||
end: 21, | ||
), | ||
pattern: BindingPattern( | ||
kind: Identifier(BindingIdentifier( | ||
span: Span( | ||
start: 20, | ||
end: 21, | ||
), | ||
atom: Atom("c"), | ||
)), | ||
type_annotation: None, | ||
optional: false, | ||
), | ||
), | ||
], | ||
rest: None, | ||
), | ||
return_type: None, | ||
body: Block(Block( | ||
statements: [ | ||
Expression(Identifier(Identifier( | ||
span: Span( | ||
start: 25, | ||
end: 26, | ||
), | ||
name: Atom("b"), | ||
))), | ||
], | ||
)), | ||
)), | ||
], | ||
), | ||
)) |
3 changes: 3 additions & 0 deletions
3
crates/fuse-parser/tests/cases/pass/function-declaration-02/case.fuse
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,3 @@ | ||
function test(a, b, c,) | ||
b | ||
end |
187 changes: 187 additions & 0 deletions
187
crates/fuse-parser/tests/cases/pass/function-declaration-02/tokens.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,187 @@ | ||
--- | ||
source: crates/fuse-parser/tests/cases/mod.rs | ||
expression: tokens | ||
input_file: crates/fuse-parser/tests/cases/pass/function-declaration-02/case.fuse | ||
--- | ||
[ | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 0, | ||
end: 8, | ||
), | ||
kind: Function, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [ | ||
Token( | ||
span: Span( | ||
start: 8, | ||
end: 9, | ||
), | ||
kind: Whitespace, | ||
), | ||
], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 9, | ||
end: 13, | ||
), | ||
kind: Identifier, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 13, | ||
end: 14, | ||
), | ||
kind: LParen, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 14, | ||
end: 15, | ||
), | ||
kind: Identifier, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 15, | ||
end: 16, | ||
), | ||
kind: Comma, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [ | ||
Token( | ||
span: Span( | ||
start: 16, | ||
end: 17, | ||
), | ||
kind: Whitespace, | ||
), | ||
], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 17, | ||
end: 18, | ||
), | ||
kind: Identifier, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 18, | ||
end: 19, | ||
), | ||
kind: Comma, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [ | ||
Token( | ||
span: Span( | ||
start: 19, | ||
end: 20, | ||
), | ||
kind: Whitespace, | ||
), | ||
], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 20, | ||
end: 21, | ||
), | ||
kind: Identifier, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 21, | ||
end: 22, | ||
), | ||
kind: Comma, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 22, | ||
end: 23, | ||
), | ||
kind: RParen, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [ | ||
Token( | ||
span: Span( | ||
start: 23, | ||
end: 25, | ||
), | ||
kind: Whitespace, | ||
), | ||
], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 25, | ||
end: 26, | ||
), | ||
kind: Identifier, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [ | ||
Token( | ||
span: Span( | ||
start: 26, | ||
end: 27, | ||
), | ||
kind: Whitespace, | ||
), | ||
], | ||
), | ||
TokenReference( | ||
token: Token( | ||
span: Span( | ||
start: 27, | ||
end: 30, | ||
), | ||
kind: End, | ||
), | ||
leading_trivia: [], | ||
trailing_trivia: [ | ||
Token( | ||
span: Span( | ||
start: 30, | ||
end: 31, | ||
), | ||
kind: Whitespace, | ||
), | ||
], | ||
), | ||
] |
62 changes: 62 additions & 0 deletions
62
crates/fuse-parser/tests/cases/pass/function-declaration-03/ast.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,62 @@ | ||
--- | ||
source: crates/fuse-parser/tests/cases/mod.rs | ||
expression: parsed.chunk | ||
input_file: crates/fuse-parser/tests/cases/pass/function-declaration-03/case.fuse | ||
--- | ||
Some(Chunk( | ||
span: Span( | ||
start: 0, | ||
end: 16, | ||
), | ||
body: Block( | ||
statements: [ | ||
FunctionDeclaration(Function( | ||
span: Span( | ||
start: 0, | ||
end: 15, | ||
), | ||
identifier: Some(Identifier( | ||
span: Span( | ||
start: 3, | ||
end: 7, | ||
), | ||
name: Atom("test"), | ||
)), | ||
params: FunctionParameters( | ||
span: Span( | ||
start: 7, | ||
end: 10, | ||
), | ||
items: [ | ||
FunctionParameter( | ||
span: Span( | ||
start: 8, | ||
end: 9, | ||
), | ||
pattern: BindingPattern( | ||
kind: Identifier(BindingIdentifier( | ||
span: Span( | ||
start: 8, | ||
end: 9, | ||
), | ||
atom: Atom("a"), | ||
)), | ||
type_annotation: None, | ||
optional: false, | ||
), | ||
), | ||
], | ||
rest: None, | ||
), | ||
return_type: None, | ||
body: Expression(Identifier(Identifier( | ||
span: Span( | ||
start: 14, | ||
end: 15, | ||
), | ||
name: Atom("a"), | ||
))), | ||
)), | ||
], | ||
), | ||
)) |
1 change: 1 addition & 0 deletions
1
crates/fuse-parser/tests/cases/pass/function-declaration-03/case.fuse
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 @@ | ||
fn test(a) => a |
Oops, something went wrong.