Skip to content

Commit

Permalink
parser: add tests for bool and float
Browse files Browse the repository at this point in the history
Signed-off-by: FedericoBruzzone <[email protected]>
  • Loading branch information
FedericoBruzzone committed Sep 16, 2024
1 parent cf019e9 commit 947c6b2
Show file tree
Hide file tree
Showing 7 changed files with 533 additions and 108 deletions.
7 changes: 6 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ pub mod tests {
|| p.ends_with("id_int_assign_2.fs")
|| p.ends_with("comment.fs")
|| p.ends_with("comment_and_id_int.fs")
|| p.ends_with("id_int_assign_with_len_one.fs")
|| p.ends_with("id_int_assign_with_spaces.fs")
|| p.ends_with("id_float_assign.fs")
|| p.ends_with("id_bool_true_assign.fs")
|| p.ends_with("id_bool_false_assign.fs")
});

for path in fs_files {
Expand All @@ -380,7 +385,7 @@ pub mod tests {
let output_ast = Parser::new(Lexer::new(&source)).parse();
let ast_file = fs_file.to_string().replace(".fs", ".ast.json");
let json_ast = std::fs::File::open(ast_file).unwrap();
// println!("{}", serde_json::to_string(&output_ast).unwrap());
println!("{}", serde_json::to_string(&output_ast).unwrap());
let expected_ast = serde_json::from_reader(json_ast).unwrap();
assert_eq!(output_ast, expected_ast);
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser/old_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,15 @@ pub mod tests {
let fs_files = fs_files.iter().filter(|p| {
p.ends_with("id_int_assign.fs")
|| p.ends_with("id_int_assign_2.fs")
|| p.ends_with("comment.fs")
|| p.ends_with("comment_and_id_int.fs")
|| p.ends_with("id_int_assign_with_len_one.fs")
|| p.ends_with("id_int_assign_with_spaces.fs")
|| p.ends_with("id_float_assign.fs")
|| p.ends_with("id_bool_true_assign.fs")
|| p.ends_with("id_bool_false_assign.fs")
|| p.ends_with("id_str_assign.fs")
|| p.ends_with("id_str_assign_multiple_words.fs")
|| p.ends_with("comment.fs")
|| p.ends_with("comment_and_id_int.fs")
});

for path in fs_files {
Expand Down
126 changes: 105 additions & 21 deletions testdata/native_types/id_bool_false_assign.ast.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,117 @@
{
"stmts": [
"kind": "File",
"children": [
{
"Assign": {
"lhs": {
"Identifier": {
"name": "_x_bool",
"location": {
"file_path": "",
"line": 0,
"column_start": 0,
"column_end": 7
"Tree": {
"kind": "StmtVarDecl",
"children": [
{
"Token": {
"kind": "TokenIdentifier",
"lexeme": "_x_bool",
"location": {
"file_path": "",
"line": 0,
"column_start": 0,
"column_end": 7
}
}
}
},
"type_": "Bool",
"rhs": {
"Ok": {
"Literal": {
"literal": {
"Bool": false
},
},
{
"Token": {
"kind": "TokenColon",
"lexeme": ":",
"location": {
"file_path": "",
"line": 0,
"column_start": 7,
"column_end": 8
}
}
},
{
"Tree": {
"kind": "TypeExpr",
"children": [
{
"Token": {
"kind": "TokenIdentifier",
"lexeme": "bool",
"location": {
"file_path": "",
"line": 0,
"column_start": 9,
"column_end": 13
}
}
}
]
}
},
{
"Token": {
"kind": "TokenAssign",
"lexeme": "=",
"location": {
"file_path": "",
"line": 0,
"column_start": 16,
"column_end": 21
"column_start": 14,
"column_end": 15
}
}
},
{
"Tree": {
"kind": "StmtExpr",
"children": [
{
"Tree": {
"kind": "ExprLiteral",
"children": [
{
"Token": {
"kind": {
"TokenLiteral": "Bool"
},
"lexeme": "false",
"location": {
"file_path": "",
"line": 0,
"column_start": 16,
"column_end": 21
}
}
}
]
}
},
{
"Token": {
"kind": "TokenNewLine",
"lexeme": "\\n",
"location": {
"file_path": "",
"line": 0,
"column_start": 21,
"column_end": 21
}
}
}
]
}
}
]
}
},
{
"Token": {
"kind": "TokenEOF",
"lexeme": "",
"location": {
"file_path": "",
"line": 1,
"column_start": 0,
"column_end": 0
}
}
}
Expand Down
126 changes: 105 additions & 21 deletions testdata/native_types/id_bool_true_assign.ast.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,117 @@
{
"stmts": [
"kind": "File",
"children": [
{
"Assign": {
"lhs": {
"Identifier": {
"name": "_x_bool",
"location": {
"file_path": "",
"line": 0,
"column_start": 0,
"column_end": 7
"Tree": {
"kind": "StmtVarDecl",
"children": [
{
"Token": {
"kind": "TokenIdentifier",
"lexeme": "_x_bool",
"location": {
"file_path": "",
"line": 0,
"column_start": 0,
"column_end": 7
}
}
}
},
"type_": "Bool",
"rhs": {
"Ok": {
"Literal": {
"literal": {
"Bool": true
},
},
{
"Token": {
"kind": "TokenColon",
"lexeme": ":",
"location": {
"file_path": "",
"line": 0,
"column_start": 7,
"column_end": 8
}
}
},
{
"Tree": {
"kind": "TypeExpr",
"children": [
{
"Token": {
"kind": "TokenIdentifier",
"lexeme": "bool",
"location": {
"file_path": "",
"line": 0,
"column_start": 9,
"column_end": 13
}
}
}
]
}
},
{
"Token": {
"kind": "TokenAssign",
"lexeme": "=",
"location": {
"file_path": "",
"line": 0,
"column_start": 16,
"column_end": 20
"column_start": 14,
"column_end": 15
}
}
},
{
"Tree": {
"kind": "StmtExpr",
"children": [
{
"Tree": {
"kind": "ExprLiteral",
"children": [
{
"Token": {
"kind": {
"TokenLiteral": "Bool"
},
"lexeme": "true",
"location": {
"file_path": "",
"line": 0,
"column_start": 16,
"column_end": 20
}
}
}
]
}
},
{
"Token": {
"kind": "TokenNewLine",
"lexeme": "\\n",
"location": {
"file_path": "",
"line": 0,
"column_start": 20,
"column_end": 20
}
}
}
]
}
}
]
}
},
{
"Token": {
"kind": "TokenEOF",
"lexeme": "",
"location": {
"file_path": "",
"line": 1,
"column_start": 0,
"column_end": 0
}
}
}
Expand Down
Loading

0 comments on commit 947c6b2

Please sign in to comment.