-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtext_test.py
More file actions
153 lines (130 loc) · 2.26 KB
/
text_test.py
File metadata and controls
153 lines (130 loc) · 2.26 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from template import Template
from template.test import TestCase, main
class Stringy:
def __init__(self, text):
self.text = text
def asString(self):
return self.text
__str__ = asString
class TextTest(TestCase):
def testText(self):
tt = (("basic", Template()),
("interp", Template({"INTERPOLATE": 1})))
vars = self._callsign()
v2 = {"ref": lambda obj: "%s[%s]" % (obj, obj.__class__.__name__),
"sfoo": Stringy("foo"),
"sbar": Stringy("bar")}
vars.update(v2)
self.Expect(DATA, tt, vars)
DATA = r"""
-- test --
This is a text block "hello" 'hello' 1/3 1\4 <html> </html>
$ @ { } @{ } ${ } # ~ ' ! % *foo
$a ${b} $c
-- expect --
This is a text block "hello" 'hello' 1/3 1\4 <html> </html>
$ @ { } @{ } ${ } # ~ ' ! % *foo
$a ${b} $c
-- test --
<table width=50%>©
-- expect --
<table width=50%>©
-- test --
[% foo = 'Hello World' -%]
start
[%
#
# [% foo %]
#
#
-%]
end
-- expect --
start
end
-- test --
pre
[%
# [% PROCESS foo %]
-%]
mid
[% BLOCK foo; "This is foo"; END %]
-- expect --
pre
mid
-- test --
-- use interp --
This is a text block "hello" 'hello' 1/3 1\4 <html> </html>
\$ @ { } @{ } \${ } # ~ ' ! % *foo
$a ${b} $c
-- expect --
This is a text block "hello" 'hello' 1/3 1\4 <html> </html>
$ @ { } @{ } ${ } # ~ ' ! % *foo
alpha bravo charlie
-- test --
<table width=50%>©
-- expect --
<table width=50%>©
-- test --
[% foo = 'Hello World' -%]
start
[%
#
# [% foo %]
#
#
-%]
end
-- expect --
start
end
-- test --
pre
[%
#
# [% PROCESS foo %]
#
-%]
mid
[% BLOCK foo; "This is foo"; END %]
-- expect --
pre
mid
-- test --
[% a = "C'est un test"; a %]
-- expect --
C'est un test
-- test --
[% META title = "C'est un test" -%]
[% component.title -%]
-- expect --
C'est un test
-- test --
[% META title = 'C\'est un autre test' -%]
[% component.title -%]
-- expect --
C'est un autre test
-- test --
[% META title = "C'est un \"test\"" -%]
[% component.title -%]
-- expect --
C'est un "test"
-- test --
[% sfoo %]/[% sbar %]
-- expect --
foo/bar
-- test --
[% s1 = "$sfoo"
s2 = "$sbar ";
s3 = sfoo;
ref(s1);
'/';
ref(s2);
'/';
ref(s3);
-%]
-- expect --
foo[str]/bar [str]/foo[Stringy]
"""
if __name__ == '__main__':
main()