mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
feature: Allow hyphens in identifiers, working on #14
This commit is contained in:
+39
-10
@@ -1,11 +1,10 @@
|
||||
var chai = require("chai");
|
||||
var should = chai.should();
|
||||
var expect = chai.expect;
|
||||
const chai = require("chai");
|
||||
const expect = chai.expect;
|
||||
|
||||
var lexical = require('../src/lexical.js');
|
||||
|
||||
describe('lexical', function() {
|
||||
it('should test filter syntax', function(){
|
||||
it('should test filter syntax', function() {
|
||||
lexical.filterLine.test('abs').should.equal(true);
|
||||
lexical.filterLine.test('plus:1').should.equal(true);
|
||||
lexical.filterLine.test('replace: "a", b').should.equal(true);
|
||||
@@ -40,24 +39,36 @@ describe('lexical', function() {
|
||||
});
|
||||
|
||||
describe('.isVariable()', function() {
|
||||
it('should return true for foo', function(){
|
||||
it('should return true for foo', function() {
|
||||
lexical.isVariable("foo").should.equal(true);
|
||||
});
|
||||
it('should return true for.bar.foo', function(){
|
||||
it('should return true for.bar.foo', function() {
|
||||
lexical.isVariable("foo.bar.foo").should.equal(true);
|
||||
});
|
||||
it('should return true for foo[0].b', function(){
|
||||
it('should return true for foo[0].b', function() {
|
||||
lexical.isVariable("foo[0].b").should.equal(true);
|
||||
});
|
||||
it('should return true for 0a', function(){
|
||||
it('should return true for 0a', function() {
|
||||
lexical.isVariable("0a").should.equal(true);
|
||||
});
|
||||
it('should return true for foo[a.b]', function(){
|
||||
it('should return true for foo[a.b]', function() {
|
||||
lexical.isVariable("foo[a.b]").should.equal(true);
|
||||
});
|
||||
it('should return true for foo[a.b]', function(){
|
||||
it('should return true for foo[a.b]', function() {
|
||||
lexical.isVariable("foo['a[0]']").should.equal(true);
|
||||
});
|
||||
it('should return true for "var-1"', function() {
|
||||
lexical.isVariable("var-1").should.equal(true);
|
||||
});
|
||||
it('should return true for "-var"', function() {
|
||||
lexical.isVariable("-var").should.equal(true);
|
||||
});
|
||||
it('should return true for "var-"', function() {
|
||||
lexical.isVariable("var-").should.equal(true);
|
||||
});
|
||||
it('should return true for "3-4"', function() {
|
||||
lexical.isVariable("3-4").should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should test none literal', function() {
|
||||
@@ -90,4 +101,22 @@ describe('lexical', function() {
|
||||
lexical.parseLiteral('"ab\'c"').should.equal("ab\'c");
|
||||
});
|
||||
|
||||
describe('.matchValue()', function(){
|
||||
it('should match -5-5', function() {
|
||||
var match = lexical.matchValue('-5-5');
|
||||
expect(match && match[0]).to.equal('-5-5');
|
||||
});
|
||||
it('should match 4-3', function() {
|
||||
var match = lexical.matchValue('4-3');
|
||||
expect(match && match[0]).to.equal('4-3');
|
||||
});
|
||||
it('should match 4-3', function() {
|
||||
var match = lexical.matchValue('4-3');
|
||||
expect(match && match[0]).to.equal('4-3');
|
||||
});
|
||||
it('should match var-1', function() {
|
||||
var match = lexical.matchValue('var-1');
|
||||
expect(match && match[0]).to.equal('var-1');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+27
-3
@@ -5,19 +5,43 @@ chai.use(require("chai-as-promised"));
|
||||
|
||||
describe('tags/assign', function() {
|
||||
var liquid = Liquid();
|
||||
it('should support assign 1', function() {
|
||||
it('should assign as string', function() {
|
||||
var src = '{% assign foo="bar" %}{{foo}}';
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('bar');
|
||||
});
|
||||
it('should support assign 2', function() {
|
||||
it('should assign as array', function() {
|
||||
var src = '{% assign foo=(1..3) %}{{foo}}';
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('[1,2,3]');
|
||||
});
|
||||
it('should support assign 3', function() {
|
||||
it('should assign as filter result', function() {
|
||||
var src = '{% assign foo="a b" | capitalize | split: " " | first %}{{foo}}';
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('A');
|
||||
});
|
||||
it('should assign var-1', function() {
|
||||
var src = '{% assign var-1 = 5 %}{{ var-1 }}';
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal('5');
|
||||
});
|
||||
it('should assign var-', function() {
|
||||
var src = '{% assign var- = 5 %}{{ var- }}';
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal('5');
|
||||
});
|
||||
it('should assign -var', function() {
|
||||
var src = '{% assign -var = 5 %}{{ -var }}';
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal('5');
|
||||
});
|
||||
it('should assign -5-5', function() {
|
||||
var src = '{% assign -5-5 = 5 %}{{ -5-5 }}';
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal('5');
|
||||
});
|
||||
it('should assign 4-3', function() {
|
||||
var src = '{% assign 4-3 = 5 %}{{ 4-3 }}';
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal('5');
|
||||
});
|
||||
it('should not assign -6', function() {
|
||||
var src = '{% assign -6 = 5 %}{{ -6 }}';
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal('-6');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user