do not trim output tags and previous \n, #19

This commit is contained in:
harttle
2017-01-31 23:15:23 +08:00
parent 0c8148c12b
commit 21eefe1d7b
4 changed files with 27 additions and 35 deletions
+14 -18
View File
@@ -48,7 +48,7 @@ describe('tokenizer', function() {
tokens[2].value.should.equal('foo');
});
it('should keep white spaces and newlines', function() {
var html = '{{foo}}\n{%bar %} \n {{alice}}';
var html = '{%foo%}\n{%bar %} \n {%alice%}';
var tokens = parse(html);
expect(tokens.length).to.equal(5);
expect(tokens[1].type).to.equal('html');
@@ -62,41 +62,37 @@ describe('tokenizer', function() {
expect(whiteSpaceCtrl('\n {%foo%} \n')).to.equal('\n {%foo%} \n');
});
it('should strip all blank characters before and after', function() {
expect(whiteSpaceCtrl('\n \t\r{{-foo-}} \t\n')).to.equal('{{-foo-}}');
expect(whiteSpaceCtrl(' \t\r{%-foo-%} \t\n')).to.equal('{%-foo-%}');
});
it('should not trim previous/next lines', function() {
expect(whiteSpaceCtrl(' \t\n {{-foo-}}')).to.equal(' \t{{-foo-}}');
expect(whiteSpaceCtrl('{{-foo-}} \n \tfoo')).to.equal('{{-foo-}} \tfoo');
});
it("should not trim inter-word blanks", function() {
expect(whiteSpaceCtrl('\nhello {{-world-}}')).to.equal('\nhello {{-world-}}');
expect(whiteSpaceCtrl('{{-hello-}} world')).to.equal('{{-hello-}} world');
expect(whiteSpaceCtrl(' \t\n {%-foo-%}')).to.equal(' \t\n{%-foo-%}');
expect(whiteSpaceCtrl('{%-foo-%} \n \tfoo')).to.equal('{%-foo-%} \tfoo');
});
it('should trim exactly one trailing CR', function() {
expect(whiteSpaceCtrl('{{-foo-}} \n\n')).to.equal('{{-foo-}}\n');
expect(whiteSpaceCtrl('{%-foo-%} \n\n')).to.equal('{%-foo-%}\n');
});
it('should trim all leading/trailing blanks when options.greedy set', function() {
expect(whiteSpaceCtrl(' \n \n\t\r{{-foo-}}\n \n', {
expect(whiteSpaceCtrl(' \n \n\t\r{%-foo-%}\n \n', {
greedy: true
})).to.equal('{{-foo-}}');
})).to.equal('{%-foo-%}');
});
it('should strip whitespaces when set trim_left', function() {
expect(whiteSpaceCtrl('\n {{foo}} \n', {
expect(whiteSpaceCtrl('\n {%foo%} \n', {
trim_left: true
})).to.equal('{{-foo}} \n');
})).to.equal('\n{%-foo%} \n');
});
it('should strip whitespaces when set trim_right', function() {
expect(whiteSpaceCtrl('\n {{foo}} \n', {
expect(whiteSpaceCtrl('\n {%foo%} \n', {
trim_right: true
})).to.equal('\n {{foo-}}');
})).to.equal('\n {%foo-%}');
});
it('markup should has priority over options', function() {
expect(whiteSpaceCtrl('\n {{-foo}} \n', {
expect(whiteSpaceCtrl('\n {%-foo%} \n', {
trim_left: false
})).to.equal('{{-foo}} \n');
})).to.equal('\n{%-foo%} \n');
});
it('should support a mix of markup and options', function() {
expect(whiteSpaceCtrl('\n {%-foo%} \n', {
expect(whiteSpaceCtrl(' {%-foo%} \n', {
trim_left: true,
trim_right: true
})).to.equal('{%-foo-%}');