-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.py
More file actions
38 lines (30 loc) · 777 Bytes
/
tests.py
File metadata and controls
38 lines (30 loc) · 777 Bytes
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
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.abspath(__file__)))) # noqa
import pytest
from oops_parser import parse
from oops_parser.libs.parsy import ParseError
def test_parse():
code = '''
($x on $y)
($y left_of $z)
-{($z color red)
($z on $w)
-{($z color red)
($z on $y)}}
'''
ast = parse(code)
assert '$x.on == $y AND $y.left_of == $z AND NOT ($z.color == red AND $z.on == $w AND NOT ($z.color == red AND $z.on == $y))' == str(ast) # noqa
def test_parse_error():
code = '''
($x on table
'''
with pytest.raises(ParseError):
parse(code)
def test_nega():
code = '''
($x on table)
-($x color red)
'''
ast = parse(code)
assert '$x.on == table AND $x.color != red' == str(ast)