raw and comment

This commit is contained in:
harttle
2016-06-20 01:10:43 +08:00
parent 54bc206d36
commit 8053d7021f
16 changed files with 105 additions and 51 deletions
-6
View File
@@ -27,12 +27,6 @@ describe('tag', function() {
}).to.throw(/tag foo not found/);
});
it('should throw when render method not defined', function() {
expect(function() {
tag.register('foo', {});
}).to.throw(/expect foo.render to be a function/);
});
it('should register simple tag', function() {
expect(
function() {
+12
View File
@@ -34,6 +34,18 @@ describe('tags', function() {
test('{% assign foo="a b" | capitalize | split: " " | first %}{{foo}}', 'A');
});
it('should support raw', function() {
testThrow('{% raw%}', /{% raw%} not closed/);
test('{% raw %}{{ 5 | plus: 6 }}{% endraw %} is equal to 11.', '{{ 5 | plus: 6 }} is equal to 11.');
test('{% raw %}\n{{ foo}} \n{% endraw %}', '\n{{ foo}} \n');
});
it('should support comment', function() {
testThrow('{% comment %}{% raw%}', /{% comment %} not closed/);
test('My name is {% comment %}super{% endcomment %} Shopify.', 'My name is Shopify.');
test('{% comment %}\n{{ foo}} \n{% endcomment %}', '');
});
it('should support case', function() {
testThrow('{% case "foo"%}', /{% case "foo"%} not closed/);
test('{% case "foo"%}' +
+10
View File
@@ -1,5 +1,6 @@
var chai = require("chai");
var should = chai.should();
var expect = chai.expect;
var tokenizer = require('../tokenizer.js');
@@ -39,4 +40,13 @@ describe('tokenizer', function() {
tokens[1].value.should.equal('bar');
tokens[2].value.should.equal('foo');
});
it('should keep white spaces and newlines', function(){
var html = '{{foo}}\n{%bar %} \n {{alice}}';
var tokens = tokenizer.parse(html);
expect(tokens.length).to.equal(5);
expect(tokens[1].type).to.equal('html');
expect(tokens[1].raw).to.equal('\n');
expect(tokens[3].type).to.equal('html');
expect(tokens[3].raw).to.equal(' \n ');
});
});