diff --git a/src/protocol/tests/parser_literals.rs b/src/protocol/tests/parser_literals.rs index 29ab95774c778f867b8ecbc46072e01ff5e39f90..de343928abfb66f8f8b6cc0399badfa476c205b4 100644 --- a/src/protocol/tests/parser_literals.rs +++ b/src/protocol/tests/parser_literals.rs @@ -67,4 +67,58 @@ fn test_string_literals() { Tester::new_single_source_expect_err("non-ASCII string", " func test() -> string { return \"💧\"; } ").error(|e| { e.assert_msg_has(0, "non-ASCII character in string literal"); }); +} + +#[test] +fn test_tuple_literals() { + Tester::new_single_source_expect_ok("zero tuples", " + func test() -> () { + // Looks like lisp :) + auto t1 = (); + () t2 = (); + auto t3 = (()); + () t4 = (()); + auto t5 = ((((())))); + ((())) t6 = ((((())))); + + return (); + } + ").for_function("test", |f| { f + .for_variable("t1", |v| { v.assert_concrete_type("()"); }) + .for_variable("t2", |v| { v.assert_concrete_type("()"); }) + .for_variable("t3", |v| { v.assert_concrete_type("()"); }) + .for_variable("t4", |v| { v.assert_concrete_type("()"); }) + .for_variable("t5", |v| { v.assert_concrete_type("()"); }) + .for_variable("t6", |v| { v.assert_concrete_type("()"); }); + }); + + // All one-tuples (T) are transformed into T to prevent ambiguity + Tester::new_single_source_expect_ok("one tuples", " + func test() -> (u32) { + auto a = (0); + (s32) b = (1); + ((((s32)))) c = ((2)); + } + ").for_function("test", |f| { f + .for_variable("a", |v| { v.assert_concrete_type("s32"); }) + .for_variable("b", |v| { v.assert_concrete_type("s32"); }) + .for_variable("c", |v| { v.assert_concrete_type("s32"); }); + }); + + Tester::new_single_source_expect_ok("actual tuples", " + func test() -> (u32, u32) { + (u8,u16,u32) a = (0, 1, 2); + auto b = a; + auto c = (3, 4, 5); + ((auto, auto)) d = (a, c); + auto e = (\"hello\", 'c', 5 + 2); + return ((0), (1)); + } + ").for_function("test", |f| { f + .for_variable("a", |v| { v.assert_concrete_type("(u8,u16,u32)"); }) + .for_variable("b", |v| { v.assert_concrete_type("(u8,u16,u32)"); }) + .for_variable("c", |v| { v.assert_concrete_type("(s32,s32,s32)"); }) + .for_variable("d", |v| { v.assert_concrete_type("((u8,u16,u32),(s32,s32,s32))"); }) + .for_variable("e", |v| { v.assert_concrete_type("(string,char,s32)"); }); + }); } \ No newline at end of file