diff --git a/src/protocol/tests/parser_validation.rs b/src/protocol/tests/parser_validation.rs index bf9e3b8f311230cfd5de5d805fb1c6c4d4505e84..bc6d059c5e2a3de48e42595a44266bffbce77247 100644 --- a/src/protocol/tests/parser_validation.rs +++ b/src/protocol/tests/parser_validation.rs @@ -11,7 +11,7 @@ fn test_correct_struct_instance() { "single field", " struct Foo { s32 a } - Foo bar(s32 arg) { return Foo{ a: arg }; } + func bar(s32 arg) -> Foo { return Foo{ a: arg }; } " ); @@ -19,7 +19,7 @@ fn test_correct_struct_instance() { "multiple fields", " struct Foo { s32 a, s32 b } - Foo bar(s32 arg) { return Foo{ a: arg, b: arg }; } + func bar(s32 arg) -> Foo { return Foo{ a: arg, b: arg }; } " ); @@ -27,7 +27,7 @@ fn test_correct_struct_instance() { "single field, explicit polymorph", " struct Foo{ T field } - Foo bar(s32 arg) { return Foo{ field: arg }; } + func bar(s32 arg) -> Foo { return Foo{ field: arg }; } " ); @@ -35,7 +35,7 @@ fn test_correct_struct_instance() { "single field, implicit polymorph", " struct Foo{ T field } - s32 bar(s32 arg) { + func bar(s32 arg) -> s32 { auto thingo = Foo{ field: arg }; return arg; } @@ -46,7 +46,7 @@ fn test_correct_struct_instance() { "multiple fields, same explicit polymorph", " struct Pair{ T1 first, T2 second } - s32 bar(s32 arg) { + func bar(s32 arg) -> s32 { auto qux = Pair{ first: arg, second: arg }; return arg; } @@ -57,7 +57,7 @@ fn test_correct_struct_instance() { "multiple fields, same implicit polymorph", " struct Pair{ T1 first, T2 second } - s32 bar(s32 arg) { + func bar(s32 arg) -> s32 { auto wup = Pair{ first: arg, second: arg }; return arg; } @@ -68,7 +68,7 @@ fn test_correct_struct_instance() { "multiple fields, different explicit polymorph", " struct Pair{ T1 first, T2 second } - s32 bar(s32 arg1, s8 arg2) { + func bar(s32 arg1, s8 arg2) -> s32 { auto shoo = Pair{ first: arg1, second: arg2 }; return arg1; } @@ -79,7 +79,7 @@ fn test_correct_struct_instance() { "multiple fields, different implicit polymorph", " struct Pair{ T1 first, T2 second } - s32 bar(s32 arg1, s8 arg2) { + func bar(s32 arg1, s8 arg2) -> s32 { auto shrubbery = Pair{ first: arg1, second: arg2 }; return arg1; } @@ -103,8 +103,8 @@ fn test_incorrect_struct_instance() { Tester::new_single_source_expect_err( "reused field in instance", " - struct Foo{ int a, int b } - int bar() { + struct Foo{ s32 a, s32 b } + func bar() -> s32 { auto foo = Foo{ a: 5, a: 3 }; return 0; } @@ -117,8 +117,8 @@ fn test_incorrect_struct_instance() { Tester::new_single_source_expect_err( "missing field", " - struct Foo { int a, int b } - int bar() { + struct Foo { s32 a, s32 b } + func bar() -> s32 { auto foo = Foo{ a: 2 }; return 0; } @@ -131,8 +131,8 @@ fn test_incorrect_struct_instance() { Tester::new_single_source_expect_err( "missing fields", " - struct Foo { int a, int b, int c } - int bar() { + struct Foo { s32 a, s32 b, s32 c } + func bar() -> s32 { auto foo = Foo{ a: 2 }; return 0; } @@ -149,7 +149,7 @@ fn test_correct_enum_instance() { "single variant", " enum Foo { A } - Foo bar() { return Foo::A; } + func bar() -> Foo { return Foo::A; } " ); @@ -157,7 +157,7 @@ fn test_correct_enum_instance() { "multiple variants", " enum Foo { A=15, B = 0xF } - Foo bar() { auto a = Foo::A; return Foo::B; } + func bar() -> Foo { auto a = Foo::A; return Foo::B; } " ); @@ -165,7 +165,7 @@ fn test_correct_enum_instance() { "explicit single polymorph", " enum Foo{ A } - Foo bar() { return Foo::A; } + func bar() -> Foo { return Foo::A; } " ); @@ -173,7 +173,7 @@ fn test_correct_enum_instance() { "explicit multi-polymorph", " enum Foo{ A, B } - Foo bar() { return Foo::B; } + func bar() -> Foo { return Foo::B; } " ); } @@ -184,7 +184,7 @@ fn test_incorrect_enum_instance() { "variant name reuse", " enum Foo { A, A } - Foo bar() { return Foo::A; } + func bar() -> Foo { return Foo::A; } " ).error(|e| { e .assert_num(2) @@ -198,7 +198,7 @@ fn test_incorrect_enum_instance() { "undefined variant", " enum Foo { A } - Foo bar() { return Foo::B; } + func bar() -> Foo { return Foo::B; } " ).error(|e| { e .assert_num(1) @@ -212,7 +212,7 @@ fn test_correct_union_instance() { "single tag", " union Foo { A } - Foo bar() { return Foo::A; } + func bar() -> Foo { return Foo::A; } " ); @@ -220,39 +220,39 @@ fn test_correct_union_instance() { "multiple tags", " union Foo { A, B } - Foo bar() { return Foo::B; } + func bar() -> Foo { return Foo::B; } " ); Tester::new_single_source_expect_ok( "single embedded", " - union Foo { A(int) } - Foo bar() { return Foo::A(5); } + union Foo { A(s32) } + func bar() -> Foo { return Foo::A(5); } " ); Tester::new_single_source_expect_ok( "multiple embedded", " - union Foo { A(int), B(s8) } - Foo bar() { return Foo::B(2); } + union Foo { A(s32), B(s8) } + func bar() -> Foo { return Foo::B(2); } " ); Tester::new_single_source_expect_ok( "multiple values in embedded", " - union Foo { A(int, s8) } - Foo bar() { return Foo::A(0, 2); } + union Foo { A(s32, s8) } + func bar() -> Foo { return Foo::A(0, 2); } " ); Tester::new_single_source_expect_ok( "mixed tag/embedded", " - union OptionInt { None, Some(int) } - OptionInt bar() { return OptionInt::Some(3); } + union OptionInt { None, Some(s32) } + func bar() -> OptionInt { return OptionInt::Some(3); } " ); @@ -260,14 +260,14 @@ fn test_correct_union_instance() { "single polymorphic var", " union Option { None, Some(T) } - Option bar() { return Option::Some(3); }" + func bar() -> Option { return Option::Some(3); }" ); Tester::new_single_source_expect_ok( "multiple polymorphic vars", " union Result { Ok(T), Err(E), } - Result bar() { return Result::Ok(3); } + func bar() -> Result { return Result::Ok(3); } " ); @@ -275,7 +275,7 @@ fn test_correct_union_instance() { "multiple polymorphic in one variant", " union MaybePair{ None, Some(T1, T2) } - MaybePair bar() { return MaybePair::Some(1, 2); } + func bar() -> MaybePair { return MaybePair::Some(1, 2); } " ); } @@ -298,13 +298,13 @@ fn test_incorrect_union_instance() { Tester::new_single_source_expect_err( "embedded-variant name reuse", " - union Foo{ A(int), A(s8) } + union Foo{ A(s32), A(s8) } " ).error(|e| { e .assert_num(2) .assert_occurs_at(0, "A(s8)") .assert_msg_has(0, "union variant is defined more than once") - .assert_occurs_at(1, "A(int)") + .assert_occurs_at(1, "A(s32)") .assert_msg_has(1, "other union variant"); }); @@ -312,7 +312,7 @@ fn test_incorrect_union_instance() { "undefined variant", " union Silly{ Thing(s8) } - Silly bar() { return Silly::Undefined(5); } + func bar() -> Silly { return Silly::Undefined(5); } " ).error(|e| { e .assert_msg_has(0, "variant 'Undefined' does not exist on the union 'Silly'"); @@ -321,8 +321,8 @@ fn test_incorrect_union_instance() { Tester::new_single_source_expect_err( "using tag instead of embedded", " - union Foo{ A(int) } - Foo bar() { return Foo::A; } + union Foo{ A(s32) } + func bar() -> Foo { return Foo::A; } " ).error(|e| { e .assert_msg_has(0, "variant 'A' of union 'Foo' expects 1 embedded values, but 0 were"); @@ -332,7 +332,7 @@ fn test_incorrect_union_instance() { "using embedded instead of tag", " union Foo{ A } - Foo bar() { return Foo::A(3); } + func bar() -> Foo { return Foo::A(3); } " ).error(|e| { e .assert_msg_has(0, "The variant 'A' of union 'Foo' expects 0"); @@ -341,14 +341,14 @@ fn test_incorrect_union_instance() { Tester::new_single_source_expect_err( "wrong embedded value", " - union Foo{ A(int) } - Foo bar() { return Foo::A(false); } + union Foo{ A(s32) } + func bar() -> Foo { return Foo::A(false); } " ).error(|e| { e .assert_occurs_at(0, "Foo::A") - .assert_msg_has(0, "Failed to fully resolve") + .assert_msg_has(0, "failed to fully resolve") .assert_occurs_at(1, "false") - .assert_msg_has(1, "has been resolved to 'int'") + .assert_msg_has(1, "has been resolved to 's32'") .assert_msg_has(1, "has been resolved to 'bool'"); }); } \ No newline at end of file