11use 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]
275fn 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]
5431fn 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]
8246fn 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]
10771fn 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#"
12185fn 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]
132107fn test_parse_method_call_with_args ( ) {
133108 let source = r#"
134109fn 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#"
177152fn 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]
193184fn test_parse_nested_struct_expression ( ) {
194185 let source = r#"
195186fn 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]
354344fn test_parse_multiple_variable_declarations ( ) {
355345 let source = r#"
356346fn 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]
370372fn test_parse_variable_with_type_inference ( ) {
371373 let source = r#"
372374fn 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]
383385fn test_parse_multiple_definitions ( ) {
384386 let source = r#"
385- struct Point { x: i32, y: i32 }
387+ struct Point { x: i32; y: i32; }
386388enum Color { Red, Green, Blue }
387389fn 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]
426427fn test_parse_array_of_arrays ( ) {
427428 let source = r#"
428429fn 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]
439440fn 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]
464464fn test_parse_empty_array_literal ( ) {
465465 let source = r#"
466466fn 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]
477476fn 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]
490488fn test_parse_bitwise_not ( ) {
491489 let source = r#"
0 commit comments