|
9 | 9 | * http://www.opensource.org/licenses/MIT |
10 | 10 | */ |
11 | 11 |
|
12 | | -/*global beforeEach, afterEach, describe, it, require */ |
| 12 | +/* global beforeEach, afterEach, describe, it */ |
13 | 13 |
|
14 | 14 | ;(function (context, expect, tmpl) { |
15 | 15 | 'use strict' |
|
53 | 53 | it('String template', function () { |
54 | 54 | expect( |
55 | 55 | tmpl('{%=o.value%}', data) |
56 | | - ).to.be( |
| 56 | + ).to.equal( |
57 | 57 | 'value' |
58 | 58 | ) |
59 | 59 | }) |
60 | 60 |
|
61 | 61 | it('Load template by id', function () { |
62 | 62 | expect( |
63 | 63 | tmpl('template', data) |
64 | | - ).to.be( |
| 64 | + ).to.equal( |
65 | 65 | 'value' |
66 | 66 | ) |
67 | 67 | }) |
68 | 68 |
|
69 | 69 | it('Retun function when called without data parameter', function () { |
70 | 70 | expect( |
71 | 71 | tmpl('{%=o.value%}')(data) |
72 | | - ).to.be( |
| 72 | + ).to.equal( |
73 | 73 | 'value' |
74 | 74 | ) |
75 | 75 | }) |
|
86 | 86 | it('Escape HTML special characters with {%=o.prop%}', function () { |
87 | 87 | expect( |
88 | 88 | tmpl('{%=o.special%}', data) |
89 | | - ).to.be( |
| 89 | + ).to.equal( |
90 | 90 | '<>&"'' |
91 | 91 | ) |
92 | 92 | }) |
93 | 93 |
|
94 | 94 | it('Allow HTML special characters with {%#o.prop%}', function () { |
95 | 95 | expect( |
96 | 96 | tmpl('{%#o.special%}', data) |
97 | | - ).to.be( |
| 97 | + ).to.equal( |
98 | 98 | '<>&"\'\x00' |
99 | 99 | ) |
100 | 100 | }) |
101 | 101 |
|
102 | 102 | it('Function call', function () { |
103 | 103 | expect( |
104 | 104 | tmpl('{%=o.func()%}', data) |
105 | | - ).to.be( |
| 105 | + ).to.equal( |
106 | 106 | 'value' |
107 | 107 | ) |
108 | 108 | }) |
109 | 109 |
|
110 | 110 | it('Dot notation', function () { |
111 | 111 | expect( |
112 | 112 | tmpl('{%=o.deep.value%}', data) |
113 | | - ).to.be( |
| 113 | + ).to.equal( |
114 | 114 | 'value' |
115 | 115 | ) |
116 | 116 | }) |
117 | 117 |
|
118 | 118 | it('Handle single quotes', function () { |
119 | 119 | expect( |
120 | 120 | tmpl('\'single quotes\'{%=": \'"%}', data) |
121 | | - ).to.be( |
| 121 | + ).to.equal( |
122 | 122 | "'single quotes': '" |
123 | 123 | ) |
124 | 124 | }) |
125 | 125 |
|
126 | 126 | it('Handle double quotes', function () { |
127 | 127 | expect( |
128 | 128 | tmpl('"double quotes"{%=": \\""%}', data) |
129 | | - ).to.be( |
| 129 | + ).to.equal( |
130 | 130 | '"double quotes": "' |
131 | 131 | ) |
132 | 132 | }) |
133 | 133 |
|
134 | 134 | it('Handle backslashes', function () { |
135 | 135 | expect( |
136 | 136 | tmpl('\\backslashes\\{%=": \\\\"%}', data) |
137 | | - ).to.be( |
| 137 | + ).to.equal( |
138 | 138 | '\\backslashes\\: \\' |
139 | 139 | ) |
140 | 140 | }) |
|
148 | 148 | '{%=o.zeroValue%}', |
149 | 149 | data |
150 | 150 | ) |
151 | | - ).to.be( |
| 151 | + ).to.equal( |
152 | 152 | 'false0' |
153 | 153 | ) |
154 | 154 | }) |
|
162 | 162 | '{%#o.zeroValue%}', |
163 | 163 | data |
164 | 164 | ) |
165 | | - ).to.be( |
| 165 | + ).to.equal( |
166 | 166 | 'false0' |
167 | 167 | ) |
168 | 168 | }) |
|
173 | 173 | '\n\r\t{%=o.value%} \n\r\t{%=o.value%} ', |
174 | 174 | data |
175 | 175 | ) |
176 | | - ).to.be( |
| 176 | + ).to.equal( |
177 | 177 | '\n\r\tvalue \n\r\tvalue ' |
178 | 178 | ) |
179 | 179 | }) |
|
183 | 183 | it('Escape HTML special characters with print(data)', function () { |
184 | 184 | expect( |
185 | 185 | tmpl('{% print(o.special); %}', data) |
186 | | - ).to.be( |
| 186 | + ).to.equal( |
187 | 187 | '<>&"'' |
188 | 188 | ) |
189 | 189 | }) |
190 | 190 |
|
191 | 191 | it('Allow HTML special characters with print(data, true)', function () { |
192 | 192 | expect( |
193 | 193 | tmpl('{% print(o.special, true); %}', data) |
194 | | - ).to.be( |
| 194 | + ).to.equal( |
195 | 195 | '<>&"\'\x00' |
196 | 196 | ) |
197 | 197 | }) |
|
205 | 205 | '{% print(o.zeroValue); %}', |
206 | 206 | data |
207 | 207 | ) |
208 | | - ).to.be( |
| 208 | + ).to.equal( |
209 | 209 | 'false0' |
210 | 210 | ) |
211 | 211 | }) |
|
219 | 219 | '{% print(o.zeroValue, true); %}', |
220 | 220 | data |
221 | 221 | ) |
222 | | - ).to.be( |
| 222 | + ).to.equal( |
223 | 223 | 'false0' |
224 | 224 | ) |
225 | 225 | }) |
226 | 226 |
|
227 | 227 | it('Include template', function () { |
228 | 228 | expect( |
229 | 229 | tmpl('{% include("template", {value: "value"}); %}', data) |
230 | | - ).to.be( |
| 230 | + ).to.equal( |
231 | 231 | 'value' |
232 | 232 | ) |
233 | 233 | }) |
234 | 234 |
|
235 | 235 | it('If condition', function () { |
236 | 236 | expect( |
237 | 237 | tmpl('{% if (o.value) { %}true{% } else { %}false{% } %}', data) |
238 | | - ).to.be( |
| 238 | + ).to.equal( |
239 | 239 | 'true' |
240 | 240 | ) |
241 | 241 | }) |
|
246 | 246 | '{% if (o.undefinedValue) { %}false{% } else { %}true{% } %}', |
247 | 247 | data |
248 | 248 | ) |
249 | | - ).to.be( |
| 249 | + ).to.equal( |
250 | 250 | 'true' |
251 | 251 | ) |
252 | 252 | }) |
|
258 | 258 | '{%=o.list[i]%}{% } %}', |
259 | 259 | data |
260 | 260 | ) |
261 | | - ).to.be( |
| 261 | + ).to.equal( |
262 | 262 | '12345' |
263 | 263 | ) |
264 | 264 | }) |
|
270 | 270 | 'print(o.list[i]);} %}', |
271 | 271 | data |
272 | 272 | ) |
273 | | - ).to.be( |
| 273 | + ).to.equal( |
274 | 274 | '12345' |
275 | 275 | ) |
276 | 276 | }) |
|
282 | 282 | 'include("template", {value: o.list[i]});} %}', |
283 | 283 | data |
284 | 284 | ).replace(/[\r\n]/g, '') |
285 | | - ).to.be( |
| 285 | + ).to.equal( |
286 | 286 | '12345' |
287 | 287 | ) |
288 | 288 | }) |
|
293 | 293 | '{% if (o.list.length % 5 === 0) { %}5 list items{% } %}', |
294 | 294 | data |
295 | 295 | ).replace(/[\r\n]/g, '') |
296 | | - ).to.be( |
| 296 | + ).to.equal( |
297 | 297 | '5 list items' |
298 | 298 | ) |
299 | 299 | }) |
300 | 300 | }) |
301 | 301 | }( |
302 | 302 | this, |
303 | | - this.expect || require('expect.js'), |
| 303 | + (this.chai || require('chai')).expect, |
304 | 304 | this.tmpl || require('../js/tmpl') |
305 | 305 | )) |
0 commit comments