mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
cover all
This commit is contained in:
+14
-4
@@ -300,6 +300,9 @@ describe('filters', function () {
|
||||
it('should not truncate when short enough', function () {
|
||||
return test('{{ "12345" | truncate: 5 }}', '12345')
|
||||
})
|
||||
it('should default to 16', function () {
|
||||
return test('{{ "1234567890abcdefghi" | truncate }}', '1234567890abc...')
|
||||
})
|
||||
})
|
||||
|
||||
describe('truncatewords', function () {
|
||||
@@ -321,10 +324,17 @@ describe('filters', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('should support uniq', function () {
|
||||
return test('{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}' +
|
||||
'{{ my_array | uniq | join: ", " }}',
|
||||
'ants, bugs, bees')
|
||||
describe('uniq', function () {
|
||||
it('should uniq string list', function () {
|
||||
return test(
|
||||
'{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}' +
|
||||
'{{ my_array | uniq | join: ", " }}',
|
||||
'ants, bugs, bees'
|
||||
)
|
||||
})
|
||||
it('should uniq falsy value', function () {
|
||||
return test('{{"" | uniq | join: ","}}', '')
|
||||
})
|
||||
})
|
||||
|
||||
it('should support upcase', () => test('{{ "Parker Moore" | upcase }}', 'PARKER MOORE'))
|
||||
|
||||
+20
-13
@@ -86,21 +86,28 @@ describe('lexical', function () {
|
||||
expect(lexical.isVariable('[0][12].bar[0]')).to.equal(false)
|
||||
})
|
||||
|
||||
it('should parse boolean literal', function () {
|
||||
expect(lexical.parseLiteral('true')).to.equal(true)
|
||||
expect(lexical.parseLiteral('TrUE')).to.equal(true)
|
||||
expect(lexical.parseLiteral('false')).to.equal(false)
|
||||
})
|
||||
describe('.parseLiteral()', function () {
|
||||
it('should parse boolean literal', function () {
|
||||
expect(lexical.parseLiteral('true')).to.equal(true)
|
||||
expect(lexical.parseLiteral('TrUE')).to.equal(true)
|
||||
expect(lexical.parseLiteral('false')).to.equal(false)
|
||||
})
|
||||
|
||||
it('should parse number literal', function () {
|
||||
expect(lexical.parseLiteral('2.3')).to.equal(2.3)
|
||||
expect(lexical.parseLiteral('.32')).to.equal(0.32)
|
||||
expect(lexical.parseLiteral('-23.')).to.equal(-23)
|
||||
expect(lexical.parseLiteral('23')).to.equal(23)
|
||||
})
|
||||
it('should parse number literal', function () {
|
||||
expect(lexical.parseLiteral('2.3')).to.equal(2.3)
|
||||
expect(lexical.parseLiteral('.32')).to.equal(0.32)
|
||||
expect(lexical.parseLiteral('-23.')).to.equal(-23)
|
||||
expect(lexical.parseLiteral('23')).to.equal(23)
|
||||
})
|
||||
|
||||
it('should parse string literal', function () {
|
||||
expect(lexical.parseLiteral('"ab\'c"')).to.equal("ab'c")
|
||||
it('should parse string literal', function () {
|
||||
expect(lexical.parseLiteral('"ab\'c"')).to.equal("ab'c")
|
||||
})
|
||||
|
||||
it('should throw if non-literal', function () {
|
||||
var fn = () => lexical.parseLiteral('a')
|
||||
expect(fn).to.throw("cannot parse 'a' as literal")
|
||||
})
|
||||
})
|
||||
|
||||
describe('.matchValue()', function () {
|
||||
|
||||
+15
-8
@@ -20,15 +20,22 @@ describe('expression', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('should eval literals', function () {
|
||||
expect(evalValue('2.3')).to.equal(2.3)
|
||||
expect(evalValue('"foo"')).to.equal('foo')
|
||||
})
|
||||
describe('.evalValue()', function () {
|
||||
it('should eval literals', function () {
|
||||
expect(evalValue('2.3')).to.equal(2.3)
|
||||
expect(evalValue('"foo"')).to.equal('foo')
|
||||
})
|
||||
|
||||
it('should eval variables', function () {
|
||||
expect(evalValue('23', scope)).to.equal(23)
|
||||
expect(evalValue('one', scope)).to.equal(1)
|
||||
expect(evalValue('x', scope)).to.equal('XXX')
|
||||
it('should eval variables', function () {
|
||||
expect(evalValue('23', scope)).to.equal(23)
|
||||
expect(evalValue('one', scope)).to.equal(1)
|
||||
expect(evalValue('x', scope)).to.equal('XXX')
|
||||
})
|
||||
|
||||
it('should throw if not valid', function () {
|
||||
var fn = () => evalValue('===')
|
||||
expect(fn).to.throw("cannot eval '===' as value")
|
||||
})
|
||||
})
|
||||
|
||||
describe('.isTruthy()', function () {
|
||||
|
||||
+12
-5
@@ -6,19 +6,19 @@ chai.use(require('chai-as-promised'))
|
||||
describe('tags/case', function () {
|
||||
var liquid = Liquid()
|
||||
|
||||
it('should support case 1', function () {
|
||||
it('should reject if not closed', function () {
|
||||
var src = '{% case "foo"%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/{% case "foo"%} not closed/)
|
||||
})
|
||||
it('should support case 2', function () {
|
||||
it('should hit the specified case', function () {
|
||||
var src = '{% case "foo"%}' +
|
||||
'{% when "foo" %}foo{% when "bar"%}bar' +
|
||||
'{%endcase%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('foo')
|
||||
})
|
||||
it('should support case 3', function () {
|
||||
it('should resolve empty string if not hit', function () {
|
||||
var src = '{% case empty %}' +
|
||||
'{% when "foo" %}foo{% when ""%}bar' +
|
||||
'{%endcase%}'
|
||||
@@ -28,14 +28,21 @@ describe('tags/case', function () {
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('bar')
|
||||
})
|
||||
it('should support case 4', function () {
|
||||
it('should accept empty string as branch name', function () {
|
||||
var src = '{% case false %}' +
|
||||
'{% when "foo" %}foo{% when ""%}bar' +
|
||||
'{%endcase%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('')
|
||||
})
|
||||
it('should support case 5', function () {
|
||||
it('should support boolean case', function () {
|
||||
var src = '{% case false %}' +
|
||||
'{% when "foo" %}foo{% when false%}bar' +
|
||||
'{%endcase%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('bar')
|
||||
})
|
||||
it('should support else branch', function () {
|
||||
var src = '{% case "a" %}' +
|
||||
'{% when "b" %}b{% when "c"%}c{%else %}d' +
|
||||
'{%endcase%}'
|
||||
|
||||
+28
-2
@@ -36,8 +36,22 @@ describe('util/strftime', function () {
|
||||
it('should format %I as 0 padded hour12', function () {
|
||||
expect(t(now, '%I')).to.equal('01')
|
||||
})
|
||||
it('should format %j as day of year', function () {
|
||||
expect(t(then, '%j')).to.equal('066')
|
||||
it('should format %I as 12 for 00:00', function () {
|
||||
var date = new Date('2016-01-01T00:00:00')
|
||||
expect(t(date, '%I')).to.equal('12')
|
||||
})
|
||||
describe('%j', function () {
|
||||
it('should format %j as day of year', function () {
|
||||
expect(t(then, '%j')).to.equal('066')
|
||||
})
|
||||
it('should take count of leap years', function () {
|
||||
var date = new Date('2001-03-01')
|
||||
expect(t(date, '%j')).to.equal('060')
|
||||
})
|
||||
it('should take count of leap years', function () {
|
||||
var date = new Date('2000-03-01')
|
||||
expect(t(date, '%j')).to.equal('061')
|
||||
})
|
||||
})
|
||||
it('should format %k as space padded hour', function () {
|
||||
expect(t(then, '%k')).to.equal(' 3')
|
||||
@@ -45,6 +59,10 @@ describe('util/strftime', function () {
|
||||
it('should format %l as space padded hour12', function () {
|
||||
expect(t(now, '%l')).to.equal(' 1')
|
||||
})
|
||||
it('should format %l as 12 for 00:00', function () {
|
||||
var date = new Date('2016-01-01T00:00:00')
|
||||
expect(t(date, '%l')).to.equal('12')
|
||||
})
|
||||
it('should format %L as 0 padded millisecond', function () {
|
||||
expect(t(then, '%L')).to.equal('000')
|
||||
})
|
||||
@@ -94,9 +112,17 @@ describe('util/strftime', function () {
|
||||
it('should format %z as time zone', function () {
|
||||
expect(t(now, '%z')).to.equal('+0800')
|
||||
})
|
||||
it('should format %z as negative time zone', function () {
|
||||
var date = new Date('2016-01-04T13:15:23')
|
||||
date.getTimezoneOffset = () => 480
|
||||
expect(t(date, '%z')).to.equal('-0800')
|
||||
})
|
||||
it('should escape %% as %', function () {
|
||||
expect(t(now, '%%')).to.equal('%')
|
||||
})
|
||||
it('should retain un-recognized formaters', function () {
|
||||
expect(t(now, '%o')).to.equal('%o')
|
||||
})
|
||||
})
|
||||
|
||||
function mockUTC () {
|
||||
|
||||
Reference in New Issue
Block a user