Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
handlebars.js/spec/whitespace-control.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
147 lines (109 sloc)
4.27 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('whitespace control', function () { | |
it('should strip whitespace around mustache calls', function () { | |
var hash = { foo: 'bar<' }; | |
expectTemplate(' {{~foo~}} ').withInput(hash).toCompileTo('bar<'); | |
expectTemplate(' {{~foo}} ').withInput(hash).toCompileTo('bar< '); | |
expectTemplate(' {{foo~}} ').withInput(hash).toCompileTo(' bar<'); | |
expectTemplate(' {{~&foo~}} ').withInput(hash).toCompileTo('bar<'); | |
expectTemplate(' {{~{foo}~}} ').withInput(hash).toCompileTo('bar<'); | |
expectTemplate('1\n{{foo~}} \n\n 23\n{{bar}}4').toCompileTo('1\n23\n4'); | |
}); | |
describe('blocks', function () { | |
it('should strip whitespace around simple block calls', function () { | |
var hash = { foo: 'bar<' }; | |
expectTemplate(' {{~#if foo~}} bar {{~/if~}} ') | |
.withInput(hash) | |
.toCompileTo('bar'); | |
expectTemplate(' {{#if foo~}} bar {{/if~}} ') | |
.withInput(hash) | |
.toCompileTo(' bar '); | |
expectTemplate(' {{~#if foo}} bar {{~/if}} ') | |
.withInput(hash) | |
.toCompileTo(' bar '); | |
expectTemplate(' {{#if foo}} bar {{/if}} ') | |
.withInput(hash) | |
.toCompileTo(' bar '); | |
expectTemplate(' \n\n{{~#if foo~}} \n\nbar \n\n{{~/if~}}\n\n ') | |
.withInput(hash) | |
.toCompileTo('bar'); | |
expectTemplate(' a\n\n{{~#if foo~}} \n\nbar \n\n{{~/if~}}\n\na ') | |
.withInput(hash) | |
.toCompileTo(' abara '); | |
}); | |
it('should strip whitespace around inverse block calls', function () { | |
expectTemplate(' {{~^if foo~}} bar {{~/if~}} ').toCompileTo('bar'); | |
expectTemplate(' {{^if foo~}} bar {{/if~}} ').toCompileTo(' bar '); | |
expectTemplate(' {{~^if foo}} bar {{~/if}} ').toCompileTo(' bar '); | |
expectTemplate(' {{^if foo}} bar {{/if}} ').toCompileTo(' bar '); | |
expectTemplate( | |
' \n\n{{~^if foo~}} \n\nbar \n\n{{~/if~}}\n\n ' | |
).toCompileTo('bar'); | |
}); | |
it('should strip whitespace around complex block calls', function () { | |
var hash = { foo: 'bar<' }; | |
expectTemplate('{{#if foo~}} bar {{~^~}} baz {{~/if}}') | |
.withInput(hash) | |
.toCompileTo('bar'); | |
expectTemplate('{{#if foo~}} bar {{^~}} baz {{/if}}') | |
.withInput(hash) | |
.toCompileTo('bar '); | |
expectTemplate('{{#if foo}} bar {{~^~}} baz {{~/if}}') | |
.withInput(hash) | |
.toCompileTo(' bar'); | |
expectTemplate('{{#if foo}} bar {{^~}} baz {{/if}}') | |
.withInput(hash) | |
.toCompileTo(' bar '); | |
expectTemplate('{{#if foo~}} bar {{~else~}} baz {{~/if}}') | |
.withInput(hash) | |
.toCompileTo('bar'); | |
expectTemplate( | |
'\n\n{{~#if foo~}} \n\nbar \n\n{{~^~}} \n\nbaz \n\n{{~/if~}}\n\n' | |
) | |
.withInput(hash) | |
.toCompileTo('bar'); | |
expectTemplate( | |
'\n\n{{~#if foo~}} \n\n{{{foo}}} \n\n{{~^~}} \n\nbaz \n\n{{~/if~}}\n\n' | |
) | |
.withInput(hash) | |
.toCompileTo('bar<'); | |
expectTemplate('{{#if foo~}} bar {{~^~}} baz {{~/if}}').toCompileTo( | |
'baz' | |
); | |
expectTemplate('{{#if foo}} bar {{~^~}} baz {{/if}}').toCompileTo('baz '); | |
expectTemplate('{{#if foo~}} bar {{~^}} baz {{~/if}}').toCompileTo( | |
' baz' | |
); | |
expectTemplate('{{#if foo~}} bar {{~^}} baz {{/if}}').toCompileTo( | |
' baz ' | |
); | |
expectTemplate('{{#if foo~}} bar {{~else~}} baz {{~/if}}').toCompileTo( | |
'baz' | |
); | |
expectTemplate( | |
'\n\n{{~#if foo~}} \n\nbar \n\n{{~^~}} \n\nbaz \n\n{{~/if~}}\n\n' | |
).toCompileTo('baz'); | |
}); | |
}); | |
it('should strip whitespace around partials', function () { | |
expectTemplate('foo {{~> dude~}} ') | |
.withPartials({ dude: 'bar' }) | |
.toCompileTo('foobar'); | |
expectTemplate('foo {{> dude~}} ') | |
.withPartials({ dude: 'bar' }) | |
.toCompileTo('foo bar'); | |
expectTemplate('foo {{> dude}} ') | |
.withPartials({ dude: 'bar' }) | |
.toCompileTo('foo bar '); | |
expectTemplate('foo\n {{~> dude}} ') | |
.withPartials({ dude: 'bar' }) | |
.toCompileTo('foobar'); | |
expectTemplate('foo\n {{> dude}} ') | |
.withPartials({ dude: 'bar' }) | |
.toCompileTo('foo\n bar'); | |
}); | |
it('should only strip whitespace once', function () { | |
expectTemplate(' {{~foo~}} {{foo}} {{foo}} ') | |
.withInput({ foo: 'bar' }) | |
.toCompileTo('barbar bar '); | |
}); | |
}); |