diff --git a/src/protocol/tests/parser_validation.rs b/src/protocol/tests/parser_validation.rs index 0462c7e1e7f81070d022ab9fa36ad21f66d6203c..7d516ce640715f9c74acc159ac56a7ed8307bef9 100644 --- a/src/protocol/tests/parser_validation.rs +++ b/src/protocol/tests/parser_validation.rs @@ -528,4 +528,79 @@ fn test_polymorph_array_types() { ).for_struct("Bar", |s| { s .for_field("inputs", |f| { f.assert_parser_type("in[]"); }); }); +} + +#[test] +fn test_correct_modifying_operators() { + // Not testing the types, just that it parses + Tester::new_single_source_expect_ok( + "valid uses", + " + func f() -> u32 { + auto a = 5; + a += 2; a -= 2; a *= 2; a /= 2; a %= 2; + a <<= 2; a >>= 2; + a |= 2; a &= 2; a ^= 2; + return a; + } + " + ); +} + +#[test] +fn test_incorrect_modifying_operators() { + Tester::new_single_source_expect_err( + "wrong declaration", + "func f() -> u8 { auto a += 2; return a; }" + ).error(|e| { e.assert_msg_has(0, "expected '='"); }); + + Tester::new_single_source_expect_err( + "inside function", + "func f(u32 a) -> u32 { auto b = 0; auto c = f(a += 2); }" + ).error(|e| { e.assert_msg_has(0, "assignments are statements"); }); + + Tester::new_single_source_expect_err( + "inside tuple", + "func f(u32 a) -> u32 { auto b = (a += 2, a /= 2); return 0; }" + ).error(|e| { e.assert_msg_has(0, "assignments are statements"); }); +} + +#[test] +fn test_correct_select_statement() { + Tester::new_single_source_expect_ok( + "correct single-use", " + primitive f() { + channel unused_output -> input; + u32 outer_value = 0; + sync select { + outer_value = get(input) -> outer_value = 0; + auto new_value = get(input) -> { + f(); + outer_value = new_value; + } + get(input) + get(input) -> + outer_value = 8; + get(input) -> + {} + outer_value %= get(input) -> { + outer_value *= outer_value; + auto new_value = get(input); + outer_value += new_value; + } + } + } + " + ); +} + +#[test] +fn test_incorrect_select_statement() { + Tester::new_single_source_expect_err( + "outside sync", + "func f() -> u32 { select {} return 0; }" + ).error(|e| { e + .assert_num(1) + .assert_occurs_at(0, "select") + .assert_msg_has(0, "inside sync blocks"); + }); } \ No newline at end of file