def test_functions_cannot_be_redeclared(): with pytest.raises(TypeErrors): parse( """ fn getUserIds() [Int] fn getUserIds() [Int] """ )
def test_unknown_types_are_rejected(): with pytest.raises(TypeErrors): parse( """ record A { a Idontexist } """ )
def test_dict_keys_must_be_strings(): with pytest.raises(TypeErrors): parse( """ record A { d {Int: Float} } """ )
def test_types_cannot_be_redeclared(): with pytest.raises(TypeErrors): parse( """ record A { a Idontexist } enum A { } """ )
def test_type_errors_are_accumulated(): with pytest.raises(TypeErrors) as e: parse( """ union Resource { A, B } record Resource { } """ ) assert len(e.value.errors) == 3
def table(tests, typecheck=False): for string, expected_result in tests: if isinstance(string, list): return table([(s, expected_result) for s in string]) if not isinstance(expected_result, ast.Module): expected_result = Module([expected_result]) assert parse(string, typecheck=False) == expected_result
def test_unexpected_tokens_raise_errors(): with pytest.raises(ParseError) as e: parse("record A! {}") assert e.value.message == "unexpected '!'"
def test_tabs_are_not_allowed(): with pytest.raises(ParseError) as e: parse("record A {\n\ta Int\n}") assert e.value.message == r"unexpected '\t'"
def test_unions_cannot_be_empty(): with pytest.raises(ParseError): parse("union A {}")
def test_enums_cannnot_have_many_dangling_commas(): with pytest.raises(ParseError) as e: parse("enum A {B, C,,}") assert e.value.line == 1 assert e.value.column == 13
def test_only_toplevel_declarations_are_allowed_in_a_module(): with pytest.raises(ParseError) as e: parse("User") assert e.value.line == 1 assert e.value.column == 4
def test_parse_errors_can_halt_execution(): with pytest.raises(ParseError) as e: parse("record!") with pytest.raises(SystemExit): e.value.print_and_halt()
def test_type_errors_can_halt_execution(): with pytest.raises(TypeErrors) as e: parse("union A { B, C }") with pytest.raises(SystemExit): e.value.print_and_halt()