@@ -123,6 +123,40 @@ describe('ast', function() { |
123 | 123 | }); |
124 | 124 | }); |
125 | 125 |
|
| 126 | + describe('whitespace control', function() { |
| 127 | + describe('parse', function() { |
| 128 | + it('mustache', function() { |
| 129 | + let ast = Handlebars.parse(' {{~comment~}} '); |
| 130 | + |
| 131 | + equals(ast.body[0].value, ''); |
| 132 | + equals(ast.body[2].value, ''); |
| 133 | + }); |
| 134 | + |
| 135 | + it('block statements', function() { |
| 136 | + var ast = Handlebars.parse(' {{# comment~}} \nfoo\n {{~/comment}}'); |
| 137 | + |
| 138 | + equals(ast.body[0].value, ''); |
| 139 | + equals(ast.body[1].program.body[0].value, 'foo'); |
| 140 | + }); |
| 141 | + }); |
| 142 | + |
| 143 | + describe('parseWithoutProcessing', function() { |
| 144 | + it('mustache', function() { |
| 145 | + let ast = Handlebars.parseWithoutProcessing(' {{~comment~}} '); |
| 146 | + |
| 147 | + equals(ast.body[0].value, ' '); |
| 148 | + equals(ast.body[2].value, ' '); |
| 149 | + }); |
| 150 | + |
| 151 | + it('block statements', function() { |
| 152 | + var ast = Handlebars.parseWithoutProcessing(' {{# comment~}} \nfoo\n {{~/comment}}'); |
| 153 | + |
| 154 | + equals(ast.body[0].value, ' '); |
| 155 | + equals(ast.body[1].program.body[0].value, ' \nfoo\n '); |
| 156 | + }); |
| 157 | + }); |
| 158 | + }); |
| 159 | + |
126 | 160 | describe('standalone flags', function() { |
127 | 161 | describe('mustache', function() { |
128 | 162 | it('does not mark mustaches as standalone', function() { |
@@ -131,6 +165,54 @@ describe('ast', function() { |
131 | 165 | equals(!!ast.body[2].value, true); |
132 | 166 | }); |
133 | 167 | }); |
| 168 | + describe('blocks - parseWithoutProcessing', function() { |
| 169 | + it('block mustaches', function() { |
| 170 | + var ast = Handlebars.parseWithoutProcessing(' {{# comment}} \nfoo\n {{else}} \n bar \n {{/comment}} '), |
| 171 | + block = ast.body[1]; |
| 172 | + |
| 173 | + equals(ast.body[0].value, ' '); |
| 174 | + |
| 175 | + equals(block.program.body[0].value, ' \nfoo\n '); |
| 176 | + equals(block.inverse.body[0].value, ' \n bar \n '); |
| 177 | + |
| 178 | + equals(ast.body[2].value, ' '); |
| 179 | + }); |
| 180 | + it('initial block mustaches', function() { |
| 181 | + var ast = Handlebars.parseWithoutProcessing('{{# comment}} \nfoo\n {{/comment}}'), |
| 182 | + block = ast.body[0]; |
| 183 | + |
| 184 | + equals(block.program.body[0].value, ' \nfoo\n '); |
| 185 | + }); |
| 186 | + it('mustaches with children', function() { |
| 187 | + var ast = Handlebars.parseWithoutProcessing('{{# comment}} \n{{foo}}\n {{/comment}}'), |
| 188 | + block = ast.body[0]; |
| 189 | + |
| 190 | + equals(block.program.body[0].value, ' \n'); |
| 191 | + equals(block.program.body[1].path.original, 'foo'); |
| 192 | + equals(block.program.body[2].value, '\n '); |
| 193 | + }); |
| 194 | + it('nested block mustaches', function() { |
| 195 | + var ast = Handlebars.parseWithoutProcessing('{{#foo}} \n{{# comment}} \nfoo\n {{else}} \n bar \n {{/comment}} \n{{/foo}}'), |
| 196 | + body = ast.body[0].program.body, |
| 197 | + block = body[1]; |
| 198 | + |
| 199 | + equals(body[0].value, ' \n'); |
| 200 | + |
| 201 | + equals(block.program.body[0].value, ' \nfoo\n '); |
| 202 | + equals(block.inverse.body[0].value, ' \n bar \n '); |
| 203 | + }); |
| 204 | + it('column 0 block mustaches', function() { |
| 205 | + var ast = Handlebars.parseWithoutProcessing('test\n{{# comment}} \nfoo\n {{else}} \n bar \n {{/comment}} '), |
| 206 | + block = ast.body[1]; |
| 207 | + |
| 208 | + equals(ast.body[0].omit, undefined); |
| 209 | + |
| 210 | + equals(block.program.body[0].value, ' \nfoo\n '); |
| 211 | + equals(block.inverse.body[0].value, ' \n bar \n '); |
| 212 | + |
| 213 | + equals(ast.body[2].value, ' '); |
| 214 | + }); |
| 215 | + }); |
134 | 216 | describe('blocks', function() { |
135 | 217 | it('marks block mustaches as standalone', function() { |
136 | 218 | var ast = Handlebars.parse(' {{# comment}} \nfoo\n {{else}} \n bar \n {{/comment}} '), |
@@ -204,6 +286,18 @@ describe('ast', function() { |
204 | 286 | equals(ast.body[2].value, ''); |
205 | 287 | }); |
206 | 288 | }); |
| 289 | + describe('partials - parseWithoutProcessing', function() { |
| 290 | + it('simple partial', function() { |
| 291 | + var ast = Handlebars.parseWithoutProcessing('{{> partial }} '); |
| 292 | + equals(ast.body[1].value, ' '); |
| 293 | + }); |
| 294 | + it('indented partial', function() { |
| 295 | + var ast = Handlebars.parseWithoutProcessing(' {{> partial }} '); |
| 296 | + equals(ast.body[0].value, ' '); |
| 297 | + equals(ast.body[1].indent, ''); |
| 298 | + equals(ast.body[2].value, ' '); |
| 299 | + }); |
| 300 | + }); |
207 | 301 | describe('partials', function() { |
208 | 302 | it('marks partial as standalone', function() { |
209 | 303 | var ast = Handlebars.parse('{{> partial }} '); |
@@ -223,6 +317,17 @@ describe('ast', function() { |
223 | 317 | equals(ast.body[1].omit, undefined); |
224 | 318 | }); |
225 | 319 | }); |
| 320 | + describe('comments - parseWithoutProcessing', function() { |
| 321 | + it('simple comment', function() { |
| 322 | + var ast = Handlebars.parseWithoutProcessing('{{! comment }} '); |
| 323 | + equals(ast.body[1].value, ' '); |
| 324 | + }); |
| 325 | + it('indented comment', function() { |
| 326 | + var ast = Handlebars.parseWithoutProcessing(' {{! comment }} '); |
| 327 | + equals(ast.body[0].value, ' '); |
| 328 | + equals(ast.body[2].value, ' '); |
| 329 | + }); |
| 330 | + }); |
226 | 331 | describe('comments', function() { |
227 | 332 | it('marks comment as standalone', function() { |
228 | 333 | var ast = Handlebars.parse('{{! comment }} '); |
|