-
Notifications
You must be signed in to change notification settings - Fork 57
/
parser_error_test.py
84 lines (65 loc) · 1.71 KB
/
parser_error_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from __future__ import annotations
from xdsl.ir import MLContext
from xdsl.irdl import AnyAttr, VarOperandDef, VarResultDef, irdl_op_definition, Operation
from xdsl.parser import Parser, ParserError
from pytest import raises
@irdl_op_definition
class UnkownOp(Operation):
name = "unknown"
ops = VarOperandDef(AnyAttr())
res = VarResultDef(AnyAttr())
def check_error(prog: str, line: int, column: int, message: str):
ctx = MLContext()
ctx.register_op(UnkownOp)
parser = Parser(ctx, prog)
with raises(ParserError) as e:
parser.parse_op()
assert e.value.pos is not None
assert e.value.pos.line is line
assert e.value.pos.column is column
assert e.value.message == message
def test_parser_missing_equal():
"""Test a missing equal sign error."""
ctx = MLContext()
ctx.register_op(UnkownOp)
prog = \
"""
unknown() {
%0 : !i32 unknown()
}
"""
check_error(prog, 3, 13, "'=' expected")
def test_parser_redefined_value():
"""Test an SSA value redefinition error."""
ctx = MLContext()
ctx.register_op(UnkownOp)
prog = \
"""
unknown() {
%val : !i32 = unknown()
%val : !i32 = unknown()
}
"""
check_error(prog, 4, 3, "SSA value val is already defined")
def test_parser_missing_operation_name():
"""Test a missing operation name error."""
ctx = MLContext()
ctx.register_op(UnkownOp)
prog = \
"""
unknown() {
%val : !i32 =
}
"""
check_error(prog, 4, 1, "operation name expected")
def test_parser_missing_attribute():
"""Test a missing attribute error."""
ctx = MLContext()
ctx.register_op(UnkownOp)
prog = \
"""
unknown() {
%val : i32 = unknown()
}
"""
check_error(prog, 3, 10, "attribute expected")