示例#1
0
def test_functions_cannot_be_redeclared():
    with pytest.raises(TypeErrors):
        parse(
            """
              fn getUserIds() [Int]
              fn getUserIds() [Int]
            """
        )
示例#2
0
def test_unknown_types_are_rejected():
    with pytest.raises(TypeErrors):
        parse(
            """
              record A {
                a Idontexist
              }
            """
        )
示例#3
0
def test_dict_keys_must_be_strings():
    with pytest.raises(TypeErrors):
        parse(
            """
              record A {
                d {Int: Float}
              }
            """
        )
示例#4
0
def test_types_cannot_be_redeclared():
    with pytest.raises(TypeErrors):
        parse(
            """
              record A {
                a Idontexist
              }

              enum A { }
            """
        )
示例#5
0
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
示例#6
0
文件: common.py 项目: Bogdanp/cedar
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
示例#7
0
def test_unexpected_tokens_raise_errors():
    with pytest.raises(ParseError) as e:
        parse("record A! {}")

    assert e.value.message == "unexpected '!'"
示例#8
0
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'"
示例#9
0
def test_unions_cannot_be_empty():
    with pytest.raises(ParseError):
        parse("union A {}")
示例#10
0
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
示例#11
0
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
示例#12
0
def test_unions_cannot_be_empty():
    with pytest.raises(ParseError):
        parse("union A {}")
示例#13
0
def test_parse_errors_can_halt_execution():
    with pytest.raises(ParseError) as e:
        parse("record!")

    with pytest.raises(SystemExit):
        e.value.print_and_halt()
示例#14
0
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()
示例#15
0
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
示例#16
0
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
示例#17
0
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'"
示例#18
0
def test_parse_errors_can_halt_execution():
    with pytest.raises(ParseError) as e:
        parse("record!")

    with pytest.raises(SystemExit):
        e.value.print_and_halt()
示例#19
0
def test_unexpected_tokens_raise_errors():
    with pytest.raises(ParseError) as e:
        parse("record A! {}")

    assert e.value.message == "unexpected '!'"