-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_define_unbound.py
60 lines (53 loc) · 1.19 KB
/
test_define_unbound.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
"""
Test cases for BNF grammar
Run tests with
pytest test_define_unbound.py
"""
import lib
l = lib.Lib()
def test_find_vars():
assert lib.find_vars(l.bnf['c-l+literal'][0]) == set('ntm')
assert lib.find_vars(l.bnf['l-nb-literal-text'][0]) == set('n')
assert lib.find_vars(l.bnf['s-l+block-indented'][0]) == set('nmc')
def test_define_unbound():
assert list(lib.define_unbound([])) == [{}]
assert list(lib.define_unbound('m')) == [{"m": m} for m in range(0, lib.M_VAR_MAX)]
assert list(lib.define_unbound('t')) == [
{
"t": 'CLIP'
},
{
"t": 'KEEP'
},
{
"t": 'STRIP'
},
]
assert list(lib.define_unbound(['t', 'm']))[:4] == [
{
"m": 0,
"t": 'CLIP'
},
{
"m": 0,
"t": 'KEEP'
},
{
"m": 0,
"t": 'STRIP'
},
{
"m": 1,
"t": 'CLIP'
},
]
def test_automagically_define_unbound():
assert list(lib.automagically_define_unbound(l.bnf['s-l+block-indented'][0], dict(n='42', c='99')))[:2] == [{
'c': '99',
'm': 0,
'n': '42'
}, {
'c': '99',
'm': 1,
'n': '42'
}]