Skip to content

Commit

Permalink
test(parser): add cases for parsing constants and mutable variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Mar 7, 2024
1 parent dc0c896 commit fb6c6e3
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: crates/fuse-parser/tests/cases/mod.rs
expression: parsed.chunk
input_file: crates/fuse-parser/tests/cases/pass/variable-declaration-03/case.fuse
---
Some(Chunk(
span: Span(
start: 0,
end: 18,
),
body: Block(
statements: [
VariableDeclaration(VariableDeclaration(
span: Span(
start: 0,
end: 17,
),
kind: Let,
binding: BindingPattern(
kind: Identifier(BindingIdentifier(
span: Span(
start: 4,
end: 11,
),
atom: Atom("num"),
mutable: true,
)),
type_annotation: None,
optional: false,
),
expression: Some(NumberLiteral(NumberLiteral(
span: Span(
start: 14,
end: 17,
),
raw: Atom("123"),
value: 123.0,
kind: Decimal,
))),
)),
],
),
))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let mut num = 123
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
source: crates/fuse-parser/tests/cases/mod.rs
expression: tokens
input_file: crates/fuse-parser/tests/cases/pass/variable-declaration-03/case.fuse
---
[
TokenReference(
token: Token(
span: Span(
start: 0,
end: 3,
),
kind: Let,
),
leading_trivia: [],
trailing_trivia: [
Token(
span: Span(
start: 3,
end: 4,
),
kind: Whitespace,
),
],
),
TokenReference(
token: Token(
span: Span(
start: 4,
end: 7,
),
kind: Mut,
),
leading_trivia: [],
trailing_trivia: [
Token(
span: Span(
start: 7,
end: 8,
),
kind: Whitespace,
),
],
),
TokenReference(
token: Token(
span: Span(
start: 8,
end: 11,
),
kind: Identifier,
),
leading_trivia: [],
trailing_trivia: [
Token(
span: Span(
start: 11,
end: 12,
),
kind: Whitespace,
),
],
),
TokenReference(
token: Token(
span: Span(
start: 12,
end: 13,
),
kind: Eq,
),
leading_trivia: [],
trailing_trivia: [
Token(
span: Span(
start: 13,
end: 14,
),
kind: Whitespace,
),
],
),
TokenReference(
token: Token(
span: Span(
start: 14,
end: 17,
),
kind: NumberLiteral,
),
leading_trivia: [],
trailing_trivia: [
Token(
span: Span(
start: 17,
end: 18,
),
kind: Whitespace,
),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: crates/fuse-parser/tests/cases/mod.rs
expression: parsed.chunk
input_file: crates/fuse-parser/tests/cases/pass/variable-declaration-04/case.fuse
---
Some(Chunk(
span: Span(
start: 0,
end: 16,
),
body: Block(
statements: [
VariableDeclaration(VariableDeclaration(
span: Span(
start: 0,
end: 15,
),
kind: Const,
binding: BindingPattern(
kind: Identifier(BindingIdentifier(
span: Span(
start: 6,
end: 8,
),
atom: Atom("PI"),
mutable: false,
)),
type_annotation: None,
optional: false,
),
expression: Some(NumberLiteral(NumberLiteral(
span: Span(
start: 11,
end: 15,
),
raw: Atom("3.14"),
value: 3.14,
kind: Float,
))),
)),
],
),
))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const PI = 3.14
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
source: crates/fuse-parser/tests/cases/mod.rs
expression: tokens
input_file: crates/fuse-parser/tests/cases/pass/variable-declaration-04/case.fuse
---
[
TokenReference(
token: Token(
span: Span(
start: 0,
end: 5,
),
kind: Const,
),
leading_trivia: [],
trailing_trivia: [
Token(
span: Span(
start: 5,
end: 6,
),
kind: Whitespace,
),
],
),
TokenReference(
token: Token(
span: Span(
start: 6,
end: 8,
),
kind: Identifier,
),
leading_trivia: [],
trailing_trivia: [
Token(
span: Span(
start: 8,
end: 9,
),
kind: Whitespace,
),
],
),
TokenReference(
token: Token(
span: Span(
start: 9,
end: 10,
),
kind: Eq,
),
leading_trivia: [],
trailing_trivia: [
Token(
span: Span(
start: 10,
end: 11,
),
kind: Whitespace,
),
],
),
TokenReference(
token: Token(
span: Span(
start: 11,
end: 15,
),
kind: NumberLiteral,
),
leading_trivia: [],
trailing_trivia: [
Token(
span: Span(
start: 15,
end: 16,
),
kind: Whitespace,
),
],
),
]

0 comments on commit fb6c6e3

Please sign in to comment.