diff options
author | kpdecker <kpdecker@gmail.com> | 2013-07-30 02:53:07 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2013-10-14 22:50:50 -0500 |
commit | 5b483ff78decee27c221fabdbccffec614cedadd (patch) | |
tree | e3af806510e3dcebcebeca1b976c05dfeea182ae | |
parent | 30384789d261159985f1582934ed28e954b84836 (diff) | |
download | handlebars.js-5b483ff78decee27c221fabdbccffec614cedadd.zip handlebars.js-5b483ff78decee27c221fabdbccffec614cedadd.tar.gz handlebars.js-5b483ff78decee27c221fabdbccffec614cedadd.tar.bz2 |
Define test cases
-rw-r--r-- | spec/whitespace-control.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/whitespace-control.js b/spec/whitespace-control.js new file mode 100644 index 0000000..3a2711d --- /dev/null +++ b/spec/whitespace-control.js @@ -0,0 +1,62 @@ +describe('whitespace control', function() { + it('should strip whitespace around mustache calls', function() { + var hash = {foo: 'bar<'}; + + shouldCompileTo(' {{(foo)}} ', hash, 'bar<'); + shouldCompileTo(' {{(foo}} ', hash, 'bar< '); + shouldCompileTo(' {{foo)}} ', hash, ' bar<'); + + shouldCompileTo(' {{(&foo)}} ', hash, 'bar<'); + shouldCompileTo(' {{({foo})}} ', hash, 'bar<'); + }); + + describe('blocks', function() { + it('should strip whitespace around simple block calls', function() { + var hash = {foo: 'bar<'}; + + shouldCompileTo(' {{(#if foo)}} bar {{(/if)}} ', hash, 'bar'); + shouldCompileTo(' {{#if foo)}} bar {{/if)}} ', hash, ' bar '); + shouldCompileTo(' {{(#if foo}} bar {{(/if}} ', hash, ' bar '); + shouldCompileTo(' {{#if foo}} bar {{/if}} ', hash, ' bar '); + }); + it('should strip whitespace around inverse block calls', function() { + var hash = {}; + + shouldCompileTo(' {{(^if foo)}} bar {{(/if)}} ', hash, 'bar'); + shouldCompileTo(' {{^if foo)}} bar {{/if)}} ', hash, ' bar '); + shouldCompileTo(' {{(^if foo}} bar {{(/if}} ', hash, ' bar '); + shouldCompileTo(' {{^if foo}} bar {{/if}} ', hash, ' bar '); + }); + it('should strip whitespace around complex block calls', function() { + var hash = {foo: 'bar<'}; + + shouldCompileTo('{{#if foo)}} bar {{(^)}} baz {{(/if}}', hash, 'bar'); + shouldCompileTo('{{#if foo)}} bar {{^)}} baz {{/if}}', hash, 'bar '); + shouldCompileTo('{{#if foo}} bar {{(^)}} baz {{(/if}}', hash, ' bar'); + shouldCompileTo('{{#if foo}} bar {{^)}} baz {{/if}}', hash, ' bar '); + + shouldCompileTo('{{#if foo)}} bar {{(else)}} baz {{(/if}}', hash, 'bar'); + + hash = {}; + + shouldCompileTo('{{#if foo)}} bar {{(^)}} baz {{(/if}}', hash, 'baz'); + shouldCompileTo('{{#if foo}} bar {{(^)}} baz {{/if}}', hash, 'baz '); + shouldCompileTo('{{#if foo)}} bar {{(^}} baz {{(/if}}', hash, ' baz'); + shouldCompileTo('{{#if foo)}} bar {{(^}} baz {{/if}}', hash, ' baz '); + + shouldCompileTo('{{#if foo)}} bar {{(else)}} baz {{(/if}}', hash, 'baz'); + }); + }); + + it('should strip whitespace around partials', function() { + shouldCompileToWithPartials('foo {{(> dude)}} ', [{}, {}, {dude: 'bar'}], true, 'foobar'); + shouldCompileToWithPartials('foo {{> dude)}} ', [{}, {}, {dude: 'bar'}], true, 'foo bar'); + shouldCompileToWithPartials('foo {{> dude}} ', [{}, {}, {dude: 'bar'}], true, 'foo bar '); + }); + + it('should only strip whitespace once', function() { + var hash = {foo: 'bar'}; + + shouldCompileTo(' {{(foo)}} {{foo}} {{foo}} ', hash, 'barbar bar '); + }); +}); |