Skip to content

Commit

Permalink
parser: fixed all remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLydike committed Jan 13, 2023
1 parent 783fd83 commit 81f4e0d
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 184 deletions.
18 changes: 12 additions & 6 deletions tests/test_parser_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ def check_error(prog: str, line: int, column: int, message: str):
parser.must_parse_operation()

assert e.value.span
assert e.value.span.get_line_col() == (line, column)
assert any(message in ex.error.msg for ex in e.value.history.iterate())
msgs = [err.error.msg for err in e.value.history.iterate()]

for err in e.value.history.iterate():
if message in err.error.msg:
assert err.error.span.get_line_col() == (line, column)
break
else:
assert False, "'{}' not found in an error message {}!".format(message, e.value.args)


def test_parser_missing_equal():
Expand All @@ -38,7 +44,7 @@ def test_parser_missing_equal():
%0 : !i32 unknown()
}
"""
check_error(prog, 3, 13, "Operation definitions expect an `=` after op-result-list!")
check_error(prog, 3, 12, "Operation definitions expect an `=` after op-result-list!")


def test_parser_redefined_value():
Expand Down Expand Up @@ -67,10 +73,10 @@ def test_parser_missing_operation_name():
%val : !i32 =
}
"""
check_error(prog, 3, 13, "Expected an operation name here")
check_error(prog, 4, 0, "Expected an operation name here")


def test_parser_missing_attribute():
def test_parser_malformed_type():
"""Test a missing attribute error."""
ctx = MLContext()
ctx.register_op(UnkownOp)
Expand All @@ -81,4 +87,4 @@ def test_parser_missing_attribute():
%val : i32 = unknown()
}
"""
check_error(prog, 3, 10, "attribute expected")
check_error(prog, 3, 9, "Expected type of value-id here!")
4 changes: 2 additions & 2 deletions tests/test_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ def parse(cls, result_types: List[Attribute],
parser: BaseParser) -> PlusCustomFormatOp:
def get_ssa_val(name: Span) -> SSAValue:
if name.text not in parser.ssaValues:
parser.raise_error('Unknown SSA Value name', name)
parser.raise_error('SSA Value used before assignment', name)
return parser.ssaValues[name.text]

lhs = parser.expect(parser.try_parse_value_id, 'Expected SSA Value name here!')
parser.parse_char("+")
parser.must_parse_characters("+", "Malformed operation format, expected `+`!")
rhs = parser.expect(parser.try_parse_value_id, 'Expected SSA Value name here!')

return PlusCustomFormatOp.create(operands=[get_ssa_val(name) for name in (lhs, rhs)],
Expand Down
Loading

0 comments on commit 81f4e0d

Please sign in to comment.