Skip to content

Commit

Permalink
test(parser): few tests for function declaration.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Mar 4, 2024
1 parent 7a1ea1a commit 21a38b7
Show file tree
Hide file tree
Showing 6 changed files with 469 additions and 0 deletions.
100 changes: 100 additions & 0 deletions crates/fuse-parser/tests/cases/pass/function-declaration-02/ast.snap
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"),
))),
],
)),
)),
],
),
))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function test(a, b, c,)
b
end
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,
),
],
),
]
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"),
))),
)),
],
),
))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn test(a) => a
Loading

0 comments on commit 21a38b7

Please sign in to comment.