|
13 | 13 |
|
14 | 14 | /* eslint-disable strict */ |
15 | 15 |
|
16 | | -;(function(context, expect, tmpl) { |
| 16 | +;(function (context, expect, tmpl) { |
17 | 17 | 'use strict' |
18 | 18 |
|
19 | 19 | if (context.require === undefined) { |
20 | 20 | // Override the template loading method: |
21 | | - tmpl.load = function(id) { |
| 21 | + tmpl.load = function (id) { |
22 | 22 | switch (id) { |
23 | 23 | case 'template': |
24 | 24 | return '{%=o.value%}' |
|
28 | 28 |
|
29 | 29 | var data |
30 | 30 |
|
31 | | - beforeEach(function() { |
| 31 | + beforeEach(function () { |
32 | 32 | // Initialize the sample data: |
33 | 33 | data = { |
34 | 34 | value: 'value', |
|
37 | 37 | zeroValue: 0, |
38 | 38 | special: '<>&"\'\x00', |
39 | 39 | list: [1, 2, 3, 4, 5], |
40 | | - func: function() { |
| 40 | + func: function () { |
41 | 41 | return this.value |
42 | 42 | }, |
43 | 43 | deep: { |
|
46 | 46 | } |
47 | 47 | }) |
48 | 48 |
|
49 | | - afterEach(function() { |
| 49 | + afterEach(function () { |
50 | 50 | // Purge the template cache: |
51 | 51 | tmpl.cache = {} |
52 | 52 | }) |
53 | 53 |
|
54 | | - describe('Template loading', function() { |
55 | | - it('String template', function() { |
| 54 | + describe('Template loading', function () { |
| 55 | + it('String template', function () { |
56 | 56 | expect(tmpl('{%=o.value%}', data)).to.equal('value') |
57 | 57 | }) |
58 | 58 |
|
59 | | - it('Load template by id', function() { |
| 59 | + it('Load template by id', function () { |
60 | 60 | expect(tmpl('template', data)).to.equal('value') |
61 | 61 | }) |
62 | 62 |
|
63 | | - it('Retun function when called without data parameter', function() { |
| 63 | + it('Retun function when called without data parameter', function () { |
64 | 64 | expect(tmpl('{%=o.value%}')(data)).to.equal('value') |
65 | 65 | }) |
66 | 66 |
|
67 | | - it('Cache templates loaded by id', function() { |
| 67 | + it('Cache templates loaded by id', function () { |
68 | 68 | tmpl('template') |
69 | 69 | expect(tmpl.cache.template).to.be.a('function') |
70 | 70 | }) |
71 | 71 | }) |
72 | 72 |
|
73 | | - describe('Interpolation', function() { |
74 | | - it('Escape HTML special characters with {%=o.prop%}', function() { |
| 73 | + describe('Interpolation', function () { |
| 74 | + it('Escape HTML special characters with {%=o.prop%}', function () { |
75 | 75 | expect(tmpl('{%=o.special%}', data)).to.equal('<>&"'') |
76 | 76 | }) |
77 | 77 |
|
78 | | - it('Allow HTML special characters with {%#o.prop%}', function() { |
| 78 | + it('Allow HTML special characters with {%#o.prop%}', function () { |
79 | 79 | expect(tmpl('{%#o.special%}', data)).to.equal('<>&"\'\x00') |
80 | 80 | }) |
81 | 81 |
|
82 | | - it('Function call', function() { |
| 82 | + it('Function call', function () { |
83 | 83 | expect(tmpl('{%=o.func()%}', data)).to.equal('value') |
84 | 84 | }) |
85 | 85 |
|
86 | | - it('Dot notation', function() { |
| 86 | + it('Dot notation', function () { |
87 | 87 | expect(tmpl('{%=o.deep.value%}', data)).to.equal('value') |
88 | 88 | }) |
89 | 89 |
|
90 | | - it('Handle single quotes', function() { |
| 90 | + it('Handle single quotes', function () { |
91 | 91 | expect(tmpl("'single quotes'{%=\": '\"%}", data)).to.equal( |
92 | 92 | "'single quotes': '" |
93 | 93 | ) |
94 | 94 | }) |
95 | 95 |
|
96 | | - it('Handle double quotes', function() { |
| 96 | + it('Handle double quotes', function () { |
97 | 97 | expect(tmpl('"double quotes"{%=": \\""%}', data)).to.equal( |
98 | 98 | '"double quotes": "' |
99 | 99 | ) |
100 | 100 | }) |
101 | 101 |
|
102 | | - it('Handle backslashes', function() { |
| 102 | + it('Handle backslashes', function () { |
103 | 103 | expect(tmpl('\\backslashes\\{%=": \\\\"%}', data)).to.equal( |
104 | 104 | '\\backslashes\\: \\' |
105 | 105 | ) |
106 | 106 | }) |
107 | 107 |
|
108 | | - it('Interpolate escaped falsy values except undefined or null', function() { |
| 108 | + it('Interpolate escaped falsy values except undefined or null', function () { |
109 | 109 | expect( |
110 | 110 | tmpl( |
111 | 111 | '{%=o.undefinedValue%}' + |
|
117 | 117 | ).to.equal('false0') |
118 | 118 | }) |
119 | 119 |
|
120 | | - it('Interpolate unescaped falsy values except undefined or null', function() { |
| 120 | + it('Interpolate unescaped falsy values except undefined or null', function () { |
121 | 121 | expect( |
122 | 122 | tmpl( |
123 | 123 | '{%#o.undefinedValue%}' + |
|
129 | 129 | ).to.equal('false0') |
130 | 130 | }) |
131 | 131 |
|
132 | | - it('Preserve whitespace', function() { |
| 132 | + it('Preserve whitespace', function () { |
133 | 133 | expect(tmpl('\n\r\t{%=o.value%} \n\r\t{%=o.value%} ', data)).to.equal( |
134 | 134 | '\n\r\tvalue \n\r\tvalue ' |
135 | 135 | ) |
136 | 136 | }) |
137 | 137 | }) |
138 | 138 |
|
139 | | - describe('Evaluation', function() { |
140 | | - it('Escape HTML special characters with print(data)', function() { |
| 139 | + describe('Evaluation', function () { |
| 140 | + it('Escape HTML special characters with print(data)', function () { |
141 | 141 | expect(tmpl('{% print(o.special); %}', data)).to.equal( |
142 | 142 | '<>&"'' |
143 | 143 | ) |
144 | 144 | }) |
145 | 145 |
|
146 | | - it('Allow HTML special characters with print(data, true)', function() { |
| 146 | + it('Allow HTML special characters with print(data, true)', function () { |
147 | 147 | expect(tmpl('{% print(o.special, true); %}', data)).to.equal('<>&"\'\x00') |
148 | 148 | }) |
149 | 149 |
|
150 | | - it('Print out escaped falsy values except undefined or null', function() { |
| 150 | + it('Print out escaped falsy values except undefined or null', function () { |
151 | 151 | expect( |
152 | 152 | tmpl( |
153 | 153 | '{% print(o.undefinedValue); %}' + |
|
159 | 159 | ).to.equal('false0') |
160 | 160 | }) |
161 | 161 |
|
162 | | - it('Print out unescaped falsy values except undefined or null', function() { |
| 162 | + it('Print out unescaped falsy values except undefined or null', function () { |
163 | 163 | expect( |
164 | 164 | tmpl( |
165 | 165 | '{% print(o.undefinedValue, true); %}' + |
|
171 | 171 | ).to.equal('false0') |
172 | 172 | }) |
173 | 173 |
|
174 | | - it('Include template', function() { |
| 174 | + it('Include template', function () { |
175 | 175 | expect( |
176 | 176 | tmpl('{% include("template", {value: "value"}); %}', data) |
177 | 177 | ).to.equal('value') |
178 | 178 | }) |
179 | 179 |
|
180 | | - it('If condition', function() { |
| 180 | + it('If condition', function () { |
181 | 181 | expect( |
182 | 182 | tmpl('{% if (o.value) { %}true{% } else { %}false{% } %}', data) |
183 | 183 | ).to.equal('true') |
184 | 184 | }) |
185 | 185 |
|
186 | | - it('Else condition', function() { |
| 186 | + it('Else condition', function () { |
187 | 187 | expect( |
188 | 188 | tmpl( |
189 | 189 | '{% if (o.undefinedValue) { %}false{% } else { %}true{% } %}', |
|
192 | 192 | ).to.equal('true') |
193 | 193 | }) |
194 | 194 |
|
195 | | - it('For loop', function() { |
| 195 | + it('For loop', function () { |
196 | 196 | expect( |
197 | 197 | tmpl( |
198 | 198 | '{% for (var i=0; i<o.list.length; i++) { %}' + |
|
202 | 202 | ).to.equal('12345') |
203 | 203 | }) |
204 | 204 |
|
205 | | - it('For loop print call', function() { |
| 205 | + it('For loop print call', function () { |
206 | 206 | expect( |
207 | 207 | tmpl( |
208 | 208 | '{% for (var i=0; i<o.list.length; i++) {print(o.list[i]);} %}', |
|
211 | 211 | ).to.equal('12345') |
212 | 212 | }) |
213 | 213 |
|
214 | | - it('For loop include template', function() { |
| 214 | + it('For loop include template', function () { |
215 | 215 | expect( |
216 | 216 | tmpl( |
217 | 217 | '{% for (var i=0; i<o.list.length; i++) {' + |
|
221 | 221 | ).to.equal('12345') |
222 | 222 | }) |
223 | 223 |
|
224 | | - it('Modulo operator', function() { |
| 224 | + it('Modulo operator', function () { |
225 | 225 | expect( |
226 | 226 | tmpl( |
227 | 227 | '{% if (o.list.length % 5 === 0) { %}5 list items{% } %}', |
|
0 commit comments