-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests_parse.py
More file actions
58 lines (44 loc) · 1.39 KB
/
Copy pathtests_parse.py
File metadata and controls
58 lines (44 loc) · 1.39 KB
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
from lexer import parse_atom, read_grammar
with open('C_grammar', 'r') as f:
g = read_grammar(f.read())
def test_parse_block():
src = """int main() {
int j;
return j;
}"""
tree, remainder = parse_atom(g, 'Wrap', src)
assert not remainder
def test_parse_comment():
line_comment = """int main() {
// This is a line comment. Please ignore it.
return 0;
}"""
tree, remainder = parse_atom(g, 'Wrap', line_comment)
assert not remainder
inline_comment = """int main() {
return 0; // This is an inline comment. You may also ignore it.
}"""
tree, remainder = parse_atom(g, 'Wrap', inline_comment)
assert not remainder
def test_parse_statement():
src = "int i = 0;"
tree, remainder = parse_atom(g, 'Statement', src)
assert not remainder
src = "int i;"
tree, remainder = parse_atom(g, 'Statement', src)
assert not remainder
def test_parse_declaration():
src = "int i = 0"
tree, remainder = parse_atom(g, 'Declaration', src)
assert not remainder
src = "int i"
tree, remainder = parse_atom(g, 'Declaration', src)
assert not remainder
def test_parse_for():
src = "for (i = 0; i < 5; i = i + 1) { j = 3 }"
tree, remainder = parse_atom(g, 'ForLoop', src)
assert not remainder
def test_parse_empty_if():
src = "if (1) { }"
tree, remainder = parse_atom(g, 'If', src)
assert not remainder