-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathref_test.py
More file actions
75 lines (61 loc) · 1.19 KB
/
ref_test.py
File metadata and controls
75 lines (61 loc) · 1.19 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from template.test import TestCase, main
def comma_list(format):
def func(*args):
return format % ", ".join(str(x) for x in args)
return func
class RefTest(TestCase):
def testRef(self):
replace = {
"a": comma_list("a sub [%s]"),
"j": {"k": 3,
"l": 5,
"m": {"n": comma_list("nsub [%s]")}},
"z": lambda sub: "z called %s" % sub(10, 20, 30)
}
self.Expect(DATA, None, replace)
DATA = r"""
-- test --
a: [% a %]
a(5): [% a(5) %]
a(5,10): [% a(5,10) %]
-- expect --
a: a sub []
a(5): a sub [5]
a(5,10): a sub [5, 10]
-- test --
[% b = \a -%]
b: [% b %]
b(5): [% b(5) %]
b(5,10): [% b(5,10) %]
-- expect --
b: a sub []
b(5): a sub [5]
b(5,10): a sub [5, 10]
-- test --
[% c = \a(10,20) -%]
c: [% c %]
c(30): [% c(30) %]
c(30,40): [% c(30,40) %]
-- expect --
c: a sub [10, 20]
c(30): a sub [10, 20, 30]
c(30,40): a sub [10, 20, 30, 40]
-- test --
[% z(\a) %]
-- expect --
z called a sub [10, 20, 30]
-- test --
[% f = \j.k -%]
f: [% f %]
-- expect --
f: 3
-- test --
[% f = \j.m.n -%]
f: [% f %]
f(11): [% f(11) %]
-- expect --
f: nsub []
f(11): nsub [11]
"""
if __name__ == '__main__':
main()