Skip to content

Commit 89754a0

Browse files
committed
Fix some tests and bugs
1 parent d1b77ea commit 89754a0

File tree

130 files changed

+83
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+83
-99
lines changed

ast/src/builder.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,15 @@ impl<'a> Builder<'a, InitState> {
642642
) -> Rc<ReturnStatement> {
643643
let id = Self::get_node_id();
644644
let location = Self::get_location(node, code);
645-
let expression =
646-
self.build_expression(id, &node.child_by_field_name("expression").unwrap(), code);
647-
645+
let expr_node = &node.child_by_field_name("expression");
646+
let expression = if let Some(expr) = expr_node {
647+
self.build_expression(id, expr, code)
648+
} else {
649+
Expression::Literal(Literal::Unit(Rc::new(UnitLiteral::new(
650+
Self::get_node_id(),
651+
Self::get_location(node, code),
652+
))))
653+
};
648654
let node = Rc::new(ReturnStatement::new(id, location, expression));
649655
self.arena.add_node(
650656
AstNode::Statement(Statement::Return(node.clone())),
@@ -738,7 +744,9 @@ impl<'a> Builder<'a, InitState> {
738744
"array_index_access_expression" => Expression::ArrayIndexAccess(
739745
self.build_array_index_access_expression(parent_id, node, code),
740746
),
741-
"generic_name" | "type" => Expression::Type(self.build_type(parent_id, node, code)),
747+
"generic_name" | "qualified_name" | "type" => {
748+
Expression::Type(self.build_type(parent_id, node, code))
749+
}
742750
"member_access_expression" => {
743751
Expression::MemberAccess(self.build_member_access_expression(parent_id, node, code))
744752
}

tests/src/ast/README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,7 @@ cargo llvm-cov --package inference-ast --lib --summary-only
9191
- Good: `test_parse_function_with_multiple_parameters`
9292
- Bad: `test_fn_2`
9393

94-
4. **Mark unsupported features as ignored**: If a test fails due to grammar limitations, use `#[ignore]`
95-
```rust
96-
#[ignore = "feature X not yet supported in grammar"]
97-
#[test]
98-
fn test_feature_x() {
99-
// ...
100-
}
101-
```
102-
103-
5. **Add comments for complex tests**: Explain the purpose of tests that aren't immediately obvious
94+
4. **Add comments for complex tests**: Explain the purpose of tests that aren't immediately obvious
10495

10596
### Test Organization
10697

tests/src/ast/builder.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,6 @@ use inference::std::types::Address;
193193
assert_eq!(directives.len(), 2);
194194
}
195195

196-
#[ignore]
197-
#[test]
198-
fn test_parse_context_definition() {
199-
let source = r#"
200-
context A {}
201-
"#;
202-
let ast = build_ast(source.to_string());
203-
let source_files = &ast.source_files;
204-
assert_eq!(source_files.len(), 1);
205-
}
206-
207196
#[test]
208197
fn test_parse_binary_expression_add() {
209198
let source = r#"
@@ -372,7 +361,6 @@ fn test() -> bool {
372361
assert_eq!(source_files.len(), 1);
373362
}
374363

375-
#[ignore]
376364
#[test]
377365
fn test_parse_unary_negate() {
378366
let source = r#"
@@ -525,13 +513,14 @@ fn test() {
525513
assert_eq!(source_files.len(), 1);
526514
}
527515

528-
#[ignore]
529516
#[test]
530517
fn test_parse_for_loop() {
531518
let source = r#"
532519
fn test() {
533-
for (let i: i32 = 0; i < 10; i = i + 1) {
520+
let mut i: i32 = 0;
521+
loop i < 10 {
534522
foo(i);
523+
i = i + 1;
535524
}
536525
}
537526
"#;
@@ -662,7 +651,6 @@ fn test() -> i32 {
662651
assert_eq!(source_files.len(), 1);
663652
}
664653

665-
#[ignore]
666654
#[test]
667655
fn test_parse_chained_member_access() {
668656
let source = r#"
@@ -805,12 +793,12 @@ fn test() -> i32 {
805793
let source_files = &ast.source_files;
806794
assert_eq!(source_files.len(), 1);
807795
}
808-
#[ignore]
796+
809797
#[test]
810798
fn test_parse_multiline_comments() {
811799
let source = r#"
812-
/* This is a
813-
multiline comment */
800+
// This is a
801+
// multiline comment
814802
fn test() -> i32 {
815803
return 42;
816804
}

tests/src/ast/builder_extended.rs

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
use crate::utils::build_ast;
22

3-
// Extended comprehensive tests for advanced AST features
4-
5-
#[ignore = "spec/total definition not supported"]
6-
#[test]
7-
fn test_parse_spec_definition() {
8-
let source = r#"
9-
total fn sum(items: []i32) -> i32 {
10-
filter {
11-
return >= 0;
12-
}
13-
let result = 0;
14-
for item in items {
15-
result = result + item;
16-
}
17-
return result;
18-
}
19-
"#;
20-
let ast = build_ast(source.to_string());
21-
let source_files = &ast.source_files;
22-
assert_eq!(source_files.len(), 1);
23-
}
24-
25-
#[ignore = "forall with empty return not parsing correctly"]
3+
// Extended comprehensive tests
264
#[test]
275
fn test_parse_function_with_forall() {
286
let source = r#"
@@ -49,11 +27,10 @@ fn test() -> () forall {
4927
assert_eq!(source_files.len(), 1);
5028
}
5129

52-
#[ignore = "filter block not supported"]
5330
#[test]
5431
fn test_parse_function_with_filter() {
5532
let source = r#"
56-
total fn add(a: i32, b: i32) -> i32 {
33+
fn add(a: i32, b: i32) -> i32 {
5734
filter {
5835
return >= 0;
5936
}
@@ -65,19 +42,6 @@ total fn add(a: i32, b: i32) -> i32 {
6542
assert_eq!(source_files.len(), 1);
6643
}
6744

68-
#[ignore = "constructor function keyword not supported"]
69-
#[test]
70-
fn test_parse_constructor_function() {
71-
let source = r#"
72-
constructor fn create_spec() -> SpecType {
73-
return SpecType { value: 42 };
74-
}
75-
"#;
76-
let ast = build_ast(source.to_string());
77-
let source_files = &ast.source_files;
78-
assert_eq!(source_files.len(), 1);
79-
}
80-
8145
#[test]
8246
fn test_parse_qualified_type() {
8347
let source = r#"
@@ -102,7 +66,7 @@ type sf = typeof(sorting_function);
10266
assert_eq!(source_files.len(), 1);
10367
}
10468

105-
#[ignore = "let outside function not supported"]
69+
#[ignore = "//TODO: add proper error reporting and handling"]
10670
#[test]
10771
fn test_parse_typeof_with_identifier() {
10872
let source = r#"
@@ -114,9 +78,9 @@ type mytype = typeof(x);
11478
assert_eq!(source_files.len(), 1);
11579
}
11680

117-
#[ignore = "method call syntax not fully supported"]
81+
#[ignore = "//TODO: add proper error reporting and handling"]
11882
#[test]
119-
fn test_parse_method_call_expression() {
83+
fn test_parse_error_on_method_call_expression() {
12084
let source = r#"
12185
fn test() {
12286
let result = object.method();
@@ -127,12 +91,23 @@ fn test() {
12791
assert_eq!(source_files.len(), 1);
12892
}
12993

130-
#[ignore = "method call with args not fully supported"]
94+
#[test]
95+
fn test_parse_method_call_expression() {
96+
let source = r#"
97+
fn test() {
98+
let result: i32 = object.method();
99+
}
100+
"#;
101+
let ast = build_ast(source.to_string());
102+
let source_files = &ast.source_files;
103+
assert_eq!(source_files.len(), 1);
104+
}
105+
131106
#[test]
132107
fn test_parse_method_call_with_args() {
133108
let source = r#"
134109
fn test() {
135-
let result = object.method(arg1, arg2);
110+
let result: u64 = object.method(arg1, arg2);
136111
}
137112
"#;
138113
let ast = build_ast(source.to_string());
@@ -170,9 +145,9 @@ enum Color {
170145
assert_eq!(source_files.len(), 1);
171146
}
172147

173-
#[ignore = "multiline struct expressions not supported"]
148+
#[ignore = "//TODO: add proper error reporting and handling"]
174149
#[test]
175-
fn test_parse_complex_struct_expression() {
150+
fn test_parse_error_on_complex_struct_expression() {
176151
let source = r#"
177152
fn test() {
178153
let point = Point {
@@ -188,12 +163,28 @@ fn test() {
188163
assert_eq!(source_files.len(), 1);
189164
}
190165

191-
#[ignore = "nested struct expressions not supported"]
166+
#[test]
167+
fn test_parse_complex_struct_expression() {
168+
let source = r#"
169+
fn test() {
170+
let point: Point = Point {
171+
x: 10,
172+
y: 20,
173+
z: 30,
174+
label: "origin"
175+
};
176+
}
177+
"#;
178+
let ast = build_ast(source.to_string());
179+
let source_files = &ast.source_files;
180+
assert_eq!(source_files.len(), 1);
181+
}
182+
192183
#[test]
193184
fn test_parse_nested_struct_expression() {
194185
let source = r#"
195186
fn test() {
196-
let rect = Rectangle {
187+
let rect: Rectangle = Rectangle {
197188
top_left: Point { x: 0, y: 0 },
198189
bottom_right: Point { x: 100, y: 100 }
199190
};
@@ -349,40 +340,51 @@ fn test3() -> i32 { return 3; }
349340
assert_eq!(source_files[0].definitions.len(), 3);
350341
}
351342

352-
#[ignore = "numeric literals parsing issue"]
353343
#[test]
354344
fn test_parse_multiple_variable_declarations() {
355345
let source = r#"
356346
fn test() {
357-
let a = 1;
358-
let b = 2;
359-
let c = 3;
360-
let d = 4;
347+
let a: i32 = 1;
348+
let b: i64 = 2;
349+
let c: u32 = 3;
350+
let d: u64 = 4;
351+
}
352+
"#;
353+
let ast = build_ast(source.to_string());
354+
let source_files = &ast.source_files;
355+
assert_eq!(source_files.len(), 1);
356+
}
357+
358+
#[ignore = "//TODO: add proper error reporting and handling"]
359+
#[test]
360+
fn test_parse_error_on_variable_with_type_inference() {
361+
let source = r#"
362+
fn test() {
363+
let x: i32 = 42;
361364
}
362365
"#;
363366
let ast = build_ast(source.to_string());
364367
let source_files = &ast.source_files;
365368
assert_eq!(source_files.len(), 1);
366369
}
367370

368-
#[ignore = "type inference syntax not supported"]
369371
#[test]
370372
fn test_parse_variable_with_type_inference() {
371373
let source = r#"
372374
fn test() {
373-
let x := 42;
375+
let x: i32 = 42;
374376
}
375377
"#;
376378
let ast = build_ast(source.to_string());
377379
let source_files = &ast.source_files;
378380
assert_eq!(source_files.len(), 1);
379381
}
380382

381-
#[ignore = "struct literals in const not supported"]
383+
#[ignore = "//TODO: add proper error reporting and handling"]
382384
#[test]
383385
fn test_parse_multiple_definitions() {
384386
let source = r#"
385-
struct Point { x: i32, y: i32 }
387+
struct Point { x: i32; y: i32; }
386388
enum Color { Red, Green, Blue }
387389
fn create_point(x: i32, y: i32) -> Point {
388390
return Point { x: x, y: y };
@@ -421,20 +423,19 @@ fn test() {
421423
assert_eq!(source_files.len(), 1);
422424
}
423425

424-
#[ignore = "nested array literals not supported"]
425426
#[test]
426427
fn test_parse_array_of_arrays() {
427428
let source = r#"
428429
fn test() {
429-
let matrix = [[1, 2], [3, 4]];
430+
let matrix: [[i32; 2]; 2] = [[1, 2], [3, 4]];
430431
}
431432
"#;
432433
let ast = build_ast(source.to_string());
433434
let source_files = &ast.source_files;
434435
assert_eq!(source_files.len(), 1);
435436
}
436437

437-
#[ignore = "self parameter not yet implemented"]
438+
#[ignore = "self parameter not yet implemented in type inference"]
438439
#[test]
439440
fn test_parse_function_with_self_param() {
440441
let source = r#"
@@ -459,20 +460,18 @@ fn test(_: i32) -> i32 {
459460
assert_eq!(source_files.len(), 1);
460461
}
461462

462-
#[ignore = "empty array literal syntax not supported"]
463463
#[test]
464464
fn test_parse_empty_array_literal() {
465465
let source = r#"
466466
fn test() {
467-
let arr = [];
467+
let arr: [i32; 0] = [];
468468
}
469469
"#;
470470
let ast = build_ast(source.to_string());
471471
let source_files = &ast.source_files;
472472
assert_eq!(source_files.len(), 1);
473473
}
474474

475-
#[ignore = "ignore parameter not fully implemented"]
476475
#[test]
477476
fn test_parse_function_with_mixed_params() {
478477
let source = r#"
@@ -485,7 +484,6 @@ fn test(a: i32, _: i32, c: i32) -> i32 {
485484
assert_eq!(source_files.len(), 1);
486485
}
487486

488-
#[ignore = "bitwise NOT not yet supported"]
489487
#[test]
490488
fn test_parse_bitwise_not() {
491489
let source = r#"

0 commit comments

Comments
 (0)