mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 21:40:39 -07:00
refactor: es6 building and linting
This commit is contained in:
+5
-5
@@ -6,7 +6,7 @@ const express = require('express')
|
||||
const Liquid = require('../src')
|
||||
|
||||
describe('engine#express()', function () {
|
||||
var app, engine
|
||||
let app, engine
|
||||
|
||||
beforeEach(function () {
|
||||
app = express()
|
||||
@@ -36,11 +36,11 @@ describe('engine#express()', function () {
|
||||
.expect(200, done)
|
||||
})
|
||||
it('should pass error when file not found', function (done) {
|
||||
var view = {
|
||||
let view = {
|
||||
root: []
|
||||
}
|
||||
var file = '/not-exist.html'
|
||||
var ctx = {}
|
||||
let file = '/not-exist.html'
|
||||
let ctx = {}
|
||||
engine.express().call(view, file, ctx, function (err) {
|
||||
try {
|
||||
expect(err.code).to.equal('ENOENT')
|
||||
@@ -82,7 +82,7 @@ describe('engine#express()', function () {
|
||||
.expect(200, done)
|
||||
})
|
||||
it('should respect express views (Undefined) when lookup', function (done) {
|
||||
var files = {}
|
||||
let files = {}
|
||||
files[process.cwd() + '/views/include.html'] = '{% include file %}'
|
||||
files[process.cwd() + '/views/bar.html'] = 'bar'
|
||||
mock(files)
|
||||
|
||||
+11
-11
@@ -5,17 +5,17 @@ const expect = chai.expect
|
||||
|
||||
chai.use(sinonChai)
|
||||
|
||||
var filter = require('../src/filter.js')()
|
||||
var Scope = require('../src/scope.js')
|
||||
let filter = require('../src/filter.js')()
|
||||
let Scope = require('../src/scope.js')
|
||||
|
||||
describe('filter', function () {
|
||||
var scope
|
||||
let scope
|
||||
beforeEach(function () {
|
||||
filter.clear()
|
||||
scope = Scope.factory()
|
||||
})
|
||||
it('should return default filter when not registered', function () {
|
||||
var result = filter.construct('foo')
|
||||
let result = filter.construct('foo')
|
||||
expect(result.name).to.equal('foo')
|
||||
})
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('filter', function () {
|
||||
|
||||
it('should parse argument syntax', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: a, "b"')
|
||||
let f = filter.construct('foo: a, "b"')
|
||||
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal(['a', '"b"'])
|
||||
@@ -49,7 +49,7 @@ describe('filter', function () {
|
||||
})
|
||||
|
||||
it('should call filter with corrct arguments', function () {
|
||||
var spy = sinon.spy()
|
||||
let spy = sinon.spy()
|
||||
filter.register('foo', spy)
|
||||
filter.construct('foo: 33').render('foo', scope)
|
||||
expect(spy).to.have.been.calledWith('foo', 33)
|
||||
@@ -57,35 +57,35 @@ describe('filter', function () {
|
||||
|
||||
it('should support arguments as named key/values', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: key1: "literal1", key2: value2')
|
||||
let f = filter.construct('foo: key1: "literal1", key2: value2')
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal([ '\'key1\'', '"literal1"', '\'key2\'', 'value2' ])
|
||||
})
|
||||
|
||||
it('should support arguments as named key/values with inline literals', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: "test0", key1: "literal1", key2: value2')
|
||||
let f = filter.construct('foo: "test0", key1: "literal1", key2: value2')
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal([ '"test0"', '\'key1\'', '"literal1"', '\'key2\'', 'value2' ])
|
||||
})
|
||||
|
||||
it('should support arguments as named key/values with inline values', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: test0, key1: "literal1", key2: value2')
|
||||
let f = filter.construct('foo: test0, key1: "literal1", key2: value2')
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal([ 'test0', '\'key1\'', '"literal1"', '\'key2\'', 'value2' ])
|
||||
})
|
||||
|
||||
it('should support argument values named same as keys', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: a: a')
|
||||
let f = filter.construct('foo: a: a')
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal(['\'a\'', 'a'])
|
||||
})
|
||||
|
||||
it('should support argument literals named same as keys', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: a: "a"')
|
||||
let f = filter.construct('foo: a: "a"')
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal(['\'a\'', '"a"'])
|
||||
})
|
||||
|
||||
+16
-14
@@ -1,10 +1,12 @@
|
||||
const chai = require('chai')
|
||||
const chaiAsPromised = require('chai-as-promised')
|
||||
const expect = chai.expect
|
||||
var liquid = require('../src')()
|
||||
chai.use(chaiAsPromised)
|
||||
import chai from 'chai'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import Liquid from '../src/index'
|
||||
|
||||
var ctx = {
|
||||
chai.use(chaiAsPromised)
|
||||
const liquid = new Liquid()
|
||||
const expect = chai.expect
|
||||
|
||||
let ctx = {
|
||||
date: new Date(),
|
||||
foo: 'bar',
|
||||
arr: [-2, 'a'],
|
||||
@@ -83,7 +85,7 @@ describe('filters', function () {
|
||||
|
||||
describe('date', function () {
|
||||
it('should support date: %a %b %d %Y', function () {
|
||||
var str = ctx.date.toDateString()
|
||||
let str = ctx.date.toDateString()
|
||||
return test('{{ date | date:"%a %b %d %Y"}}', str)
|
||||
})
|
||||
it('should create a new Date when given "now"', function () {
|
||||
@@ -128,7 +130,7 @@ describe('filters', function () {
|
||||
return test('{{ "Tetsuro Takara" | escape }}', 'Tetsuro Takara')
|
||||
})
|
||||
it('should escape function', function () {
|
||||
return test('{{ func | escape }}', 'function () {}')
|
||||
return test('{{ func | escape }}', 'function func() {}')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -140,7 +142,7 @@ describe('filters', function () {
|
||||
})
|
||||
|
||||
it('should support split/first', function () {
|
||||
var src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' +
|
||||
let src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' +
|
||||
'{{ my_array | first }}'
|
||||
return test(src, 'apples')
|
||||
})
|
||||
@@ -153,19 +155,19 @@ describe('filters', function () {
|
||||
})
|
||||
|
||||
it('should support join', function () {
|
||||
var src = '{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}' +
|
||||
let src = '{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}' +
|
||||
'{{ beatles | join: " and " }}'
|
||||
return test(src, 'John and Paul and George and Ringo')
|
||||
})
|
||||
|
||||
it('should support split/last', function () {
|
||||
var src = '{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}' +
|
||||
let src = '{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}' +
|
||||
'{{ my_array|last }}'
|
||||
return test(src, 'tiger')
|
||||
})
|
||||
|
||||
it('should support lstrip', function () {
|
||||
var src = '{{ " So much room for activities! " | lstrip }}'
|
||||
let src = '{{ " So much room for activities! " | lstrip }}'
|
||||
return test(src, 'So much room for activities! ')
|
||||
})
|
||||
|
||||
@@ -191,12 +193,12 @@ describe('filters', function () {
|
||||
})
|
||||
|
||||
it('should support string_with_newlines', function () {
|
||||
var src = '{% capture string_with_newlines %}\n' +
|
||||
let src = '{% capture string_with_newlines %}\n' +
|
||||
'Hello\n' +
|
||||
'there\n' +
|
||||
'{% endcapture %}' +
|
||||
'{{ string_with_newlines | newline_to_br }}'
|
||||
var dst = '<br />' +
|
||||
let dst = '<br />' +
|
||||
'Hello<br />' +
|
||||
'there<br />'
|
||||
return test(src, dst)
|
||||
|
||||
+7
-7
@@ -5,7 +5,7 @@ const mock = require('mock-fs')
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('liquid', function () {
|
||||
var engine, strictEngine, ctx
|
||||
let engine, strictEngine, ctx
|
||||
beforeEach(function () {
|
||||
ctx = {
|
||||
name: 'harttle',
|
||||
@@ -37,7 +37,7 @@ describe('liquid', function () {
|
||||
})
|
||||
describe('Liquid', function () {
|
||||
it('should ignore invalid root option', function () {
|
||||
var liquid = Liquid({ root: /regex/ })
|
||||
let liquid = Liquid({ root: /regex/ })
|
||||
expect(liquid.options.root).to.deep.equal([])
|
||||
})
|
||||
})
|
||||
@@ -68,18 +68,18 @@ describe('liquid', function () {
|
||||
}).to.not.throw()
|
||||
})
|
||||
it('should render template multiple times', function () {
|
||||
var template = engine.parse('{{obj}}')
|
||||
let template = engine.parse('{{obj}}')
|
||||
return engine.render(template, ctx)
|
||||
.then(result => expect(result).to.equal('{"foo":"bar"}'))
|
||||
.then(() => engine.render(template, ctx))
|
||||
.then((result) => expect(result).to.equal('{"foo":"bar"}'))
|
||||
})
|
||||
it('should render filters', function () {
|
||||
var template = engine.parse('<p>{{arr | join: "_"}}</p>')
|
||||
let template = engine.parse('<p>{{arr | join: "_"}}</p>')
|
||||
return expect(engine.render(template, ctx)).to.eventually.equal('<p>-2_a</p>')
|
||||
})
|
||||
it('should render accessive filters', function () {
|
||||
var src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' +
|
||||
let src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' +
|
||||
'{{ my_array | first }}'
|
||||
return expect(engine.parseAndRender(src)).to.eventually.equal('apples')
|
||||
})
|
||||
@@ -89,7 +89,7 @@ describe('liquid', function () {
|
||||
.to.eventually.equal('foo')
|
||||
})
|
||||
it('should find files without extname', function () {
|
||||
var engine = Liquid({root: '/root'})
|
||||
let engine = Liquid({root: '/root'})
|
||||
return expect(engine.renderFile('/root/files/bar', ctx))
|
||||
.to.eventually.equal('bar')
|
||||
})
|
||||
@@ -106,7 +106,7 @@ describe('liquid', function () {
|
||||
.to.eventually.equal('foo')
|
||||
})
|
||||
it('should default root to cwd', function () {
|
||||
var files = {}
|
||||
let files = {}
|
||||
files[process.cwd() + '/foo.html'] = 'FOO'
|
||||
mock(files)
|
||||
|
||||
|
||||
+6
-6
@@ -1,7 +1,7 @@
|
||||
const chai = require('chai')
|
||||
const expect = chai.expect
|
||||
|
||||
var lexical = require('../src/lexical.js')
|
||||
let lexical = require('../src/lexical.js')
|
||||
|
||||
describe('lexical', function () {
|
||||
it('should test filter syntax', function () {
|
||||
@@ -105,26 +105,26 @@ describe('lexical', function () {
|
||||
})
|
||||
|
||||
it('should throw if non-literal', function () {
|
||||
var fn = () => lexical.parseLiteral('a')
|
||||
let fn = () => lexical.parseLiteral('a')
|
||||
expect(fn).to.throw("cannot parse 'a' as literal")
|
||||
})
|
||||
})
|
||||
|
||||
describe('.matchValue()', function () {
|
||||
it('should match -5-5', function () {
|
||||
var match = lexical.matchValue('-5-5')
|
||||
let 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')
|
||||
let 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')
|
||||
let 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')
|
||||
let match = lexical.matchValue('var-1')
|
||||
expect(match && match[0]).to.equal('var-1')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ const Liquid = require('../../src')
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('cache options', function () {
|
||||
var engine
|
||||
let engine
|
||||
beforeEach(function () {
|
||||
engine = Liquid({
|
||||
root: '/root/',
|
||||
|
||||
@@ -4,8 +4,8 @@ const Liquid = require('../../src')
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('strict options', function () {
|
||||
var engine
|
||||
var ctx = {}
|
||||
let engine
|
||||
let ctx = {}
|
||||
beforeEach(function () {
|
||||
engine = Liquid({
|
||||
root: '/root/',
|
||||
@@ -17,16 +17,16 @@ describe('strict options', function () {
|
||||
.eventually.equal('beforeafter')
|
||||
})
|
||||
it('should throw when strict_variables true', function () {
|
||||
var tpl = engine.parse('before{{notdefined}}after')
|
||||
var opts = {
|
||||
let tpl = engine.parse('before{{notdefined}}after')
|
||||
let opts = {
|
||||
strict_variables: true
|
||||
}
|
||||
return expect(engine.render(tpl, ctx, opts)).to
|
||||
.be.rejectedWith(/undefined variable: notdefined/)
|
||||
})
|
||||
it('should pass strict_variables to render by parseAndRender', function () {
|
||||
var html = 'before{{notdefined}}after'
|
||||
var opts = {
|
||||
let html = 'before{{notdefined}}after'
|
||||
let opts = {
|
||||
strict_variables: true
|
||||
}
|
||||
return expect(engine.parseAndRender(html, ctx, opts)).to
|
||||
|
||||
+16
-16
@@ -4,59 +4,59 @@ const Liquid = require('../../src')
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('trimming', function () {
|
||||
var ctx = {name: 'harttle'}
|
||||
let ctx = {name: 'harttle'}
|
||||
|
||||
describe('tag trimming', function () {
|
||||
it('should respect trim_tag_left', function () {
|
||||
var engine = Liquid({ trim_tag_left: true })
|
||||
let engine = Liquid({ trim_tag_left: true })
|
||||
return expect(engine.parseAndRender(' \n \t{%if true%}foo{%endif%} '))
|
||||
.to.eventually.equal('foo ')
|
||||
})
|
||||
it('should respect trim_tag_right', function () {
|
||||
var engine = Liquid({ trim_tag_right: true })
|
||||
let engine = Liquid({ trim_tag_right: true })
|
||||
return expect(engine.parseAndRender('\t{%if true%}foo{%endif%} \n'))
|
||||
.to.eventually.equal('\tfoo')
|
||||
})
|
||||
it('should not trim value', function () {
|
||||
var engine = Liquid({ trim_tag_left: true, trim_tag_right: true })
|
||||
let engine = Liquid({ trim_tag_left: true, trim_tag_right: true })
|
||||
return expect(engine.parseAndRender('{%if true%}a {{name}} b{%endif%}', ctx))
|
||||
.to.eventually.equal('a harttle b')
|
||||
})
|
||||
})
|
||||
describe('value trimming', function () {
|
||||
it('should respect trim_value_left', function () {
|
||||
var engine = Liquid({ trim_value_left: true })
|
||||
let engine = Liquid({ trim_value_left: true })
|
||||
return expect(engine.parseAndRender(' \n \t{{name}} ', ctx))
|
||||
.to.eventually.equal('harttle ')
|
||||
})
|
||||
it('should respect trim_value_right', function () {
|
||||
var engine = Liquid({ trim_value_right: true })
|
||||
let engine = Liquid({ trim_value_right: true })
|
||||
return expect(engine.parseAndRender(' \n \t{{name}} ', ctx))
|
||||
.to.eventually.equal(' \n \tharttle')
|
||||
})
|
||||
it('should respect not trim tag', function () {
|
||||
var engine = Liquid({ trim_value_left: true, trim_value_right: true })
|
||||
let engine = Liquid({ trim_value_left: true, trim_value_right: true })
|
||||
return expect(engine.parseAndRender('\t{% if true %} aha {%endif%}\t'))
|
||||
.to.eventually.equal('\t aha \t')
|
||||
})
|
||||
})
|
||||
describe('greedy', function () {
|
||||
var src = '\n {%-if true-%}\n a \n{{-name-}}{%-endif-%}\n '
|
||||
let src = '\n {%-if true-%}\n a \n{{-name-}}{%-endif-%}\n '
|
||||
it('should enable greedy by default', function () {
|
||||
var engine = Liquid()
|
||||
let engine = Liquid()
|
||||
return expect(engine.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('aharttle')
|
||||
})
|
||||
it('should respect to greedy:false by default', function () {
|
||||
var engine = Liquid({greedy: false})
|
||||
let engine = Liquid({greedy: false})
|
||||
return expect(engine.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('\n a \nharttle ')
|
||||
})
|
||||
})
|
||||
describe('markup', function () {
|
||||
it('should support trim using markup', function () {
|
||||
var engine = Liquid()
|
||||
var src = [
|
||||
let engine = Liquid()
|
||||
let src = [
|
||||
'{%- assign username = "John G. Chalmers-Smith" -%}',
|
||||
'{%- if username and username.length > 10 -%}',
|
||||
' Wow, {{ username }}, you have a long name!',
|
||||
@@ -64,12 +64,12 @@ describe('trimming', function () {
|
||||
' Hello there!',
|
||||
'{%- endif -%}'
|
||||
].join('\n')
|
||||
var dst = 'Wow, John G. Chalmers-Smith, you have a long name!'
|
||||
let dst = 'Wow, John G. Chalmers-Smith, you have a long name!'
|
||||
return expect(engine.parseAndRender(src)).to.eventually.equal(dst)
|
||||
})
|
||||
it('should not trim when not specified', function () {
|
||||
var engine = Liquid()
|
||||
var src = [
|
||||
let engine = Liquid()
|
||||
let src = [
|
||||
'{% assign username = "John G. Chalmers-Smith" %}',
|
||||
'{% if username and username.length > 10 %}',
|
||||
' Wow, {{ username }}, you have a long name!',
|
||||
@@ -77,7 +77,7 @@ describe('trimming', function () {
|
||||
' Hello there!',
|
||||
'{% endif %}'
|
||||
].join('\n')
|
||||
var dst = '\n\n Wow, John G. Chalmers-Smith, you have a long name!\n'
|
||||
let dst = '\n\n Wow, John G. Chalmers-Smith, you have a long name!\n'
|
||||
return expect(engine.parseAndRender(src)).to.eventually.equal(dst)
|
||||
})
|
||||
})
|
||||
|
||||
+8
-8
@@ -3,13 +3,13 @@ const expect = chai.expect
|
||||
|
||||
chai.use(require('sinon-chai'))
|
||||
|
||||
var filter = require('../src/filter.js')()
|
||||
var tag = require('../src/tag.js')()
|
||||
var Template = require('../src/parser.js')
|
||||
let filter = require('../src/filter.js')()
|
||||
let tag = require('../src/tag.js')()
|
||||
let Template = require('../src/parser.js')
|
||||
|
||||
describe('template', function () {
|
||||
var template
|
||||
var add = (l, r) => l + r
|
||||
let template
|
||||
let add = (l, r) => l + r
|
||||
|
||||
beforeEach(function () {
|
||||
filter.clear()
|
||||
@@ -26,21 +26,21 @@ describe('template', function () {
|
||||
})
|
||||
|
||||
it('should parse value string', function () {
|
||||
var tpl = template.parseValue('foo')
|
||||
let tpl = template.parseValue('foo')
|
||||
expect(tpl.type).to.equal('value')
|
||||
expect(tpl.initial).to.equal('foo')
|
||||
expect(tpl.filters).to.deep.equal([])
|
||||
})
|
||||
|
||||
it('should parse value string with a simple filter', function () {
|
||||
var tpl = template.parseValue('foo | add: 3, "foo"')
|
||||
let tpl = template.parseValue('foo | add: 3, "foo"')
|
||||
expect(tpl.initial).to.equal('foo')
|
||||
expect(tpl.filters.length).to.equal(1)
|
||||
expect(tpl.filters[0].filter).to.equal(add)
|
||||
})
|
||||
|
||||
it('should parse value string with filters', function () {
|
||||
var tpl = template.parseValue('foo | add: "|" | add')
|
||||
let tpl = template.parseValue('foo | add: "|" | add')
|
||||
expect(tpl.initial).to.equal('foo')
|
||||
expect(tpl.filters.length).to.equal(2)
|
||||
})
|
||||
|
||||
+5
-6
@@ -1,11 +1,10 @@
|
||||
'use strict'
|
||||
const chai = require('chai')
|
||||
import chai from 'chai'
|
||||
import Scope from '../src/scope.js'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
var Scope = require('../src/scope.js')
|
||||
|
||||
describe('scope', function () {
|
||||
var scope, ctx
|
||||
let scope, ctx
|
||||
beforeEach(function () {
|
||||
ctx = {
|
||||
foo: 'zoo',
|
||||
@@ -161,7 +160,7 @@ describe('scope', function () {
|
||||
})
|
||||
})
|
||||
describe('strict_variables', function () {
|
||||
var scope
|
||||
let scope
|
||||
beforeEach(function () {
|
||||
scope = Scope.factory(ctx, {
|
||||
strict_variables: true
|
||||
|
||||
+7
-7
@@ -1,14 +1,14 @@
|
||||
const chai = require('chai')
|
||||
const expect = chai.expect
|
||||
var syntax = require('../src/syntax.js')
|
||||
var Scope = require('../src/scope.js')
|
||||
let syntax = require('../src/syntax.js')
|
||||
let Scope = require('../src/scope.js')
|
||||
|
||||
var evalExp = syntax.evalExp
|
||||
var evalValue = syntax.evalValue
|
||||
var isTruthy = syntax.isTruthy
|
||||
let evalExp = syntax.evalExp
|
||||
let evalValue = syntax.evalValue
|
||||
let isTruthy = syntax.isTruthy
|
||||
|
||||
describe('expression', function () {
|
||||
var scope
|
||||
let scope
|
||||
|
||||
beforeEach(function () {
|
||||
scope = Scope.factory({
|
||||
@@ -36,7 +36,7 @@ describe('expression', function () {
|
||||
})
|
||||
|
||||
it('should throw if not valid', function () {
|
||||
var fn = () => evalValue('===')
|
||||
let fn = () => evalValue('===')
|
||||
expect(fn).to.throw("cannot eval '===' as value")
|
||||
})
|
||||
})
|
||||
|
||||
+5
-5
@@ -3,11 +3,11 @@ const sinon = require('sinon')
|
||||
const expect = chai.expect
|
||||
chai.use(require('sinon-chai'))
|
||||
|
||||
var tag = require('../src/tag.js')()
|
||||
var Scope = require('../src/scope.js')
|
||||
let tag = require('../src/tag.js')()
|
||||
let Scope = require('../src/scope.js')
|
||||
|
||||
describe('tag', function () {
|
||||
var scope
|
||||
let scope
|
||||
before(function () {
|
||||
scope = Scope.factory({
|
||||
foo: 'bar',
|
||||
@@ -38,7 +38,7 @@ describe('tag', function () {
|
||||
})
|
||||
|
||||
it('should call tag.render', function () {
|
||||
var spy = sinon.spy()
|
||||
let spy = sinon.spy()
|
||||
tag.register('foo', {
|
||||
render: spy
|
||||
})
|
||||
@@ -53,7 +53,7 @@ describe('tag', function () {
|
||||
})
|
||||
|
||||
describe('hash', function () {
|
||||
var spy, token
|
||||
let spy, token
|
||||
beforeEach(function () {
|
||||
spy = sinon.spy()
|
||||
tag.register('foo', {
|
||||
|
||||
+8
-8
@@ -4,46 +4,46 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/case', function () {
|
||||
var liquid = Liquid()
|
||||
let liquid = Liquid()
|
||||
|
||||
it('should reject if not closed', function () {
|
||||
var src = '{% case "foo"%}'
|
||||
let src = '{% case "foo"%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/{% case "foo"%} not closed/)
|
||||
})
|
||||
it('should hit the specified case', function () {
|
||||
var src = '{% case "foo"%}' +
|
||||
let src = '{% case "foo"%}' +
|
||||
'{% when "foo" %}foo{% when "bar"%}bar' +
|
||||
'{%endcase%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('foo')
|
||||
})
|
||||
it('should resolve empty string if not hit', function () {
|
||||
var src = '{% case empty %}' +
|
||||
let src = '{% case empty %}' +
|
||||
'{% when "foo" %}foo{% when ""%}bar' +
|
||||
'{%endcase%}'
|
||||
var ctx = {
|
||||
let ctx = {
|
||||
empty: ''
|
||||
}
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('bar')
|
||||
})
|
||||
it('should accept empty string as branch name', function () {
|
||||
var src = '{% case false %}' +
|
||||
let src = '{% case false %}' +
|
||||
'{% when "foo" %}foo{% when ""%}bar' +
|
||||
'{%endcase%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('')
|
||||
})
|
||||
it('should support boolean case', function () {
|
||||
var src = '{% case false %}' +
|
||||
let 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" %}' +
|
||||
let src = '{% case "a" %}' +
|
||||
'{% when "b" %}b{% when "c"%}c{%else %}d' +
|
||||
'{%endcase%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
|
||||
@@ -4,29 +4,29 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/comment', function () {
|
||||
var liquid = Liquid()
|
||||
let liquid = Liquid()
|
||||
it('should support empty content', function () {
|
||||
var src = '{% comment %}{% raw%}'
|
||||
let src = '{% comment %}{% raw%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/{% comment %} not closed/)
|
||||
})
|
||||
it('should ignore plain string', function () {
|
||||
var src = 'My name is {% comment %}super{% endcomment %} Shopify.'
|
||||
let src = 'My name is {% comment %}super{% endcomment %} Shopify.'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('My name is Shopify.')
|
||||
})
|
||||
it('should ignore output tokens', function () {
|
||||
var src = '{% comment %}\n{{ foo}} \n{% endcomment %}'
|
||||
let src = '{% comment %}\n{{ foo}} \n{% endcomment %}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('')
|
||||
})
|
||||
it('should ignore tag tokens', function () {
|
||||
var src = '{% comment %}{%if true%}true{%else%}false{%endif%}{% endcomment %}'
|
||||
let src = '{% comment %}{%if true%}true{%else%}false{%endif%}{% endcomment %}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('')
|
||||
})
|
||||
it('should ignore un-balenced tag tokens', function () {
|
||||
var src = '{% comment %}{%if true%}true{%else%}false{% endcomment %}'
|
||||
let src = '{% comment %}{%if true%}true{%else%}false{% endcomment %}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('')
|
||||
})
|
||||
|
||||
+6
-6
@@ -4,10 +4,10 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/cycle', function () {
|
||||
var liquid = Liquid()
|
||||
let liquid = Liquid()
|
||||
|
||||
it('should support cycle', function () {
|
||||
var src = "{% cycle '1', '2', '3' %}"
|
||||
let src = "{% cycle '1', '2', '3' %}"
|
||||
return expect(liquid.parseAndRender(src + src + src + src))
|
||||
.to.eventually.equal('1231')
|
||||
})
|
||||
@@ -18,8 +18,8 @@ describe('tags/cycle', function () {
|
||||
})
|
||||
|
||||
it('should support cycle in for block', function () {
|
||||
var src = '{% for i in (1..5) %}{% cycle one, "e"%}{% endfor %}'
|
||||
var ctx = {
|
||||
let src = '{% for i in (1..5) %}{% cycle one, "e"%}{% endfor %}'
|
||||
let ctx = {
|
||||
one: 1
|
||||
}
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
@@ -27,10 +27,10 @@ describe('tags/cycle', function () {
|
||||
})
|
||||
|
||||
it('should support cycle group', function () {
|
||||
var src = "{% cycle one: '1', '2', '3'%}" +
|
||||
let src = "{% cycle one: '1', '2', '3'%}" +
|
||||
"{% cycle 1: '1', '2', '3'%}" +
|
||||
"{% cycle 2: '1', '2', '3'%}"
|
||||
var ctx = {
|
||||
let ctx = {
|
||||
one: 1
|
||||
}
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
|
||||
@@ -5,10 +5,10 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/decrement', function () {
|
||||
var liquid = Liquid()
|
||||
let liquid = Liquid()
|
||||
it('should throw when variable expression illegal', function () {
|
||||
var src = '{% decrement / %}{{var}}'
|
||||
var ctx = {}
|
||||
let src = '{% decrement / %}{{var}}'
|
||||
let ctx = {}
|
||||
return expect(liquid.parseAndRender(src, ctx)).to.be.rejectedWith(/illegal/)
|
||||
})
|
||||
|
||||
|
||||
+29
-29
@@ -4,7 +4,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/for', function () {
|
||||
var liquid, ctx
|
||||
let liquid, ctx
|
||||
before(function () {
|
||||
liquid = Liquid()
|
||||
liquid.registerTag('throwingTag', {
|
||||
@@ -22,25 +22,25 @@ describe('tags/for', function () {
|
||||
}
|
||||
})
|
||||
it('should support array', function () {
|
||||
var src = '{%for c in alpha%}{{c}}{%endfor%}'
|
||||
let src = '{%for c in alpha%}{{c}}{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('abc')
|
||||
})
|
||||
|
||||
it('should support object', function () {
|
||||
var src = '{%for item in obj%}{{item[0]}},{{item[1]}}-{%else%}b{%endfor%}'
|
||||
let src = '{%for item in obj%}{{item[0]}},{{item[1]}}-{%else%}b{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('foo,bar-coo,haa-')
|
||||
})
|
||||
|
||||
describe('scope', function () {
|
||||
it('should read super scope', function () {
|
||||
var src = '{%for a in (1..2)%}{{num}}{%endfor%}'
|
||||
let src = '{%for a in (1..2)%}{{num}}{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, {num: 1}))
|
||||
.to.eventually.equal('11')
|
||||
})
|
||||
it('should write super scope', function () {
|
||||
var src = '{%for a in (1..2)%}{{num}}{%assign num = 2%}{%endfor%}'
|
||||
let src = '{%for a in (1..2)%}{{num}}{%assign num = 2%}{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, {num: 1}))
|
||||
.to.eventually.equal('12')
|
||||
})
|
||||
@@ -48,13 +48,13 @@ describe('tags/for', function () {
|
||||
|
||||
describe('illegal', function () {
|
||||
it('should reject when for not closed', function () {
|
||||
var src = '{%for c in alpha%}{{c}}'
|
||||
let src = '{%for c in alpha%}{{c}}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.be.rejectedWith(/tag .* not closed/)
|
||||
})
|
||||
|
||||
it('should reject when inner templates rejected', function () {
|
||||
var src = '{%for c in alpha%}{%throwingTag%}{%endfor%}'
|
||||
let src = '{%for c in alpha%}{%throwingTag%}{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.be.rejectedWith(/intended render error/)
|
||||
})
|
||||
@@ -62,51 +62,51 @@ describe('tags/for', function () {
|
||||
|
||||
describe('else', function () {
|
||||
it('should goto else for empty array', function () {
|
||||
var src = '{%for c in emptyArray%}a{%else%}b{%endfor%}'
|
||||
let src = '{%for c in emptyArray%}a{%else%}b{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('b')
|
||||
})
|
||||
|
||||
it('should treat non-empty string as one single element', function () {
|
||||
var src = '{%for c in "abc"%}x{{c}}{%else%}y{%endfor%}'
|
||||
let src = '{%for c in "abc"%}x{{c}}{%else%}y{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('xabc')
|
||||
})
|
||||
|
||||
it('should goto else for empty string', function () {
|
||||
var src = '{%for c in ""%}a{%else%}b{%endfor%}'
|
||||
let src = '{%for c in ""%}a{%else%}b{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('b')
|
||||
})
|
||||
|
||||
it('should goto else for empty string object', function () {
|
||||
// it should be false although `new String` is none-conform
|
||||
var src = '{%for c in strObj%}a{%else%}b{%endfor%}'
|
||||
let src = '{%for c in strObj%}a{%else%}b{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('b')
|
||||
})
|
||||
|
||||
it('should goto else for empty object', function () {
|
||||
var src = '{%for c in emptyObj%}a{%else%}b{%endfor%}'
|
||||
let src = '{%for c in emptyObj%}a{%else%}b{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('b')
|
||||
})
|
||||
|
||||
it('should goto else for null-prototyped object', function () {
|
||||
var src = '{%for c in nullProtoObj%}a{%else%}b{%endfor%}'
|
||||
let src = '{%for c in nullProtoObj%}a{%else%}b{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('b')
|
||||
})
|
||||
})
|
||||
|
||||
it('should support for with forloop', function () {
|
||||
var src = '{%for c in alpha%}' +
|
||||
let src = '{%for c in alpha%}' +
|
||||
'{{forloop.first}}.{{forloop.index}}.{{forloop.index0}}.' +
|
||||
'{{forloop.last}}.{{forloop.length}}.' +
|
||||
'{{forloop.rindex}}.{{forloop.rindex0}}' +
|
||||
'{{c}}\n' +
|
||||
'{%endfor%}'
|
||||
var dst = 'true.1.0.false.3.3.2a\n' +
|
||||
let dst = 'true.1.0.false.3.3.2a\n' +
|
||||
'false.2.1.false.3.2.1b\n' +
|
||||
'false.3.2.true.3.1.0c\n'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
@@ -114,14 +114,14 @@ describe('tags/for', function () {
|
||||
})
|
||||
|
||||
it('should support for with continue', function () {
|
||||
var src = '{% for i in (1..5) %}' +
|
||||
let src = '{% for i in (1..5) %}' +
|
||||
'{{i}}{% continue %}after' +
|
||||
'{% endfor %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('12345')
|
||||
})
|
||||
it('should support for with break', function () {
|
||||
var src = '{% for i in (one..5) %}' +
|
||||
let src = '{% for i in (one..5) %}' +
|
||||
'{% if i == 4 %}{% break %}{% endif %}' +
|
||||
'{{ i }}' +
|
||||
'{% endfor %}'
|
||||
@@ -131,22 +131,22 @@ describe('tags/for', function () {
|
||||
|
||||
describe('limit', function () {
|
||||
it('should support for with limit', function () {
|
||||
var src = '{% for i in (1..5) limit:2 %}{{ i }}{% endfor %}'
|
||||
let src = '{% for i in (1..5) limit:2 %}{{ i }}{% endfor %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('12')
|
||||
})
|
||||
it('should set forloop.last properly', function () {
|
||||
var src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.last}} {%endfor%}'
|
||||
let src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.last}} {%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('false true ')
|
||||
})
|
||||
it('should set forloop.first properly', function () {
|
||||
var src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.first}} {%endfor%}'
|
||||
let src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.first}} {%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('true false ')
|
||||
})
|
||||
it('should set forloop.length properly', function () {
|
||||
var src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.length}} {%endfor%}'
|
||||
let src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.length}} {%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('2 2 ')
|
||||
})
|
||||
@@ -154,27 +154,27 @@ describe('tags/for', function () {
|
||||
|
||||
describe('offset', function () {
|
||||
it('should support offset with limit', function () {
|
||||
var src = '{% for i in (1..10) limit:2 offset:5%}{{ i }}{% endfor %}'
|
||||
let src = '{% for i in (1..10) limit:2 offset:5%}{{ i }}{% endfor %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('67')
|
||||
})
|
||||
it('should set index properly', function () {
|
||||
var src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.index}} {%endfor%}'
|
||||
let src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.index}} {%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('1 2 ')
|
||||
})
|
||||
it('should set index0 properly', function () {
|
||||
var src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.index0}} {%endfor%}'
|
||||
let src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.index0}} {%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('0 1 ')
|
||||
})
|
||||
it('should set rindex properly', function () {
|
||||
var src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.rindex}} {%endfor%}'
|
||||
let src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.rindex}} {%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('2 1 ')
|
||||
})
|
||||
it('should set rindex0 properly', function () {
|
||||
var src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.rindex0}} {%endfor%}'
|
||||
let src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.rindex0}} {%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('1 0 ')
|
||||
})
|
||||
@@ -182,19 +182,19 @@ describe('tags/for', function () {
|
||||
|
||||
describe('reverse', function () {
|
||||
it('should support for reversed in the last position', function () {
|
||||
var src = '{% for i in (1..5) limit:2 reversed %}{{ i }}{% endfor %}'
|
||||
let src = '{% for i in (1..5) limit:2 reversed %}{{ i }}{% endfor %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('21')
|
||||
})
|
||||
|
||||
it('should support for reversed in the first position', function () {
|
||||
var src = '{% for i in (1..5) reversed limit:2 %}{{ i }}{% endfor %}'
|
||||
let src = '{% for i in (1..5) reversed limit:2 %}{{ i }}{% endfor %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('21')
|
||||
})
|
||||
|
||||
it('should support for reversed in the middle position', function () {
|
||||
var src = '{% for i in (1..5) offset:2 reversed limit:4 %}{{ i }}{% endfor %}'
|
||||
let src = '{% for i in (1..5) offset:2 reversed limit:4 %}{{ i }}{% endfor %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('543')
|
||||
})
|
||||
|
||||
+20
-20
@@ -4,8 +4,8 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/if', function () {
|
||||
var liquid = Liquid()
|
||||
var ctx = {
|
||||
let liquid = Liquid()
|
||||
let ctx = {
|
||||
one: 1,
|
||||
two: 2,
|
||||
emptyString: '',
|
||||
@@ -13,101 +13,101 @@ describe('tags/if', function () {
|
||||
}
|
||||
|
||||
it('should throw if not closed', function () {
|
||||
var src = '{% if false%}yes'
|
||||
let src = '{% if false%}yes'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.be.rejectedWith(/tag {% if false%} not closed/)
|
||||
})
|
||||
it('should support nested', function () {
|
||||
var src = '{%if false%}{%if true%}{%else%}a{%endif%}{%endif%}'
|
||||
let src = '{%if false%}{%if true%}{%else%}a{%endif%}{%endif%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('')
|
||||
})
|
||||
|
||||
describe('single value as condition', function () {
|
||||
it('should support boolean', function () {
|
||||
var src = '{% if false %}1{%elsif true%}2{%else%}3{%endif%}'
|
||||
let src = '{% if false %}1{%elsif true%}2{%else%}3{%endif%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('2')
|
||||
})
|
||||
it('should treat Array truthy', function () {
|
||||
var src = '{%if emptyArray%}a{%endif%}'
|
||||
let src = '{%if emptyArray%}a{%endif%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('a')
|
||||
})
|
||||
it('should return true if empty string', function () {
|
||||
var src = '{%if emptyString%}a{%endif%}'
|
||||
let src = '{%if emptyString%}a{%endif%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('a')
|
||||
})
|
||||
})
|
||||
describe('expression as condition', function () {
|
||||
it('should support ==', function () {
|
||||
var src = '{% if 2==3 %}yes{%else%}no{%endif%}'
|
||||
let src = '{% if 2==3 %}yes{%else%}no{%endif%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
it('should support >=', function () {
|
||||
var src = '{% if 1>=2 and one<two %}a{%endif%}'
|
||||
let src = '{% if 1>=2 and one<two %}a{%endif%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('')
|
||||
})
|
||||
it('should support !=', function () {
|
||||
var src = '{% if one!=two %}yes{%else%}no{%endif%}'
|
||||
let src = '{% if one!=two %}yes{%else%}no{%endif%}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('yes')
|
||||
})
|
||||
it('should support value and expression', function () {
|
||||
var src = `X{%if version and version != '' %}x{{version}}y{%endif%}Y`
|
||||
var ctx = { 'version': '' }
|
||||
let src = `X{%if version and version != '' %}x{{version}}y{%endif%}Y`
|
||||
let ctx = { 'version': '' }
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('XY')
|
||||
})
|
||||
})
|
||||
describe('comparasion to null', function () {
|
||||
it('should evaluate false for null < 10', function () {
|
||||
var src = '{% if null < 10 %}yes{% else %}no{% endif %}'
|
||||
let src = '{% if null < 10 %}yes{% else %}no{% endif %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for null > 10', function () {
|
||||
var src = '{% if null > 10 %}yes{% else %}no{% endif %}'
|
||||
let src = '{% if null > 10 %}yes{% else %}no{% endif %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for null <= 10', function () {
|
||||
var src = '{% if null <= 10 %}yes{% else %}no{% endif %}'
|
||||
let src = '{% if null <= 10 %}yes{% else %}no{% endif %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for null >= 10', function () {
|
||||
var src = '{% if null >= 10 %}yes{% else %}no{% endif %}'
|
||||
let src = '{% if null >= 10 %}yes{% else %}no{% endif %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for 10 < null', function () {
|
||||
var src = '{% if 10 < null %}yes{% else %}no{% endif %}'
|
||||
let src = '{% if 10 < null %}yes{% else %}no{% endif %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for 10 > null', function () {
|
||||
var src = '{% if 10 > null %}yes{% else %}no{% endif %}'
|
||||
let src = '{% if 10 > null %}yes{% else %}no{% endif %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for 10 <= null', function () {
|
||||
var src = '{% if 10 <= null %}yes{% else %}no{% endif %}'
|
||||
let src = '{% if 10 <= null %}yes{% else %}no{% endif %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for 10 >= null', function () {
|
||||
var src = '{% if 10 >= null %}yes{% else %}no{% endif %}'
|
||||
let src = '{% if 10 >= null %}yes{% else %}no{% endif %}'
|
||||
return expect(liquid.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/include', function () {
|
||||
var liquid
|
||||
let liquid
|
||||
before(function () {
|
||||
liquid = Liquid({
|
||||
root: '/',
|
||||
@@ -94,7 +94,7 @@ describe('tags/include', function () {
|
||||
'/card.html': '<p>{{person.firstName}} {{person.lastName}}<br/>{% include "address" %}</p>',
|
||||
'/address.html': 'City: {{person.address.city}}'
|
||||
})
|
||||
var ctx = {
|
||||
let ctx = {
|
||||
person: {
|
||||
firstName: 'Joe',
|
||||
lastName: 'Shmoe',
|
||||
@@ -113,7 +113,7 @@ describe('tags/include', function () {
|
||||
'/parent.html': 'X{% include child.html color:"red" %}Y',
|
||||
'/child.html': 'child with {{color}}'
|
||||
})
|
||||
var staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
|
||||
let staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
|
||||
return expect(staticLiquid.renderFile('parent.html')).to
|
||||
.eventually.equal('Xchild with redY')
|
||||
})
|
||||
@@ -123,7 +123,7 @@ describe('tags/include', function () {
|
||||
'/parent.html': 'X{% include bar/./../foo/child.html %}Y',
|
||||
'/foo/child.html': 'child'
|
||||
})
|
||||
var staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
|
||||
let staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
|
||||
return expect(staticLiquid.renderFile('parent.html')).to
|
||||
.eventually.equal('XchildY')
|
||||
})
|
||||
@@ -133,7 +133,7 @@ describe('tags/include', function () {
|
||||
'/parent.html': 'X{% include foo/child.html %}Y',
|
||||
'/foo/child.html': 'child'
|
||||
})
|
||||
var staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
|
||||
let staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
|
||||
return expect(staticLiquid.renderFile('parent.html')).to
|
||||
.eventually.equal('XchildY')
|
||||
})
|
||||
@@ -143,7 +143,7 @@ describe('tags/include', function () {
|
||||
'/parent.html': 'X{% include child.html, color:"red" %}Y',
|
||||
'/child.html': 'child with {{color}}'
|
||||
})
|
||||
var staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
|
||||
let staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
|
||||
return expect(staticLiquid.renderFile('parent.html')).to
|
||||
.eventually.equal('Xchild with redY')
|
||||
})
|
||||
|
||||
+9
-9
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/layout', function () {
|
||||
var liquid
|
||||
let liquid
|
||||
before(function () {
|
||||
liquid = Liquid({
|
||||
root: '/',
|
||||
@@ -20,7 +20,7 @@ describe('tags/layout', function () {
|
||||
mock({
|
||||
'/parent.html': 'parent'
|
||||
})
|
||||
var src = '{% layout "parent" %}{%block%}A'
|
||||
let src = '{% layout "parent" %}{%block%}A'
|
||||
return expect(liquid.parseAndRender(src)).to
|
||||
.be.rejectedWith(/tag {%block%} not closed/)
|
||||
})
|
||||
@@ -38,7 +38,7 @@ describe('tags/layout', function () {
|
||||
mock({
|
||||
'/parent.html': 'X{%block%}{%endblock%}Y'
|
||||
})
|
||||
var src = '{% layout "parent.html" %}{%block%}A{%endblock%}'
|
||||
let src = '{% layout "parent.html" %}{%block%}A{%endblock%}'
|
||||
return expect(liquid.parseAndRender(src)).to
|
||||
.eventually.equal('XAY')
|
||||
})
|
||||
@@ -46,7 +46,7 @@ describe('tags/layout', function () {
|
||||
mock({
|
||||
'/parent.html': 'X{%block%}{%endblock%}Y'
|
||||
})
|
||||
var src = '{% layout "parent.html" %}A'
|
||||
let src = '{% layout "parent.html" %}A'
|
||||
return expect(liquid.parseAndRender(src)).to
|
||||
.eventually.equal('XAY')
|
||||
})
|
||||
@@ -55,7 +55,7 @@ describe('tags/layout', function () {
|
||||
mock({
|
||||
'/parent.html': 'X{% block "a"%}{% endblock %}Y{% block b%}{%endblock%}Z'
|
||||
})
|
||||
var src = '{% layout "parent.html" %}' +
|
||||
let src = '{% layout "parent.html" %}' +
|
||||
'{%block a%}A{%endblock%}' +
|
||||
'{%block b%}B{%endblock%}'
|
||||
return expect(liquid.parseAndRender(src)).to
|
||||
@@ -65,7 +65,7 @@ describe('tags/layout', function () {
|
||||
mock({
|
||||
'/parent.html': 'X{% block "a"%}A{% endblock %}Y{% block b%}B{%endblock%}Z'
|
||||
})
|
||||
var src = '{% layout "parent.html" %}{%block a%}a{%endblock%}'
|
||||
let src = '{% layout "parent.html" %}{%block a%}a{%endblock%}'
|
||||
return expect(liquid.parseAndRender(src)).to
|
||||
.eventually.equal('XaYBZ')
|
||||
})
|
||||
@@ -112,7 +112,7 @@ describe('tags/layout', function () {
|
||||
'/parent.html': '{{color}}{%block%}{%endblock%}',
|
||||
'/main.html': '{% layout parent.html color:"black"%}{%block%}A{%endblock%}'
|
||||
})
|
||||
var staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
let staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
return expect(staticLiquid.renderFile('/main.html')).to
|
||||
.eventually.equal('blackA')
|
||||
})
|
||||
@@ -122,7 +122,7 @@ describe('tags/layout', function () {
|
||||
'/foo/parent.html': '{{color}}{%block%}{%endblock%}',
|
||||
'/main.html': '{% layout bar/../foo/parent.html color:"black"%}{%block%}A{%endblock%}'
|
||||
})
|
||||
var staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
let staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
return expect(staticLiquid.renderFile('/main.html')).to
|
||||
.eventually.equal('blackA')
|
||||
})
|
||||
@@ -132,7 +132,7 @@ describe('tags/layout', function () {
|
||||
'/foo/parent.html': '{{color}}{%block%}{%endblock%}',
|
||||
'/main.html': '{% layout foo/parent.html color:"black"%}{%block%}A{%endblock%}'
|
||||
})
|
||||
var staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
let staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
return expect(staticLiquid.renderFile('/main.html')).to
|
||||
.eventually.equal('blackA')
|
||||
})
|
||||
|
||||
+5
-5
@@ -4,20 +4,20 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/raw', function () {
|
||||
var liquid = Liquid()
|
||||
let liquid = Liquid()
|
||||
it('should support raw 1', function () {
|
||||
return expect(liquid.parseAndRender('{% raw%}'))
|
||||
.to.be.rejectedWith(/{% raw%} not closed/)
|
||||
})
|
||||
it('should support raw 2', function () {
|
||||
var src = '{% raw %}{{ 5 | plus: 6 }}{% endraw %} is equal to 11.'
|
||||
var dst = '{{ 5 | plus: 6 }} is equal to 11.'
|
||||
let src = '{% raw %}{{ 5 | plus: 6 }}{% endraw %} is equal to 11.'
|
||||
let dst = '{{ 5 | plus: 6 }} is equal to 11.'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal(dst)
|
||||
})
|
||||
it('should support raw 3', function () {
|
||||
var src = '{% raw %}\n{{ foo}} \n{% endraw %}'
|
||||
var dst = '\n{{ foo}} \n'
|
||||
let src = '{% raw %}\n{{ foo}} \n{% endraw %}'
|
||||
let dst = '\n{{ foo}} \n'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal(dst)
|
||||
})
|
||||
|
||||
+19
-19
@@ -4,52 +4,52 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/tablerow', function () {
|
||||
var liquid = Liquid()
|
||||
let liquid = Liquid()
|
||||
|
||||
it('should support tablerow', function () {
|
||||
var src = '{% tablerow i in (1..3)%}{{ i }}{% endtablerow %}'
|
||||
var dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>'
|
||||
let src = '{% tablerow i in (1..3)%}{{ i }}{% endtablerow %}'
|
||||
let dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>'
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
|
||||
})
|
||||
|
||||
it('should support cols', function () {
|
||||
var src = '{% tablerow i in alpha cols:2 %}{{ i }}{% endtablerow %}'
|
||||
var ctx = {
|
||||
let src = '{% tablerow i in alpha cols:2 %}{{ i }}{% endtablerow %}'
|
||||
let ctx = {
|
||||
alpha: ['a', 'b', 'c']
|
||||
}
|
||||
var dst =
|
||||
let dst =
|
||||
'<tr class="row1"><td class="col1">a</td><td class="col2">b</td></tr>' +
|
||||
'<tr class="row2"><td class="col1">c</td></tr>'
|
||||
return expect(liquid.parseAndRender(src, ctx)).to.eventually.equal(dst)
|
||||
})
|
||||
|
||||
it('should support cols set to 0', function () {
|
||||
var src = '{% tablerow i in (1..3) cols:0 %}{{ i }}{% endtablerow %}'
|
||||
var dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>'
|
||||
let src = '{% tablerow i in (1..3) cols:0 %}{{ i }}{% endtablerow %}'
|
||||
let dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>'
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
|
||||
})
|
||||
|
||||
it('should support empty tablerow', function () {
|
||||
var src = '{% tablerow i in (1..0) cols:2 %}{{ i }}{% endtablerow %}'
|
||||
var dst = ''
|
||||
let src = '{% tablerow i in (1..0) cols:2 %}{{ i }}{% endtablerow %}'
|
||||
let dst = ''
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
|
||||
})
|
||||
|
||||
it('should support empty array', function () {
|
||||
var src = '{% tablerow i in alpha.z cols:2 %}{{ i }}{% endtablerow %}'
|
||||
var dst = ''
|
||||
let src = '{% tablerow i in alpha.z cols:2 %}{{ i }}{% endtablerow %}'
|
||||
let dst = ''
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
|
||||
})
|
||||
|
||||
it('should throw when tablerow not closed', function () {
|
||||
var src = '{% tablerow i in (1..0) cols:2 %}{{ i }}'
|
||||
let src = '{% tablerow i in (1..0) cols:2 %}{{ i }}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/tag .* not closed/)
|
||||
})
|
||||
|
||||
it('should support tablerow with range', function () {
|
||||
var src = '{% tablerow i in (1..5) cols:2 %}{{ i }}{% endtablerow %}'
|
||||
var dst =
|
||||
let src = '{% tablerow i in (1..5) cols:2 %}{{ i }}{% endtablerow %}'
|
||||
let dst =
|
||||
'<tr class="row1"><td class="col1">1</td><td class="col2">2</td></tr>' +
|
||||
'<tr class="row2"><td class="col1">3</td><td class="col2">4</td></tr>' +
|
||||
'<tr class="row3"><td class="col1">5</td></tr>'
|
||||
@@ -57,16 +57,16 @@ describe('tags/tablerow', function () {
|
||||
})
|
||||
|
||||
it('should support tablerow with limit', function () {
|
||||
var src = '{% tablerow i in (1..5) cols:2 limit:3 %}{{ i }}{% endtablerow %}'
|
||||
var dst =
|
||||
let src = '{% tablerow i in (1..5) cols:2 limit:3 %}{{ i }}{% endtablerow %}'
|
||||
let dst =
|
||||
'<tr class="row1"><td class="col1">1</td><td class="col2">2</td></tr>' +
|
||||
'<tr class="row2"><td class="col1">3</td></tr>'
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
|
||||
})
|
||||
|
||||
it('should support tablerow with offset', function () {
|
||||
var src = '{% tablerow i in (1..5) cols:2 offset:3 %}{{ i }}{% endtablerow %}'
|
||||
var dst = '<tr class="row1"><td class="col1">4</td><td class="col2">5</td></tr>'
|
||||
let src = '{% tablerow i in (1..5) cols:2 offset:3 %}{{ i }}{% endtablerow %}'
|
||||
let dst = '<tr class="row1"><td class="col1">4</td><td class="col2">5</td></tr>'
|
||||
return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
|
||||
})
|
||||
})
|
||||
|
||||
+6
-6
@@ -4,31 +4,31 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/unless', function () {
|
||||
var liquid = Liquid()
|
||||
let liquid = Liquid()
|
||||
|
||||
it('should render else when predicate yields true', function () {
|
||||
// 0 is truthy
|
||||
var src = '{% unless 0 %}yes{%else%}no{%endunless%}'
|
||||
let src = '{% unless 0 %}yes{%else%}no{%endunless%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('no')
|
||||
})
|
||||
it('should render unless when predicate yields false', function () {
|
||||
var src = '{% unless false %}yes{%else%}no{%endunless%}'
|
||||
let src = '{% unless false %}yes{%else%}no{%endunless%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('yes')
|
||||
})
|
||||
it('should reject when tag not closed', function () {
|
||||
var src = '{% unless 1>2 %}yes'
|
||||
let src = '{% unless 1>2 %}yes'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/tag {% unless 1>2 %} not closed/)
|
||||
})
|
||||
it('should render unless when predicate yields false and else undefined', function () {
|
||||
var src = '{% unless 1>2 %}yes{%endunless%}'
|
||||
let src = '{% unless 1>2 %}yes{%endunless%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('yes')
|
||||
})
|
||||
it('should render "" when predicate yields false and else undefined', function () {
|
||||
var src = '{% unless 1<2 %}yes{%endunless%}'
|
||||
let src = '{% unless 1<2 %}yes{%endunless%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('')
|
||||
})
|
||||
|
||||
+14
-14
@@ -5,8 +5,8 @@ const expect = chai.expect
|
||||
describe('tokenizer', function () {
|
||||
describe('parse', function () {
|
||||
it('should handle plain HTML', function () {
|
||||
var html = '<html><body><p>Lorem Ipsum</p></body></html>'
|
||||
var tokens = parse(html)
|
||||
let html = '<html><body><p>Lorem Ipsum</p></body></html>'
|
||||
let tokens = parse(html)
|
||||
|
||||
expect(tokens.length).to.equal(1)
|
||||
expect(tokens[0].value).to.equal(html)
|
||||
@@ -18,24 +18,24 @@ describe('tokenizer', function () {
|
||||
}).to.throw('illegal input')
|
||||
})
|
||||
it('should handle tag syntax', function () {
|
||||
var html = '<p>{% for p in a[1]%}</p>'
|
||||
var tokens = parse(html)
|
||||
let html = '<p>{% for p in a[1]%}</p>'
|
||||
let tokens = parse(html)
|
||||
|
||||
expect(tokens.length).to.equal(3)
|
||||
expect(tokens[1].type).to.equal('tag')
|
||||
expect(tokens[1].value).to.equal('for p in a[1]')
|
||||
})
|
||||
it('should handle value syntax', function () {
|
||||
var html = '<p>{{foo | date: "%Y-%m-%d"}}</p>'
|
||||
var tokens = parse(html)
|
||||
let html = '<p>{{foo | date: "%Y-%m-%d"}}</p>'
|
||||
let tokens = parse(html)
|
||||
|
||||
expect(tokens.length).to.equal(3)
|
||||
expect(tokens[1].type).to.equal('value')
|
||||
expect(tokens[1].value).to.equal('foo | date: "%Y-%m-%d"')
|
||||
})
|
||||
it('should handle consecutive value and tags', function () {
|
||||
var html = '{{foo}}{{bar}}{%foo%}{%bar%}'
|
||||
var tokens = parse(html)
|
||||
let html = '{{foo}}{{bar}}{%foo%}{%bar%}'
|
||||
let tokens = parse(html)
|
||||
|
||||
expect(tokens.length).to.equal(4)
|
||||
expect(tokens[0].type).to.equal('value')
|
||||
@@ -45,8 +45,8 @@ describe('tokenizer', function () {
|
||||
expect(tokens[2].value).to.equal('foo')
|
||||
})
|
||||
it('should keep white spaces and newlines', function () {
|
||||
var html = '{%foo%}\n{%bar %} \n {%alice%}'
|
||||
var tokens = parse(html)
|
||||
let html = '{%foo%}\n{%bar %} \n {%alice%}'
|
||||
let tokens = parse(html)
|
||||
expect(tokens.length).to.equal(5)
|
||||
expect(tokens[1].type).to.equal('html')
|
||||
expect(tokens[1].raw).to.equal('\n')
|
||||
@@ -54,16 +54,16 @@ describe('tokenizer', function () {
|
||||
expect(tokens[3].raw).to.equal(' \n ')
|
||||
})
|
||||
it('should handle multiple lines tag', function () {
|
||||
var html = '{%foo\na:a\nb:1.23\n%}'
|
||||
var tokens = parse(html)
|
||||
let html = '{%foo\na:a\nb:1.23\n%}'
|
||||
let tokens = parse(html)
|
||||
expect(tokens.length).to.equal(1)
|
||||
expect(tokens[0].type).to.equal('tag')
|
||||
expect(tokens[0].args).to.equal('a:a\nb:1.23')
|
||||
expect(tokens[0].raw).to.equal('{%foo\na:a\nb:1.23\n%}')
|
||||
})
|
||||
it('should handle multiple lines value', function () {
|
||||
var html = '{{foo\n|date:\n"%Y-%m-%d"\n}}'
|
||||
var tokens = parse(html)
|
||||
let html = '{{foo\n|date:\n"%Y-%m-%d"\n}}'
|
||||
let tokens = parse(html)
|
||||
expect(tokens.length).to.equal(1)
|
||||
expect(tokens[0].type).to.equal('value')
|
||||
expect(tokens[0].raw).to.equal('{{foo\n|date:\n"%Y-%m-%d"\n}}')
|
||||
|
||||
+3
-3
@@ -4,15 +4,15 @@ const assert = require('../../src/util/assert.js')
|
||||
|
||||
describe('assert', function () {
|
||||
it('should not throw if predicate is truthy', function () {
|
||||
var fn = () => assert('foo', 'bar')
|
||||
let fn = () => assert('foo', 'bar')
|
||||
expect(fn).to.not.throw()
|
||||
})
|
||||
it('should not throw if predicate is truthy', function () {
|
||||
var fn = () => assert('', 'bar')
|
||||
let fn = () => assert('', 'bar')
|
||||
expect(fn).to.throw(/bar/)
|
||||
})
|
||||
it('should populate default message', function () {
|
||||
var fn = () => assert(false)
|
||||
let fn = () => assert(false)
|
||||
expect(fn).to.throw(/expect false to be true/)
|
||||
})
|
||||
})
|
||||
|
||||
+28
-28
@@ -4,8 +4,8 @@ const mock = require('mock-fs')
|
||||
const path = require('path')
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
var engine = require('../..')()
|
||||
var strictEngine = require('../..')({
|
||||
let engine = require('../..')()
|
||||
let strictEngine = require('../..')({
|
||||
strict_variables: true,
|
||||
strict_filters: true
|
||||
})
|
||||
@@ -25,8 +25,8 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should contain template content in err.message', function () {
|
||||
var html = ['1st', '2nd', 'X{% . a %} Y', '4th']
|
||||
var message = [
|
||||
let html = ['1st', '2nd', 'X{% . a %} Y', '4th']
|
||||
let message = [
|
||||
' 1| 1st',
|
||||
' 2| 2nd',
|
||||
'>> 3| X{% . a %} Y',
|
||||
@@ -42,7 +42,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should contain the whole template content in err.input', function () {
|
||||
var html = 'bar\nfoo{% . a %}\nfoo'
|
||||
let html = 'bar\nfoo{% . a %}\nfoo'
|
||||
return expect(engine.parseAndRender(html)).to.eventually
|
||||
.be.rejected
|
||||
.then(function (err) {
|
||||
@@ -66,7 +66,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
describe('captureStackTrace compatibility', function () {
|
||||
var captureStackTrace = Error.captureStackTrace
|
||||
let captureStackTrace = Error.captureStackTrace
|
||||
before(() => (Error.captureStackTrace = null))
|
||||
after(() => (Error.captureStackTrace = captureStackTrace))
|
||||
it('should use empty string if captureStackTrace not defined', function () {
|
||||
@@ -79,7 +79,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should contain file path in err.file', function () {
|
||||
var html = '<html>\n<head>\n\n{% . a %}\n\n'
|
||||
let html = '<html>\n<head>\n\n{% . a %}\n\n'
|
||||
mock({
|
||||
'/foo.html': html
|
||||
})
|
||||
@@ -113,7 +113,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should throw RenderError when tag throws', function () {
|
||||
var src = '{%throwingTag%}'
|
||||
let src = '{%throwingTag%}'
|
||||
return expect(engine.parseAndRender(src)).to.eventually
|
||||
.be.rejected
|
||||
.then(function (err) {
|
||||
@@ -122,7 +122,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should throw RenderError when tag rejects', function () {
|
||||
var src = '{%rejectingTag%}'
|
||||
let src = '{%rejectingTag%}'
|
||||
return expect(engine.parseAndRender(src)).to.eventually
|
||||
.be.rejected
|
||||
.then(function (err) {
|
||||
@@ -131,7 +131,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should throw RenderError when filter throws', function () {
|
||||
var src = '{{1|throwingFilter}}'
|
||||
let src = '{{1|throwingFilter}}'
|
||||
return expect(engine.parseAndRender(src)).to.eventually
|
||||
.be.rejected
|
||||
.then(function (err) {
|
||||
@@ -151,8 +151,8 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should contain template context in err.stack', function () {
|
||||
var html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
|
||||
var message = [
|
||||
let html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
|
||||
let message = [
|
||||
' 2| 2nd',
|
||||
' 3| 3rd',
|
||||
'>> 4| X{%throwingTag%} Y',
|
||||
@@ -181,8 +181,8 @@ describe('error', function () {
|
||||
'7th'
|
||||
].join('\n')
|
||||
})
|
||||
var html = '{%layout "throwing-tag.html"%}'
|
||||
var message = [
|
||||
let html = '{%layout "throwing-tag.html"%}'
|
||||
let message = [
|
||||
' 2| 2nd',
|
||||
' 3| 3rd',
|
||||
'>> 4| X{%throwingTag%} Y',
|
||||
@@ -202,12 +202,12 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should contain original error info for {% include %}', function () {
|
||||
var origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
|
||||
let origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
|
||||
mock({
|
||||
'/throwing-tag.html': origin.join('\n')
|
||||
})
|
||||
var html = '{%include "throwing-tag.html"%}'
|
||||
var message = [
|
||||
let html = '{%include "throwing-tag.html"%}'
|
||||
let message = [
|
||||
' 2| 2nd',
|
||||
' 3| 3rd',
|
||||
'>> 4| X{%throwingTag%} Y',
|
||||
@@ -225,7 +225,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should contain the whole template content in err.input', function () {
|
||||
var html = 'bar\nfoo{%throwingTag%}\nfoo'
|
||||
let html = 'bar\nfoo{%throwingTag%}\nfoo'
|
||||
return expect(engine.parseAndRender(html)).to.eventually
|
||||
.be.rejected
|
||||
.then(function (err) {
|
||||
@@ -234,7 +234,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should contain line number in err.line', function () {
|
||||
var src = '1\n2\n{{1|throwingFilter}}\n4'
|
||||
let src = '1\n2\n{{1|throwingFilter}}\n4'
|
||||
return expect(engine.parseAndRender(src)).to.eventually
|
||||
.be.rejected
|
||||
.then(function (err) {
|
||||
@@ -252,7 +252,7 @@ describe('error', function () {
|
||||
})
|
||||
|
||||
it('should contain file path in err.file', function () {
|
||||
var html = '<html>\n<head>\n\n{% throwingTag %}\n\n'
|
||||
let html = '<html>\n<head>\n\n{% throwingTag %}\n\n'
|
||||
mock({
|
||||
'/foo.html': html
|
||||
})
|
||||
@@ -293,7 +293,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should throw ParseError when tag parse throws', function () {
|
||||
var src = '{%throwsOnParse%}'
|
||||
let src = '{%throwsOnParse%}'
|
||||
return expect(engine.parseAndRender(src)).to.eventually
|
||||
.be.rejected
|
||||
.then(function (err) {
|
||||
@@ -302,7 +302,7 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should throw ParseError when tag not found', function () {
|
||||
var src = '{%if true%}\naaa{%endif%}\n{% -a %}\n3'
|
||||
let src = '{%if true%}\naaa{%endif%}\n{% -a %}\n3'
|
||||
return expect(engine.parseAndRender(src)).to.eventually
|
||||
.be.rejected
|
||||
.then(function (err) {
|
||||
@@ -321,8 +321,8 @@ describe('error', function () {
|
||||
})
|
||||
|
||||
it('should contain template context in err.stack', function () {
|
||||
var html = ['1st', '2nd', '3rd', 'X{% a %} {% enda %} Y', '5th', '6th', '7th']
|
||||
var message = [
|
||||
let html = ['1st', '2nd', '3rd', 'X{% a %} {% enda %} Y', '5th', '6th', '7th']
|
||||
let message = [
|
||||
' 2| 2nd',
|
||||
' 3| 3rd',
|
||||
'>> 4| X{% a %} {% enda %} Y',
|
||||
@@ -341,8 +341,8 @@ describe('error', function () {
|
||||
})
|
||||
|
||||
it('should handle err.message when context not enough', function () {
|
||||
var html = ['1st', 'X{% a %} {% enda %} Y', '3rd', '4th']
|
||||
var message = [
|
||||
let html = ['1st', 'X{% a %} {% enda %} Y', '3rd', '4th']
|
||||
let message = [
|
||||
' 1| 1st',
|
||||
'>> 2| X{% a %} {% enda %} Y',
|
||||
' 3| 3rd',
|
||||
@@ -358,7 +358,7 @@ describe('error', function () {
|
||||
})
|
||||
|
||||
it('should contain line number in err.line', function () {
|
||||
var html = '<html>\n<head>\n\n{% raw %}\n\n'
|
||||
let html = '<html>\n<head>\n\n{% raw %}\n\n'
|
||||
return expect(engine.parseAndRender(html)).to.eventually
|
||||
.be.rejected
|
||||
.then(function (err) {
|
||||
@@ -376,7 +376,7 @@ describe('error', function () {
|
||||
})
|
||||
|
||||
it('should contain file path in err.file', function () {
|
||||
var html = '<html>\n<head>\n\n{% raw %}\n\n'
|
||||
let html = '<html>\n<head>\n\n{% raw %}\n\n'
|
||||
mock({
|
||||
'/foo.html': html
|
||||
})
|
||||
|
||||
+11
-11
@@ -4,13 +4,13 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
chai.use(require('sinon-chai'))
|
||||
|
||||
var P = require('../../src/util/promise.js')
|
||||
let P = require('../../src/util/promise.js')
|
||||
|
||||
describe('util/promise', function () {
|
||||
describe('.anySeries()', function () {
|
||||
it('should resolve in series', function () {
|
||||
var spy1 = sinon.spy()
|
||||
var spy2 = sinon.spy()
|
||||
let spy1 = sinon.spy()
|
||||
let spy2 = sinon.spy()
|
||||
return P
|
||||
.anySeries(
|
||||
['first', 'second'],
|
||||
@@ -28,17 +28,17 @@ describe('util/promise', function () {
|
||||
.then(() => expect(spy2).to.have.been.calledAfter(spy1))
|
||||
})
|
||||
it('should reject when all rejected', function () {
|
||||
var p = P.anySeries(['first', 'second', 'third'],
|
||||
let p = P.anySeries(['first', 'second', 'third'],
|
||||
item => Promise.reject(new Error(item)))
|
||||
return expect(p).to.be.rejectedWith('third')
|
||||
})
|
||||
it('should resolve the value that first callback resolved', () => {
|
||||
var p = P.anySeries(['first', 'second'],
|
||||
let p = P.anySeries(['first', 'second'],
|
||||
item => Promise.resolve(item))
|
||||
return expect(p).to.eventually.equal('first')
|
||||
})
|
||||
it('should not call rest of callbacks once resolved', () => {
|
||||
var spy = sinon.spy()
|
||||
let spy = sinon.spy()
|
||||
return P
|
||||
.anySeries(['first', 'second'], (item, idx) => {
|
||||
if (idx > 0) {
|
||||
@@ -51,18 +51,18 @@ describe('util/promise', function () {
|
||||
})
|
||||
describe('.mapSeries()', function () {
|
||||
it('should resolve when all resolved', function () {
|
||||
var p = P.mapSeries(['first', 'second', 'third'],
|
||||
let p = P.mapSeries(['first', 'second', 'third'],
|
||||
item => Promise.resolve(item))
|
||||
return expect(p).to.eventually.deep.equal(['first', 'second', 'third'])
|
||||
})
|
||||
it('should reject with the error that first callback rejected', () => {
|
||||
var p = P.mapSeries(['first', 'second'],
|
||||
let p = P.mapSeries(['first', 'second'],
|
||||
item => Promise.reject(item))
|
||||
return expect(p).to.rejectedWith('first')
|
||||
})
|
||||
it('should resolve in series', function () {
|
||||
var spy1 = sinon.spy()
|
||||
var spy2 = sinon.spy()
|
||||
let spy1 = sinon.spy()
|
||||
let spy2 = sinon.spy()
|
||||
return P
|
||||
.mapSeries(
|
||||
['first', 'second'],
|
||||
@@ -80,7 +80,7 @@ describe('util/promise', function () {
|
||||
.then(() => expect(spy2).to.have.been.calledAfter(spy1))
|
||||
})
|
||||
it('should not call rest of callbacks once rejected', () => {
|
||||
var spy = sinon.spy()
|
||||
let spy = sinon.spy()
|
||||
return P
|
||||
.mapSeries(['first', 'second'], (item, idx) => {
|
||||
if (idx > 0) {
|
||||
|
||||
+13
-13
@@ -1,11 +1,11 @@
|
||||
const chai = require('chai')
|
||||
const expect = chai.expect
|
||||
|
||||
var t = require('../../src/util/strftime.js')
|
||||
let t = require('../../src/util/strftime.js')
|
||||
|
||||
describe('util/strftime', function () {
|
||||
var now
|
||||
var then
|
||||
let now
|
||||
let then
|
||||
before(function () {
|
||||
mockUTC()
|
||||
now = new Date('2016-01-04T13:15:23.000Z')
|
||||
@@ -37,7 +37,7 @@ describe('util/strftime', function () {
|
||||
expect(t(now, '%I')).to.equal('01')
|
||||
})
|
||||
it('should format %I as 12 for 00:00', function () {
|
||||
var date = new Date('2016-01-01T00:00:00.000Z')
|
||||
let date = new Date('2016-01-01T00:00:00.000Z')
|
||||
expect(t(date, '%I')).to.equal('12')
|
||||
})
|
||||
describe('%j', function () {
|
||||
@@ -45,11 +45,11 @@ describe('util/strftime', function () {
|
||||
expect(t(then, '%j')).to.equal('066')
|
||||
})
|
||||
it('should take count of leap years', function () {
|
||||
var date = new Date('2001-03-01')
|
||||
let 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')
|
||||
let date = new Date('2000-03-01')
|
||||
expect(t(date, '%j')).to.equal('061')
|
||||
})
|
||||
})
|
||||
@@ -60,7 +60,7 @@ describe('util/strftime', 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.000Z')
|
||||
let date = new Date('2016-01-01T00:00:00.000Z')
|
||||
expect(t(date, '%l')).to.equal('12')
|
||||
})
|
||||
it('should format %L as 0 padded millisecond', function () {
|
||||
@@ -75,9 +75,9 @@ describe('util/strftime', function () {
|
||||
expect(t(then, '%P')).to.equal('am')
|
||||
})
|
||||
it('should format %q as date suffix', function () {
|
||||
var st = new Date('2016-03-01T03:05:03.000Z')
|
||||
var nd = new Date('2016-03-02T03:05:03.000Z')
|
||||
var rd = new Date('2016-03-03T03:05:03.000Z')
|
||||
let st = new Date('2016-03-01T03:05:03.000Z')
|
||||
let nd = new Date('2016-03-02T03:05:03.000Z')
|
||||
let rd = new Date('2016-03-03T03:05:03.000Z')
|
||||
expect(t(st, '%q')).to.equal('st')
|
||||
expect(t(nd, '%q')).to.equal('nd')
|
||||
expect(t(rd, '%q')).to.equal('rd')
|
||||
@@ -113,7 +113,7 @@ describe('util/strftime', 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.000Z')
|
||||
let date = new Date('2016-01-04T13:15:23.000Z')
|
||||
date.getTimezoneOffset = () => 480
|
||||
expect(t(date, '%z')).to.equal('-0800')
|
||||
})
|
||||
@@ -126,7 +126,7 @@ describe('util/strftime', function () {
|
||||
})
|
||||
|
||||
function mockUTC () {
|
||||
var p = Date.prototype
|
||||
let p = Date.prototype
|
||||
|
||||
p._getHours = p.getHours
|
||||
p.getHours = p.getUTCHours
|
||||
@@ -139,7 +139,7 @@ function mockUTC () {
|
||||
}
|
||||
|
||||
function restoreUTC () {
|
||||
var p = Date.prototype
|
||||
let p = Date.prototype
|
||||
p.getHours = p._getHours
|
||||
p.getDays = p._getDays
|
||||
p.getTimezoneOffset = p._getTimezoneOffset
|
||||
|
||||
+15
-15
@@ -1,10 +1,10 @@
|
||||
const chai = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const expect = chai.expect
|
||||
const Errors = require('../../src/util/error.js')
|
||||
chai.use(require('sinon-chai'))
|
||||
import chai from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import Errors from '../../src/util/error.js'
|
||||
import _ from '../../src/util/underscore.js'
|
||||
|
||||
var _ = require('../../src/util/underscore.js')
|
||||
const expect = chai.expect
|
||||
chai.use(require('sinon-chai'))
|
||||
|
||||
describe('util/underscore', function () {
|
||||
describe('.isError()', function () {
|
||||
@@ -12,7 +12,7 @@ describe('util/underscore', function () {
|
||||
expect(_.isError(new Error())).to.be.true
|
||||
})
|
||||
it('should return true for RenderError', function () {
|
||||
var tpl = {
|
||||
let tpl = {
|
||||
token: {
|
||||
input: 'xx'
|
||||
}
|
||||
@@ -53,21 +53,21 @@ describe('util/underscore', function () {
|
||||
})
|
||||
describe('.forOwn()', function () {
|
||||
it('should iterate all properties', function () {
|
||||
var spy = sinon.spy()
|
||||
var obj = {
|
||||
let spy = sinon.spy()
|
||||
let obj = {
|
||||
foo: 'bar'
|
||||
}
|
||||
_.forOwn(obj, spy)
|
||||
expect(spy).to.have.been.calledWith('bar', 'foo', obj)
|
||||
})
|
||||
it('should default to empty object', function () {
|
||||
var spy = sinon.spy()
|
||||
let spy = sinon.spy()
|
||||
_.forOwn(undefined, spy)
|
||||
expect(spy).to.have.not.been.called
|
||||
})
|
||||
it('should not iterate over properties on prototype', function () {
|
||||
var spy = sinon.spy()
|
||||
var obj = Object.create({
|
||||
let spy = sinon.spy()
|
||||
let obj = Object.create({
|
||||
bar: 'foo'
|
||||
})
|
||||
obj.foo = 'bar'
|
||||
@@ -76,7 +76,7 @@ describe('util/underscore', function () {
|
||||
expect(spy).to.have.been.calledWith('bar', 'foo', obj)
|
||||
})
|
||||
it('should break when returned false', function () {
|
||||
var spy = sinon.stub().returns(false)
|
||||
let spy = sinon.stub().returns(false)
|
||||
_.forOwn({
|
||||
'foo': 'foo',
|
||||
'bar': 'foo'
|
||||
@@ -101,11 +101,11 @@ describe('util/underscore', function () {
|
||||
})
|
||||
})
|
||||
it('should assign 2 objects', function () {
|
||||
var src = {
|
||||
let src = {
|
||||
foo: 'foo',
|
||||
bar: 'bar'
|
||||
}
|
||||
var dst = {
|
||||
let dst = {
|
||||
foo: 'bar',
|
||||
kaa: 'kaa'
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ describe('util/url', function () {
|
||||
return
|
||||
}
|
||||
const JSDOM = require('jsdom').JSDOM
|
||||
var dom
|
||||
let dom
|
||||
beforeEach(function () {
|
||||
dom = new JSDOM(``, {
|
||||
url: 'https://example.com/foo/bar/',
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
const Liquid = require('..')
|
||||
const sinon = require('sinon')
|
||||
const chai = require('chai')
|
||||
import Liquid from '..'
|
||||
import sinon from 'sinon'
|
||||
import chai from 'chai'
|
||||
const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('xhr', () => {
|
||||
return
|
||||
}
|
||||
const JSDOM = require('jsdom').JSDOM
|
||||
var server, engine, dom
|
||||
let server, engine, dom
|
||||
beforeEach(() => {
|
||||
server = sinon.createFakeServer()
|
||||
server.autoRespond = true
|
||||
|
||||
Reference in New Issue
Block a user