|
53 | 53 |
|
54 | 54 | it('String template', function () { |
55 | 55 | expect( |
56 | | - tmpl('{%=o.value%}', data), |
| 56 | + tmpl('{%=o.value%}', data) |
| 57 | + ).to.eql( |
57 | 58 | 'value' |
58 | 59 | ); |
59 | 60 | }); |
60 | 61 |
|
61 | 62 | it('Load template by id', function () { |
62 | 63 | expect( |
63 | | - tmpl('template', data), |
| 64 | + tmpl('template', data) |
| 65 | + ).to.eql( |
64 | 66 | 'value' |
65 | 67 | ); |
66 | 68 | }); |
67 | 69 |
|
68 | 70 | it('Retun function when called without data parameter', function () { |
69 | 71 | expect( |
70 | | - tmpl('{%=o.value%}')(data), |
| 72 | + tmpl('{%=o.value%}')(data) |
| 73 | + ).to.eql( |
71 | 74 | 'value' |
72 | 75 | ); |
73 | 76 | }); |
|
85 | 88 |
|
86 | 89 | it('Escape HTML special characters with {%=o.prop%}', function () { |
87 | 90 | expect( |
88 | | - tmpl('{%=o.special%}', data), |
| 91 | + tmpl('{%=o.special%}', data) |
| 92 | + ).to.eql( |
89 | 93 | '<>&"'' |
90 | 94 | ); |
91 | 95 | }); |
92 | 96 |
|
93 | 97 | it('Allow HTML special characters with {%#o.prop%}', function () { |
94 | 98 | expect( |
95 | | - tmpl('{%#o.special%}', data), |
| 99 | + tmpl('{%#o.special%}', data) |
| 100 | + ).to.eql( |
96 | 101 | '<>&"\'\x00' |
97 | 102 | ); |
98 | 103 | }); |
99 | 104 |
|
100 | 105 | it('Function call', function () { |
101 | 106 | expect( |
102 | | - tmpl('{%=o.func()%}', data), |
| 107 | + tmpl('{%=o.func()%}', data) |
| 108 | + ).to.eql( |
103 | 109 | 'value' |
104 | 110 | ); |
105 | 111 | }); |
106 | 112 |
|
107 | 113 | it('Dot notation', function () { |
108 | 114 | expect( |
109 | | - tmpl('{%=o.deep.value%}', data), |
| 115 | + tmpl('{%=o.deep.value%}', data) |
| 116 | + ).to.eql( |
110 | 117 | 'value' |
111 | 118 | ); |
112 | 119 | }); |
113 | 120 |
|
114 | 121 | it('Handle single quotes', function () { |
115 | 122 | expect( |
116 | | - tmpl('\'single quotes\'{%=": \'"%}', data), |
117 | | - '\'single quotes\': \'' |
| 123 | + tmpl('\'single quotes\'{%=": \'"%}', data) |
| 124 | + ).to.eql( |
| 125 | + '\'single quotes\': '' |
118 | 126 | ); |
119 | 127 | }); |
120 | 128 |
|
121 | 129 | it('Handle double quotes', function () { |
122 | 130 | expect( |
123 | | - tmpl('"double quotes"{%=": \\""%}', data), |
| 131 | + tmpl('"double quotes"{%=": \\""%}', data) |
| 132 | + ).to.eql( |
124 | 133 | '"double quotes": "' |
125 | 134 | ); |
126 | 135 | }); |
127 | 136 |
|
128 | 137 | it('Handle backslashes', function () { |
129 | 138 | expect( |
130 | | - tmpl('\\backslashes\\{%=": \\\\"%}', data), |
| 139 | + tmpl('\\backslashes\\{%=": \\\\"%}', data) |
| 140 | + ).to.eql( |
131 | 141 | '\\backslashes\\: \\' |
132 | 142 | ); |
133 | 143 | }); |
|
141 | 151 | '{%=o.zeroValue%}', |
142 | 152 | data |
143 | 153 | ) |
144 | | - ).to.be( |
| 154 | + ).to.eql( |
145 | 155 | 'false0' |
146 | 156 | ); |
147 | 157 | }); |
|
155 | 165 | '{%#o.zeroValue%}', |
156 | 166 | data |
157 | 167 | ) |
158 | | - ).to.be( |
| 168 | + ).to.eql( |
159 | 169 | 'false0' |
160 | 170 | ); |
161 | 171 | }); |
|
166 | 176 | '\n\r\t{%=o.value%} \n\r\t{%=o.value%} ', |
167 | 177 | data |
168 | 178 | ) |
169 | | - ).to.be( |
| 179 | + ).to.eql( |
170 | 180 | '\n\r\tvalue \n\r\tvalue ' |
171 | 181 | ); |
172 | 182 | }); |
|
177 | 187 |
|
178 | 188 | it('Escape HTML special characters with print(data)', function () { |
179 | 189 | expect( |
180 | | - tmpl('{% print(o.special); %}', data), |
| 190 | + tmpl('{% print(o.special); %}', data) |
| 191 | + ).to.eql( |
181 | 192 | '<>&"'' |
182 | 193 | ); |
183 | 194 | }); |
184 | 195 |
|
185 | 196 | it('Allow HTML special characters with print(data, true)', function () { |
186 | 197 | expect( |
187 | | - tmpl('{% print(o.special, true); %}', data), |
| 198 | + tmpl('{% print(o.special, true); %}', data) |
| 199 | + ).to.eql( |
188 | 200 | '<>&"\'\x00' |
189 | 201 | ); |
190 | 202 | }); |
|
198 | 210 | '{% print(o.zeroValue); %}', |
199 | 211 | data |
200 | 212 | ) |
201 | | - ).to.be( |
| 213 | + ).to.eql( |
202 | 214 | 'false0' |
203 | 215 | ); |
204 | 216 | }); |
|
212 | 224 | '{% print(o.zeroValue, true); %}', |
213 | 225 | data |
214 | 226 | ) |
215 | | - ).to.be( |
| 227 | + ).to.eql( |
216 | 228 | 'false0' |
217 | 229 | ); |
218 | 230 | }); |
219 | 231 |
|
220 | 232 | it('Include template', function () { |
221 | 233 | expect( |
222 | | - tmpl('{% include("template", {value: "value"}); %}', data), |
| 234 | + tmpl('{% include("template", {value: "value"}); %}', data) |
| 235 | + ).to.eql( |
223 | 236 | 'value' |
224 | 237 | ); |
225 | 238 | }); |
226 | 239 |
|
227 | 240 | it('If condition', function () { |
228 | 241 | expect( |
229 | | - tmpl('{% if (o.value) { %}true{% } else { %}false{% } %}', data), |
| 242 | + tmpl('{% if (o.value) { %}true{% } else { %}false{% } %}', data) |
| 243 | + ).to.eql( |
230 | 244 | 'true' |
231 | 245 | ); |
232 | 246 | }); |
|
237 | 251 | '{% if (o.undefinedValue) { %}false{% } else { %}true{% } %}', |
238 | 252 | data |
239 | 253 | ) |
240 | | - ).to.be( |
| 254 | + ).to.eql( |
241 | 255 | 'true' |
242 | 256 | ); |
243 | 257 | }); |
|
249 | 263 | '{%=o.list[i]%}{% } %}', |
250 | 264 | data |
251 | 265 | ) |
252 | | - ).to.be( |
| 266 | + ).to.eql( |
253 | 267 | '12345' |
254 | 268 | ); |
255 | 269 | }); |
|
261 | 275 | 'print(o.list[i]);} %}', |
262 | 276 | data |
263 | 277 | ) |
264 | | - ).to.be( |
| 278 | + ).to.eql( |
265 | 279 | '12345' |
266 | 280 | ); |
267 | 281 | }); |
|
273 | 287 | 'include("template", {value: o.list[i]});} %}', |
274 | 288 | data |
275 | 289 | ).replace(/[\r\n]/g, '') |
276 | | - ).to.be( |
| 290 | + ).to.eql( |
277 | 291 | '12345' |
278 | 292 | ); |
279 | 293 | }); |
|
284 | 298 | '{% if (o.list.length % 5 === 0) { %}5 list items{% } %}', |
285 | 299 | data |
286 | 300 | ).replace(/[\r\n]/g, '') |
287 | | - ).to.be( |
| 301 | + ).to.eql( |
288 | 302 | '5 list items' |
289 | 303 | ); |
290 | 304 | }); |
|
0 commit comments