mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
chore: migrate test cases from Chai to Jest
This commit is contained in:
@@ -1,52 +1,51 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('drop/blank-drop', function () {
|
||||
let liquid: Liquid
|
||||
before(() => (liquid = new Liquid()))
|
||||
beforeEach(() => (liquid = new Liquid()))
|
||||
|
||||
it('render blank drop as blank string', async function () {
|
||||
const html = await liquid.parseAndRender('{{blank}}')
|
||||
expect(html).to.equal('')
|
||||
expect(html).toBe('')
|
||||
})
|
||||
it('blank equals nil', async function () {
|
||||
const src = '{%if blank == nil %}blank == nil{%else%}blank != nil{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('blank == nil')
|
||||
expect(html).toBe('blank == nil')
|
||||
})
|
||||
it('false is blank', async function () {
|
||||
const src = '{%if false == blank %}false == blank{%else%}false != blank{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false == blank')
|
||||
expect(html).toBe('false == blank')
|
||||
})
|
||||
it('"" is blank', async function () {
|
||||
const src = '{%if "" == blank %}"" == blank{%else%}"" != blank{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('"" == blank')
|
||||
expect(html).toBe('"" == blank')
|
||||
})
|
||||
it('" " is blank', async function () {
|
||||
const src = '{%if " " == blank %}" " == blank{%else%}" " != blank{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('" " == blank')
|
||||
expect(html).toBe('" " == blank')
|
||||
})
|
||||
it('{} is blank', async function () {
|
||||
const src = '{%if obj == blank %}{} == blank{%else%}{} != blank{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, { obj: {} })
|
||||
expect(html).to.equal('{} == blank')
|
||||
expect(html).toBe('{} == blank')
|
||||
})
|
||||
it('{foo: 1} is not blank', async function () {
|
||||
const src = '{%if obj == blank %}{foo: 1} == blank{%else%}{foo: 1} != blank{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, { obj: { foo: 1 } })
|
||||
expect(html).to.equal('{foo: 1} != blank')
|
||||
expect(html).toBe('{foo: 1} != blank')
|
||||
})
|
||||
it('[] is blank', async function () {
|
||||
const src = '{%if arr == blank %}[] == blank{%else%}[] != blank{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, { arr: [] })
|
||||
expect(html).to.equal('[] == blank')
|
||||
expect(html).toBe('[] == blank')
|
||||
})
|
||||
it('[1] is not blank', async function () {
|
||||
const src = '{%if arr == blank %}[1] == blank{%else%}[1] != blank{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, { arr: [1] })
|
||||
expect(html).to.equal('[1] != blank')
|
||||
expect(html).toBe('[1] != blank')
|
||||
})
|
||||
})
|
||||
@@ -1,9 +1,8 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid, Drop } from '../../../src'
|
||||
|
||||
describe('drop/drop', function () {
|
||||
let liquid: Liquid
|
||||
before(() => (liquid = new Liquid()))
|
||||
beforeEach(() => (liquid = new Liquid()))
|
||||
|
||||
class CustomDrop extends Drop {
|
||||
private name = 'NAME'
|
||||
@@ -27,39 +26,39 @@ describe('drop/drop', function () {
|
||||
}
|
||||
it('should call corresponding method when output', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.getName}}`, { obj: new CustomDrop() })
|
||||
expect(html).to.equal('GET NAME')
|
||||
expect(html).toBe('GET NAME')
|
||||
})
|
||||
it('should call corresponding method when expression evaluates', async function () {
|
||||
const html = await liquid.parseAndRender(`{% if obj.getName == "GET NAME" %}true{% endif %}`, { obj: new CustomDrop() })
|
||||
expect(html).to.equal('true')
|
||||
expect(html).toBe('true')
|
||||
})
|
||||
it('should read corresponding property', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.name}}`, { obj: new CustomDrop() })
|
||||
expect(html).to.equal('NAME')
|
||||
expect(html).toBe('NAME')
|
||||
})
|
||||
it('should output empty string if not exist', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.foo}}`, { obj: new CustomDrop() })
|
||||
expect(html).to.equal('')
|
||||
expect(html).toBe('')
|
||||
})
|
||||
it('should respect liquidMethodMissing', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.foo}}`, { obj: new CustomDropWithMethodMissing() })
|
||||
expect(html).to.equal('FOO')
|
||||
expect(html).toBe('FOO')
|
||||
})
|
||||
it('should call corresponding promise method', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.getName}}`, { obj: new PromiseDrop() })
|
||||
expect(html).to.equal('GET NAME')
|
||||
expect(html).toBe('GET NAME')
|
||||
})
|
||||
it('should read corresponding promise property', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.name}}`, { obj: new PromiseDrop() })
|
||||
expect(html).to.equal('NAME')
|
||||
expect(html).toBe('NAME')
|
||||
})
|
||||
it('should resolve before calling filters', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.name | downcase}}`, { obj: new PromiseDrop() })
|
||||
expect(html).to.equal('name')
|
||||
expect(html).toBe('name')
|
||||
})
|
||||
it('should support promise returned by liquidMethodMissing', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.foo}}`, { obj: new PromiseDrop() })
|
||||
expect(html).to.equal('FOO')
|
||||
expect(html).toBe('FOO')
|
||||
})
|
||||
it('should respect valueOf', async () => {
|
||||
class CustomDrop extends Drop {
|
||||
@@ -70,7 +69,7 @@ describe('drop/drop', function () {
|
||||
}
|
||||
const tpl = '{{drop}}: {% for field in drop %}{{ field }};{% endfor %}'
|
||||
const html = await liquid.parseAndRender(tpl, { drop: new CustomDrop() })
|
||||
expect(html).to.equal('foobar: foo;bar;')
|
||||
expect(html).toBe('foobar: foo;bar;')
|
||||
})
|
||||
it('should support valueOf in == expression', async () => {
|
||||
class AddressDrop extends Drop {
|
||||
@@ -82,6 +81,6 @@ describe('drop/drop', function () {
|
||||
const customer = { default_address: new AddressDrop() }
|
||||
const tpl = `{% if address == customer.default_address %}{{address}}{% endif %}`
|
||||
const html = await liquid.parseAndRender(tpl, { address, customer })
|
||||
expect(html).to.equal('test')
|
||||
expect(html).toBe('test')
|
||||
})
|
||||
})
|
||||
@@ -1,92 +1,91 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('drop/empty-drop', function () {
|
||||
let liquid: Liquid
|
||||
before(() => (liquid = new Liquid()))
|
||||
beforeEach(() => (liquid = new Liquid()))
|
||||
|
||||
it('render empty drop as empty string', async function () {
|
||||
const html = await liquid.parseAndRender('{{empty}}')
|
||||
expect(html).to.equal('')
|
||||
expect(html).toBe('')
|
||||
})
|
||||
it('nil is not empty', async function () {
|
||||
const src = '{%if nil == empty %}nil == empty{%else%}nil != empty{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('nil != empty')
|
||||
expect(html).toBe('nil != empty')
|
||||
})
|
||||
it('false is not empty', async function () {
|
||||
const src = '{%if false == empty %}false == empty{%else%}false != empty{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false != empty')
|
||||
expect(html).toBe('false != empty')
|
||||
})
|
||||
it('"" is empty', async function () {
|
||||
const src = '{%if "" == empty %}"" == empty{%else%}"" != empty{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('"" == empty')
|
||||
expect(html).toBe('"" == empty')
|
||||
})
|
||||
it('" " is not empty', async function () {
|
||||
const src = '{%if " " == empty %}" " == empty{%else%}" " != empty{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('" " != empty')
|
||||
expect(html).toBe('" " != empty')
|
||||
})
|
||||
it('{} is empty', async function () {
|
||||
const src = '{%if obj == empty %}{} == empty{%else%}{} != empty{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, { obj: {} })
|
||||
expect(html).to.equal('{} == empty')
|
||||
expect(html).toBe('{} == empty')
|
||||
})
|
||||
it('{foo: 1} is not empty', async function () {
|
||||
const src = '{%if obj == empty %}{foo: 1} == empty{%else%}{foo: 1} != empty{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, { obj: { foo: 1 } })
|
||||
expect(html).to.equal('{foo: 1} != empty')
|
||||
expect(html).toBe('{foo: 1} != empty')
|
||||
})
|
||||
it('[] is empty', async function () {
|
||||
const src = '{%if arr == empty %}[] == empty{%else%}[] != empty{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, { arr: [] })
|
||||
expect(html).to.equal('[] == empty')
|
||||
expect(html).toBe('[] == empty')
|
||||
})
|
||||
it('[1] is not empty', async function () {
|
||||
const src = '{%if arr == empty %}[1] == empty{%else%}[1] != empty{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, { arr: [1] })
|
||||
expect(html).to.equal('[1] != empty')
|
||||
expect(html).toBe('[1] != empty')
|
||||
})
|
||||
it('1 < empty should be false', async function () {
|
||||
const src = '{%if 1 < empty %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false')
|
||||
expect(html).toBe('false')
|
||||
})
|
||||
it('1 <= empty should be false', async function () {
|
||||
const src = '{%if 1 <= empty %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false')
|
||||
expect(html).toBe('false')
|
||||
})
|
||||
it('1 > empty should be false', async function () {
|
||||
const src = '{%if 1 > empty %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false')
|
||||
expect(html).toBe('false')
|
||||
})
|
||||
it('1 >= empty should be false', async function () {
|
||||
const src = '{%if 1 >= empty %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false')
|
||||
expect(html).toBe('false')
|
||||
})
|
||||
it('1 == empty should be false', async function () {
|
||||
const src = '{%if 1 == empty %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false')
|
||||
expect(html).toBe('false')
|
||||
})
|
||||
it('1 != empty should be true', async function () {
|
||||
const src = '{%if 1 != empty %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('true')
|
||||
expect(html).toBe('true')
|
||||
})
|
||||
it('empty != empty', async function () {
|
||||
const src = '{%if empty == empty %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false')
|
||||
expect(html).toBe('false')
|
||||
})
|
||||
it('empty != nil', async function () {
|
||||
const src = '{%if empty == nil %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false')
|
||||
expect(html).toBe('false')
|
||||
})
|
||||
})
|
||||
@@ -1,41 +1,40 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('drop/null-drop', function () {
|
||||
let liquid: Liquid
|
||||
before(() => (liquid = new Liquid()))
|
||||
beforeEach(() => (liquid = new Liquid()))
|
||||
|
||||
it('render nil as empty string', async function () {
|
||||
const html = await liquid.parseAndRender('{{nil}}')
|
||||
expect(html).to.equal('')
|
||||
expect(html).toBe('')
|
||||
})
|
||||
it('render null as empty string', async function () {
|
||||
const html = await liquid.parseAndRender('{{null}}')
|
||||
expect(html).to.equal('')
|
||||
expect(html).toBe('')
|
||||
})
|
||||
it('undefined == null', async function () {
|
||||
const src = '{%if foo == nil %}foo == nil{%else%}foo != nil{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('foo == nil')
|
||||
expect(html).toBe('foo == nil')
|
||||
})
|
||||
it('nil != blank', async function () {
|
||||
const src = '{%if nil == blank %}eq{%else%}neq{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('neq')
|
||||
expect(html).toBe('neq')
|
||||
})
|
||||
it('nil != empty', async function () {
|
||||
const src = '{%if nil == empty %}eq{%else%}neq{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('neq')
|
||||
expect(html).toBe('neq')
|
||||
})
|
||||
it('0 != null', async function () {
|
||||
const src = '{%if 0 == null %}0 == null{%else%}0 != null{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('0 != null')
|
||||
expect(html).toBe('0 != null')
|
||||
})
|
||||
it('nil == null', async function () {
|
||||
const src = '{%if nil == null %}nil == null{%else%}nil != null{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('nil == null')
|
||||
expect(html).toBe('nil == null')
|
||||
})
|
||||
})
|
||||
@@ -1,7 +1,4 @@
|
||||
import { test, render } from '../../stub/render'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('filters/array', function () {
|
||||
describe('index', function () {
|
||||
@@ -25,7 +22,7 @@ describe('filters/array', function () {
|
||||
it('should throw when comma missing', async () => {
|
||||
const src = '{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}' +
|
||||
'{{ beatles | join " and " }}'
|
||||
return expect(render(src)).to.be.rejectedWith('unexpected token at "\\" and \\"", line:1, col:65')
|
||||
return expect(render(src)).rejects.toThrow('unexpected token at "\\" and \\"", line:1, col:65')
|
||||
})
|
||||
})
|
||||
describe('last', () => {
|
||||
@@ -104,7 +101,7 @@ describe('filters/array', function () {
|
||||
const scope = { arr: ['a', 'b', 'c'] }
|
||||
await render('{{ arr | reverse | join: "" }}', scope)
|
||||
const html = await render('{{ arr | join: "" }}', scope)
|
||||
expect(html).to.equal('abc')
|
||||
expect(html).toBe('abc')
|
||||
})
|
||||
})
|
||||
describe('size', function () {
|
||||
@@ -1,5 +1,4 @@
|
||||
import { test } from '../../stub/render'
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('filters/html', function () {
|
||||
@@ -50,24 +49,24 @@ describe('filters/html', function () {
|
||||
'Ulysses?')
|
||||
})
|
||||
it('should strip multiline comments', function () {
|
||||
expect(liquid.parseAndRenderSync('{{"<!--foo\r\nbar \ncoo\t \r\n -->"|strip_html}}')).to.equal('')
|
||||
expect(liquid.parseAndRenderSync('{{"<!--foo\r\nbar \ncoo\t \r\n -->"|strip_html}}')).toBe('')
|
||||
})
|
||||
it('should strip all style tags and their contents', function () {
|
||||
return test('{{ "<style>cite { font-style: italic; }</style><cite>Ulysses<cite>?" | strip_html }}',
|
||||
'Ulysses?')
|
||||
})
|
||||
it('should strip multiline styles', function () {
|
||||
expect(liquid.parseAndRenderSync('{{"<style> \n.header {\r\n color: black;\r\n}\n</style>" | strip_html}}')).to.equal('')
|
||||
expect(liquid.parseAndRenderSync('{{"<style> \n.header {\r\n color: black;\r\n}\n</style>" | strip_html}}')).toBe('')
|
||||
})
|
||||
it('should strip all scripts tags and their contents', function () {
|
||||
return test('{{ "<script async>console.log(\'hello world\')</script><cite>Ulysses<cite>?" | strip_html }}',
|
||||
'Ulysses?')
|
||||
})
|
||||
it('should strip multiline scripts', function () {
|
||||
expect(liquid.parseAndRenderSync('{{ "<script> \nfoo\r\nbar\n</script>" | strip_html }}')).to.equal('')
|
||||
expect(liquid.parseAndRenderSync('{{ "<script> \nfoo\r\nbar\n</script>" | strip_html }}')).toBe('')
|
||||
})
|
||||
it('should not strip non-matched <script>', function () {
|
||||
expect(liquid.parseAndRenderSync('{{ "<script></script>text<script></script>" | strip_html }}')).to.equal('text')
|
||||
expect(liquid.parseAndRenderSync('{{ "<script></script>text<script></script>" | strip_html }}')).toBe('text')
|
||||
})
|
||||
it('should strip until empty', function () {
|
||||
return test('{{"<br/><br />< p ></p></ p >" | strip_html }}', '')
|
||||
@@ -1,4 +1,3 @@
|
||||
import { expect } from 'chai'
|
||||
import { test, liquid } from '../../stub/render'
|
||||
|
||||
describe('filters/math', function () {
|
||||
@@ -48,7 +47,7 @@ describe('filters/math', function () {
|
||||
it('should return "3" for 24,7', () => test('{{ 24 | modulo: 7 }}', '3'))
|
||||
it('should return "3.357" for 183.357,12', async () => {
|
||||
const html = await liquid.parseAndRender('{{ 183.357 | modulo: 12 }}')
|
||||
expect(Number(html)).to.be.closeTo(3.357, 0.001)
|
||||
expect(Number(html)).toBeCloseTo(3.357, 3)
|
||||
})
|
||||
it('should convert string', () => test('{{ "24" | modulo: "7" }}', '3'))
|
||||
})
|
||||
@@ -1,32 +1,28 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('filters/object', function () {
|
||||
const liquid = new Liquid()
|
||||
describe('default', function () {
|
||||
it('false should use default', async () => expect(await liquid.parseAndRender('{{false | default: "a"}}')).to.equal('a'))
|
||||
it('empty string should use default', async () => expect(await liquid.parseAndRender('{{"" | default: "a"}}')).to.equal('a'))
|
||||
it('empty array should use default', async () => expect(await liquid.parseAndRender('{{arr | default: "a"}}', { arr: [] })).to.equal('a'))
|
||||
it('non-empty string should not use default', async () => expect(await liquid.parseAndRender('{{" " | default: "a"}}')).to.equal(' '))
|
||||
it('nil should use default', async () => expect(await liquid.parseAndRender('{{nil | default: "a"}}')).to.equal('a'))
|
||||
it('undefined should use default', async () => expect(await liquid.parseAndRender('{{not_defined | default: "a"}}')).to.equal('a'))
|
||||
it('true should not use default', async () => expect(await liquid.parseAndRender('{{true | default: "a"}}')).to.equal('true'))
|
||||
it('0 should not use default', async () => expect(await liquid.parseAndRender('{{0 | default: "a"}}')).to.equal('0'))
|
||||
it('should output false when allow_false=true', async () => expect(await liquid.parseAndRender('{{false | default: true, allow_false: true}}')).to.equal('false'))
|
||||
it('should output default without allow_false', async () => expect(await liquid.parseAndRender('{{false | default: true}}')).to.equal('true'))
|
||||
it('should output default when allow_false=false', async () => expect(await liquid.parseAndRender('{{false | default: true, allow_false: false}}')).to.equal('true'))
|
||||
it('false should use default', async () => expect(await liquid.parseAndRender('{{false | default: "a"}}')).toBe('a'))
|
||||
it('empty string should use default', async () => expect(await liquid.parseAndRender('{{"" | default: "a"}}')).toBe('a'))
|
||||
it('empty array should use default', async () => expect(await liquid.parseAndRender('{{arr | default: "a"}}', { arr: [] })).toBe('a'))
|
||||
it('non-empty string should not use default', async () => expect(await liquid.parseAndRender('{{" " | default: "a"}}')).toBe(' '))
|
||||
it('nil should use default', async () => expect(await liquid.parseAndRender('{{nil | default: "a"}}')).toBe('a'))
|
||||
it('undefined should use default', async () => expect(await liquid.parseAndRender('{{not_defined | default: "a"}}')).toBe('a'))
|
||||
it('true should not use default', async () => expect(await liquid.parseAndRender('{{true | default: "a"}}')).toBe('true'))
|
||||
it('0 should not use default', async () => expect(await liquid.parseAndRender('{{0 | default: "a"}}')).toBe('0'))
|
||||
it('should output false when allow_false=true', async () => expect(await liquid.parseAndRender('{{false | default: true, allow_false: true}}')).toBe('false'))
|
||||
it('should output default without allow_false', async () => expect(await liquid.parseAndRender('{{false | default: true}}')).toBe('true'))
|
||||
it('should output default when allow_false=false', async () => expect(await liquid.parseAndRender('{{false | default: true, allow_false: false}}')).toBe('true'))
|
||||
it('should throw for additional args', () => {
|
||||
const src = `{{ age | default: 'now' date: '%d'}}` // missing `|` before `date`
|
||||
return expect(liquid.parseAndRender(src)).to.be.rejectedWith(/unexpected character "date: '%d'"/)
|
||||
return expect(liquid.parseAndRender(src)).rejects.toThrow(/unexpected character "date: '%d'"/)
|
||||
})
|
||||
})
|
||||
describe('json', function () {
|
||||
it('should stringify string', async () => expect(await liquid.parseAndRender('{{"foo" | json}}')).to.equal('"foo"'))
|
||||
it('should stringify number', async () => expect(await liquid.parseAndRender('{{2 | json}}')).to.equal('2'))
|
||||
it('should stringify object', async () => expect(await liquid.parseAndRender('{{obj | json}}', { obj: { foo: 'bar' } })).to.equal('{"foo":"bar"}'))
|
||||
it('should stringify array', async () => expect(await liquid.parseAndRender('{{arr | json}}', { arr: [-2, 'a'] })).to.equal('[-2,"a"]'))
|
||||
it('should stringify string', async () => expect(await liquid.parseAndRender('{{"foo" | json}}')).toBe('"foo"'))
|
||||
it('should stringify number', async () => expect(await liquid.parseAndRender('{{2 | json}}')).toBe('2'))
|
||||
it('should stringify object', async () => expect(await liquid.parseAndRender('{{obj | json}}', { obj: { foo: 'bar' } })).toBe('{"foo":"bar"}'))
|
||||
it('should stringify array', async () => expect(await liquid.parseAndRender('{{arr | json}}', { arr: [-2, 'a'] })).toBe('[-2,"a"]'))
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,4 @@
|
||||
import { test } from '../../stub/render'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('filters/string', function () {
|
||||
describe('append', function () {
|
||||
@@ -10,7 +6,7 @@ describe('filters/string', function () {
|
||||
() => test('{{ -3 | append: "abc" }}', '-3abc'))
|
||||
it('should return "abar" for "a", foo', () => test('{{ "a" | append: foo }}', { foo: 'bar' }, 'abar'))
|
||||
it('should throw if second argument not set', () => {
|
||||
return expect(test('{{ "abc" | append }}', 'abc')).to.be.rejectedWith(/2 arguments/)
|
||||
return expect(test('{{ "abc" | append }}', 'abc')).rejects.toThrow(/2 arguments/)
|
||||
})
|
||||
it('should return "abcfalse" for "abc", false', () => test('{{ "abc" | append: false }}', 'abcfalse'))
|
||||
})
|
||||
@@ -19,7 +15,7 @@ describe('filters/string', function () {
|
||||
() => test('{{ -3 | prepend: "abc" }}', 'abc-3'))
|
||||
it('should return "abar" for "a", foo', () => test('{{ "a" | prepend: foo }}', { foo: 'bar' }, 'bara'))
|
||||
it('should throw if second argument not set', () => {
|
||||
return expect(test('{{ "abc" | prepend }}', 'abc')).to.be.rejectedWith(/2 arguments/)
|
||||
return expect(test('{{ "abc" | prepend }}', 'abc')).rejects.toThrow(/2 arguments/)
|
||||
})
|
||||
it('should return "falseabc" for "abc", false', () => test('{{ "abc" | prepend: false }}', 'falseabc'))
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid, Template } from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
import { Template } from '../../../src/template'
|
||||
|
||||
describe('LiquidOptions#cache', function () {
|
||||
afterEach(restore)
|
||||
@@ -13,10 +13,10 @@ describe('LiquidOptions#cache', function () {
|
||||
})
|
||||
mock({ '/root/files/foo.html': 'foo' })
|
||||
const x = await engine.renderFile('files/foo')
|
||||
expect(x).to.equal('foo')
|
||||
expect(x).toBe('foo')
|
||||
mock({ '/root/files/foo.html': 'bar' })
|
||||
const y = await engine.renderFile('files/foo')
|
||||
expect(y).to.equal('bar')
|
||||
expect(y).toBe('bar')
|
||||
})
|
||||
it('should be disabled when cache <= 0', async function () {
|
||||
const engine = new Liquid({
|
||||
@@ -26,10 +26,10 @@ describe('LiquidOptions#cache', function () {
|
||||
})
|
||||
mock({ '/root/files/foo.html': 'foo' })
|
||||
const x = await engine.renderFile('files/foo')
|
||||
expect(x).to.equal('foo')
|
||||
expect(x).toBe('foo')
|
||||
mock({ '/root/files/foo.html': 'bar' })
|
||||
const y = await engine.renderFile('files/foo')
|
||||
expect(y).to.equal('bar')
|
||||
expect(y).toBe('bar')
|
||||
})
|
||||
it('should respect cache=true option', async function () {
|
||||
const engine = new Liquid({
|
||||
@@ -39,10 +39,10 @@ describe('LiquidOptions#cache', function () {
|
||||
})
|
||||
mock({ '/root/files/foo.html': 'foo' })
|
||||
const x = await engine.renderFile('files/foo')
|
||||
expect(x).to.equal('foo')
|
||||
expect(x).toBe('foo')
|
||||
mock({ '/root/files/foo.html': 'bar' })
|
||||
const y = await engine.renderFile('files/foo')
|
||||
expect(y).to.equal('foo')
|
||||
expect(y).toBe('foo')
|
||||
})
|
||||
it('should respect cache=2 option', async function () {
|
||||
const engine = new Liquid({
|
||||
@@ -57,12 +57,12 @@ describe('LiquidOptions#cache', function () {
|
||||
mock({ '/root/files/foo.html': 'FOO' })
|
||||
await engine.renderFile('files/bar')
|
||||
const x = await engine.renderFile('files/foo')
|
||||
expect(x).to.equal('foo')
|
||||
expect(x).toBe('foo')
|
||||
|
||||
await engine.renderFile('files/bar')
|
||||
await engine.renderFile('files/coo')
|
||||
const y = await engine.renderFile('files/foo')
|
||||
expect(y).to.equal('FOO')
|
||||
expect(y).toBe('FOO')
|
||||
})
|
||||
it('should respect cache={read, write} option', async function () {
|
||||
let last: Template[] | undefined
|
||||
@@ -70,6 +70,7 @@ describe('LiquidOptions#cache', function () {
|
||||
root: '/root/',
|
||||
extname: '.html',
|
||||
cache: {
|
||||
remove: () => void (0),
|
||||
read: (): Template[] | undefined => last,
|
||||
write: (key: string, value: Template[]) => { last = value }
|
||||
}
|
||||
@@ -77,9 +78,9 @@ describe('LiquidOptions#cache', function () {
|
||||
mock({ '/root/files/foo.html': 'foo' })
|
||||
mock({ '/root/files/bar.html': 'bar' })
|
||||
mock({ '/root/files/coo.html': 'coo' })
|
||||
expect(await engine.renderFile('files/foo')).to.equal('foo')
|
||||
expect(await engine.renderFile('files/bar')).to.equal('foo')
|
||||
expect(await engine.renderFile('files/coo')).to.equal('foo')
|
||||
expect(await engine.renderFile('files/foo')).toBe('foo')
|
||||
expect(await engine.renderFile('files/bar')).toBe('foo')
|
||||
expect(await engine.renderFile('files/coo')).toBe('foo')
|
||||
})
|
||||
it('should respect cache={ async read, async write } option', async function () {
|
||||
const cached: { [key: string]: Template[] | undefined } = {}
|
||||
@@ -87,6 +88,7 @@ describe('LiquidOptions#cache', function () {
|
||||
root: '/root/',
|
||||
extname: '.html',
|
||||
cache: {
|
||||
remove: (key: string) => { delete cached[key] },
|
||||
read: (key: string) => Promise.resolve(cached[key]),
|
||||
write: (key: string, value: Template[]) => { cached[key] = value; Promise.resolve() }
|
||||
}
|
||||
@@ -94,11 +96,11 @@ describe('LiquidOptions#cache', function () {
|
||||
mock({ '/root/files/foo.html': 'foo' })
|
||||
mock({ '/root/files/bar.html': 'bar' })
|
||||
mock({ '/root/files/coo.html': 'coo' })
|
||||
expect(await engine.renderFile('files/foo')).to.equal('foo')
|
||||
expect(await engine.renderFile('files/bar')).to.equal('bar')
|
||||
expect(await engine.renderFile('files/coo')).to.equal('coo')
|
||||
expect(await engine.renderFile('files/foo')).toBe('foo')
|
||||
expect(await engine.renderFile('files/bar')).toBe('bar')
|
||||
expect(await engine.renderFile('files/coo')).toBe('coo')
|
||||
mock({ '/root/files/coo.html': 'COO' })
|
||||
expect(await engine.renderFile('files/coo')).to.equal('coo')
|
||||
expect(await engine.renderFile('files/coo')).toBe('coo')
|
||||
})
|
||||
it('should handle concurrent cache read/write', async function () {
|
||||
const engine = new Liquid({
|
||||
@@ -115,10 +117,10 @@ describe('LiquidOptions#cache', function () {
|
||||
engine.renderFile('files/bar'),
|
||||
engine.renderFile('files/coo')
|
||||
])
|
||||
expect(foo1).to.equal('foo')
|
||||
expect(foo2).to.equal('foo')
|
||||
expect(bar).to.equal('bar')
|
||||
expect(coo).to.equal('coo')
|
||||
expect(foo1).toBe('foo')
|
||||
expect(foo2).toBe('foo')
|
||||
expect(bar).toBe('bar')
|
||||
expect(coo).toBe('coo')
|
||||
})
|
||||
it('should not cache not exist file', async function () {
|
||||
const engine = new Liquid({
|
||||
@@ -132,7 +134,7 @@ describe('LiquidOptions#cache', function () {
|
||||
|
||||
mock({ '/root/foo.html': 'foo' })
|
||||
const html = await engine.renderFile('foo')
|
||||
expect(html).to.equal('foo')
|
||||
expect(html).toBe('foo')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -144,11 +146,11 @@ describe('LiquidOptions#cache', function () {
|
||||
})
|
||||
mock({ '/root/foo.html': 'foo' })
|
||||
const x = engine.renderFileSync('foo')
|
||||
expect(x).to.equal('foo')
|
||||
expect(x).toBe('foo')
|
||||
|
||||
mock({ '/root/foo.html': 'bar' })
|
||||
const y = engine.renderFileSync('foo')
|
||||
expect(y).to.equal('bar')
|
||||
expect(y).toBe('bar')
|
||||
})
|
||||
it('should respect cache=true option', function () {
|
||||
const engine = new Liquid({
|
||||
@@ -157,9 +159,9 @@ describe('LiquidOptions#cache', function () {
|
||||
cache: true
|
||||
})
|
||||
mock({ '/root/foo.html': 'foo' })
|
||||
expect(engine.renderFileSync('foo')).to.equal('foo')
|
||||
expect(engine.renderFileSync('foo')).toBe('foo')
|
||||
mock({ '/root/foo.html': 'bar' })
|
||||
expect(engine.renderFileSync('foo')).to.equal('foo')
|
||||
expect(engine.renderFileSync('foo')).toBe('foo')
|
||||
})
|
||||
it('should not cache not exist file', async function () {
|
||||
const engine = new Liquid({
|
||||
@@ -171,7 +173,7 @@ describe('LiquidOptions#cache', function () {
|
||||
|
||||
mock({ '/root/foo.html': 'foo' })
|
||||
const y = await engine.renderFile('foo')
|
||||
expect(y).to.equal('foo')
|
||||
expect(y).toBe('foo')
|
||||
})
|
||||
it('should cache relative referenced files properly', async function () {
|
||||
const engine = new Liquid({
|
||||
@@ -186,10 +188,10 @@ describe('LiquidOptions#cache', function () {
|
||||
'/root/another/bar.html': 'bar2'
|
||||
})
|
||||
const foo1 = await engine.renderFile('foo')
|
||||
expect(foo1).to.equal('bar1')
|
||||
expect(foo1).toBe('bar1')
|
||||
|
||||
const foo2 = await engine.renderFile('another/foo')
|
||||
expect(foo2).to.equal('bar2')
|
||||
expect(foo2).toBe('bar2')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,3 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('LiquidOptions#*_delimiter_*', function () {
|
||||
@@ -8,7 +7,7 @@ describe('LiquidOptions#*_delimiter_*', function () {
|
||||
tagDelimiterRight: '%>'
|
||||
})
|
||||
const html = await engine.parseAndRender('<%=if true%>foo<%=endif%> ')
|
||||
return expect(html).to.equal('foo ')
|
||||
return expect(html).toBe('foo ')
|
||||
})
|
||||
it('should respect output_delimiter_*', async function () {
|
||||
const engine = new Liquid({
|
||||
@@ -16,7 +15,7 @@ describe('LiquidOptions#*_delimiter_*', function () {
|
||||
outputDelimiterRight: '>>'
|
||||
})
|
||||
const html = await engine.parseAndRender('<< "liquid" | capitalize >>')
|
||||
return expect(html).to.equal('Liquid')
|
||||
return expect(html).toBe('Liquid')
|
||||
})
|
||||
it('should support trimming with tag_delimiter_* set', async function () {
|
||||
const engine = new Liquid({
|
||||
@@ -26,6 +25,6 @@ describe('LiquidOptions#*_delimiter_*', function () {
|
||||
trimTagRight: true
|
||||
})
|
||||
const html = await engine.parseAndRender(' <%=if true%> \tfoo\t <%=endif%> ')
|
||||
return expect(html).to.equal('foo')
|
||||
return expect(html).toBe('foo')
|
||||
})
|
||||
})
|
||||
@@ -1,11 +1,10 @@
|
||||
import { expect, use } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('LiquidOptions#fs', function () {
|
||||
let engine: Liquid
|
||||
const fs = {
|
||||
sep: '/',
|
||||
dirname: (x: string) => x.split('/').slice(0, -1).join('/'),
|
||||
exists: (x: string) => Promise.resolve(!x.match(/not-exist/)),
|
||||
existsSync: (x: string) => !x.match(/not-exist/),
|
||||
readFile: (x: string) => Promise.resolve(`content for ${x}`),
|
||||
@@ -21,17 +20,17 @@ describe('LiquidOptions#fs', function () {
|
||||
})
|
||||
it('should be used to read templates', async function () {
|
||||
const html = await engine.renderFile('files/foo')
|
||||
expect(html).to.equal('content for /root/files/foo')
|
||||
expect(html).toBe('content for /root/files/foo')
|
||||
})
|
||||
|
||||
it('should support fallback', async function () {
|
||||
const html = await engine.renderFile('not-exist/foo')
|
||||
expect(html).to.equal('content for /root/files/fallback')
|
||||
expect(html).toBe('content for /root/files/fallback')
|
||||
})
|
||||
|
||||
it('should support renderSync', function () {
|
||||
const html = engine.renderFileSync('not-exist/foo')
|
||||
expect(html).to.equal('content for /root/files/fallback')
|
||||
expect(html).toBe('content for /root/files/fallback')
|
||||
})
|
||||
|
||||
it('should throw lookup failure if fallback not specified', function () {
|
||||
@@ -40,6 +39,14 @@ describe('LiquidOptions#fs', function () {
|
||||
fs: { ...fs, fallback: undefined }
|
||||
} as any)
|
||||
return expect(engine.renderFile('not-exist/foo'))
|
||||
.to.be.rejectedWith('Failed to lookup')
|
||||
.rejects.toThrow('Failed to lookup')
|
||||
})
|
||||
|
||||
it('should disable relativeReference if `sep` and `dirname` not specified', function () {
|
||||
const engine = new Liquid({
|
||||
root: '/root/',
|
||||
fs: { ...fs, sep: undefined, dirname: undefined }
|
||||
} as any)
|
||||
expect(engine.options.relativeReference).toBe(false)
|
||||
})
|
||||
})
|
||||
+8
-9
@@ -1,4 +1,3 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('LiquidOptions#*keepOutputType*', function () {
|
||||
@@ -12,13 +11,13 @@ describe('LiquidOptions#*keepOutputType*', function () {
|
||||
'my-string': 'test'
|
||||
}
|
||||
const booleanHtml = await engine.parseAndRender('{{my-boolean}}', context)
|
||||
expect(booleanHtml).to.equal(true)
|
||||
expect(booleanHtml).toBe(true)
|
||||
const numberHtml = await engine.parseAndRender('{{my-number}}', context)
|
||||
expect(numberHtml).to.equal(42)
|
||||
expect(numberHtml).toBe(42)
|
||||
const html = await engine.parseAndRender('{{my-string}}', context)
|
||||
expect(html).to.equal('test')
|
||||
expect(html).toBe('test')
|
||||
const composedHtml = await engine.parseAndRender('{{my-string}}:{{my-number}}', context)
|
||||
expect(composedHtml).to.equal('test:42')
|
||||
expect(composedHtml).toBe('test:42')
|
||||
})
|
||||
|
||||
it('should respect keepOutputType = false as default', async function () {
|
||||
@@ -29,12 +28,12 @@ describe('LiquidOptions#*keepOutputType*', function () {
|
||||
'my-string': 'test'
|
||||
}
|
||||
const booleanHtml = await engine.parseAndRender('{{my-boolean}}', context)
|
||||
expect(booleanHtml).to.equal('true')
|
||||
expect(booleanHtml).toBe('true')
|
||||
const numberHtml = await engine.parseAndRender('{{my-number}}', context)
|
||||
expect(numberHtml).to.equal('42')
|
||||
expect(numberHtml).toBe('42')
|
||||
const html = await engine.parseAndRender('{{my-string}}', context)
|
||||
expect(html).to.equal('test')
|
||||
expect(html).toBe('test')
|
||||
const composedHtml = await engine.parseAndRender('{{my-string}}:{{my-number}}', context)
|
||||
expect(composedHtml).to.equal('test:42')
|
||||
expect(composedHtml).toBe('test:42')
|
||||
})
|
||||
})
|
||||
@@ -1,12 +1,7 @@
|
||||
import * as chai from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Liquid, Context, isFalsy } from '../../../src'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
import { drainStream } from '../../stub/stream'
|
||||
|
||||
const expect = chai.expect
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
describe('Liquid', function () {
|
||||
describe('#plugin()', function () {
|
||||
it('should call plugin on the instance', async function () {
|
||||
@@ -15,7 +10,7 @@ describe('Liquid', function () {
|
||||
this.registerFilter('foo', x => `foo${x}foo`)
|
||||
})
|
||||
const html = await engine.parseAndRender('{{"bar"|foo}}')
|
||||
expect(html).to.equal('foobarfoo')
|
||||
expect(html).toBe('foobarfoo')
|
||||
})
|
||||
it('should call plugin with Liquid', async function () {
|
||||
const engine = new Liquid()
|
||||
@@ -23,92 +18,92 @@ describe('Liquid', function () {
|
||||
this.registerFilter('t', function (v) { return isFalsy(v, this.context) })
|
||||
})
|
||||
const html = await engine.parseAndRender('{{false|t}}')
|
||||
expect(html).to.equal('true')
|
||||
expect(html).toBe('true')
|
||||
})
|
||||
})
|
||||
describe('#parseAndRender', function () {
|
||||
const engine = new Liquid()
|
||||
it('should parse and render variable output', async function () {
|
||||
const html = await engine.parseAndRender('{{"foo"}}')
|
||||
expect(html).to.equal('foo')
|
||||
expect(html).toBe('foo')
|
||||
})
|
||||
it('should parse and render complex output', async function () {
|
||||
const tpl = '{{ "Welcome|to]Liquid" | split: "|" | join: "("}}'
|
||||
const html = await engine.parseAndRender(tpl)
|
||||
expect(html).to.equal('Welcome(to]Liquid')
|
||||
expect(html).toBe('Welcome(to]Liquid')
|
||||
})
|
||||
it('should support for-in with variable', async function () {
|
||||
const src = '{% assign total = 3 | minus: 1 %}' +
|
||||
'{% for i in (1..total) %}{{ i }}{% endfor %}'
|
||||
const html = await engine.parseAndRender(src, {})
|
||||
return expect(html).to.equal('12')
|
||||
return expect(html).toBe('12')
|
||||
})
|
||||
it('should support `globals` render option', async function () {
|
||||
const src = '{{ foo }}'
|
||||
const html = await engine.parseAndRender(src, {}, { globals: { foo: 'FOO' } })
|
||||
return expect(html).to.equal('FOO')
|
||||
return expect(html).toBe('FOO')
|
||||
})
|
||||
it('should support `strictVariables` render option', function () {
|
||||
const src = '{{ foo }}'
|
||||
return expect(engine.parseAndRender(src, {}, { strictVariables: true })).rejectedWith(/undefined variable/)
|
||||
return expect(engine.parseAndRender(src, {}, { strictVariables: true })).rejects.toThrow(/undefined variable/)
|
||||
})
|
||||
it('should support async variables in output', async () => {
|
||||
const src = '{{ foo }}'
|
||||
const html = await engine.parseAndRender(src, { foo: Promise.resolve('FOO') })
|
||||
expect(html).to.equal('FOO')
|
||||
expect(html).toBe('FOO')
|
||||
})
|
||||
it('should parse and render with Context', async function () {
|
||||
const html = await engine.parseAndRender('{{foo}}', new Context({ foo: 'FOO' }))
|
||||
expect(html).to.equal('FOO')
|
||||
expect(html).toBe('FOO')
|
||||
})
|
||||
})
|
||||
describe('#parseAndRenderSync', function () {
|
||||
const engine = new Liquid()
|
||||
it('should parse and render variable output', function () {
|
||||
const html = engine.parseAndRenderSync('{{"foo"}}')
|
||||
expect(html).to.equal('foo')
|
||||
expect(html).toBe('foo')
|
||||
})
|
||||
it('should parse and render complex output', function () {
|
||||
const tpl = '{{ "Welcome|to]Liquid" | split: "|" | join: "("}}'
|
||||
const html = engine.parseAndRenderSync(tpl)
|
||||
expect(html).to.equal('Welcome(to]Liquid')
|
||||
expect(html).toBe('Welcome(to]Liquid')
|
||||
})
|
||||
it('should support for-in with variable', function () {
|
||||
const src = '{% assign total = 3 | minus: 1 %}' +
|
||||
'{% for i in (1..total) %}{{ i }}{% endfor %}'
|
||||
const html = engine.parseAndRenderSync(src, {})
|
||||
return expect(html).to.equal('12')
|
||||
return expect(html).toBe('12')
|
||||
})
|
||||
it('should support `globals` render option', function () {
|
||||
const src = '{{ foo }}'
|
||||
const html = engine.parseAndRenderSync(src, {}, { globals: { foo: 'FOO' } })
|
||||
return expect(html).to.equal('FOO')
|
||||
return expect(html).toBe('FOO')
|
||||
})
|
||||
it('should support `strictVariables` render option', function () {
|
||||
const src = '{{ foo }}'
|
||||
return expect(() => engine.parseAndRenderSync(src, {}, { strictVariables: true })).throw(/undefined variable/)
|
||||
return expect(() => engine.parseAndRenderSync(src, {}, { strictVariables: true })).toThrow(/undefined variable/)
|
||||
})
|
||||
})
|
||||
describe('#express()', function () {
|
||||
const liquid = new Liquid({ root: '/root' })
|
||||
const render = liquid.express()
|
||||
before(function () {
|
||||
beforeEach(function () {
|
||||
mock({
|
||||
'/root/foo': 'foo'
|
||||
})
|
||||
})
|
||||
after(restore)
|
||||
afterEach(restore)
|
||||
it('should render single template', function (done) {
|
||||
render.call({ root: '/root' }, 'foo', null as any, (err: Error | null, result: string | undefined) => {
|
||||
if (err) return done(err)
|
||||
expect(result).to.equal('foo')
|
||||
expect(result).toBe('foo')
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('should render single template with Array-typed root', function (done) {
|
||||
render.call({ root: ['/root'] }, 'foo', null as any, (err: Error | null, result: string | undefined) => {
|
||||
if (err) return done(err)
|
||||
expect(result).to.equal('foo')
|
||||
expect(result).toBe('foo')
|
||||
done()
|
||||
})
|
||||
})
|
||||
@@ -119,8 +114,7 @@ describe('Liquid', function () {
|
||||
root: ['/boo', '/root/'],
|
||||
extname: '.html'
|
||||
})
|
||||
return expect(engine.renderFile('/not/exist.html')).to
|
||||
.be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
|
||||
return expect(engine.renderFile('/not/exist.html')).rejects.toThrow(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
|
||||
})
|
||||
})
|
||||
describe('#parseFile', function () {
|
||||
@@ -129,17 +123,16 @@ describe('Liquid', function () {
|
||||
root: ['/boo', '/root/'],
|
||||
extname: '.html'
|
||||
})
|
||||
return expect(engine.parseFile('/not/exist.html')).to
|
||||
.be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
|
||||
return expect(engine.parseFile('/not/exist.html')).rejects.toThrow(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
|
||||
})
|
||||
it('should fallback to require.resolve in Node.js', async function () {
|
||||
const engine = new Liquid({
|
||||
root: ['/root/'],
|
||||
extname: '.html'
|
||||
})
|
||||
const tpls = await engine.parseFileSync('mocha')
|
||||
expect(tpls.length).to.gte(1)
|
||||
expect(tpls[0].token.getText()).to.contain('module.exports')
|
||||
const tpls = await engine.parseFileSync('jest')
|
||||
expect(tpls.length).toBeGreaterThanOrEqual(1)
|
||||
expect(tpls[0].token.getText()).toContain('use strict')
|
||||
})
|
||||
})
|
||||
describe('#evalValue', function () {
|
||||
@@ -147,12 +140,12 @@ describe('Liquid', function () {
|
||||
const engine = new Liquid()
|
||||
const ctx = new Context()
|
||||
const str = await engine.evalValue('"foo"', ctx)
|
||||
expect(str).to.equal('foo')
|
||||
expect(str).toBe('foo')
|
||||
})
|
||||
it('should support plain scope', async function () {
|
||||
const engine = new Liquid()
|
||||
const str = await engine.evalValue('foo', { foo: 'FOO' })
|
||||
expect(str).to.equal('FOO')
|
||||
expect(str).toBe('FOO')
|
||||
})
|
||||
})
|
||||
describe('#evalValueSync', function () {
|
||||
@@ -160,7 +153,7 @@ describe('Liquid', function () {
|
||||
const engine = new Liquid()
|
||||
const ctx = new Context()
|
||||
const str = engine.evalValueSync('"foo"', ctx)
|
||||
expect(str).to.equal('foo')
|
||||
expect(str).toBe('foo')
|
||||
})
|
||||
})
|
||||
describe('#parse', function () {
|
||||
@@ -173,7 +166,7 @@ describe('Liquid', function () {
|
||||
'/root/partial.html': 'foo'
|
||||
})
|
||||
const tpls = engine.parse('{% render "./partial.html" %}', '/root/index.html')
|
||||
return expect(engine.renderSync(tpls)).to.equal('foo')
|
||||
return expect(engine.renderSync(tpls)).toBe('foo')
|
||||
})
|
||||
it('should resolve against pwd for relative filepath', function () {
|
||||
const engine = new Liquid({
|
||||
@@ -184,7 +177,7 @@ describe('Liquid', function () {
|
||||
[`${process.cwd()}/partial.html`]: 'foo'
|
||||
})
|
||||
const tpls = engine.parse('{% render "./partial.html" %}', './index.html')
|
||||
return expect(engine.renderSync(tpls)).to.equal('foo')
|
||||
return expect(engine.renderSync(tpls)).toBe('foo')
|
||||
})
|
||||
})
|
||||
describe('#parseFileSync', function () {
|
||||
@@ -194,7 +187,7 @@ describe('Liquid', function () {
|
||||
extname: '.html'
|
||||
})
|
||||
return expect(() => engine.parseFileSync('/not/exist.html'))
|
||||
.to.throw(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
|
||||
.toThrow(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
|
||||
})
|
||||
it('should throw with lookup list when file not exist', function () {
|
||||
const engine = new Liquid({
|
||||
@@ -202,19 +195,19 @@ describe('Liquid', function () {
|
||||
extname: '.html'
|
||||
})
|
||||
return expect(() => engine.parseFileSync('/not/exist.html'))
|
||||
.to.throw(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
|
||||
.toThrow(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
|
||||
})
|
||||
})
|
||||
describe('#enderToNodeStream', function () {
|
||||
const engine = new Liquid()
|
||||
it('should render a simple value', async () => {
|
||||
const stream = engine.renderToNodeStream(engine.parse('{{"foo"}}'))
|
||||
expect(drainStream(stream)).to.eventually.equal('foo')
|
||||
expect(drainStream(stream)).resolves.toBe('foo')
|
||||
})
|
||||
})
|
||||
describe('#enderFileToNodeStream', function () {
|
||||
let engine: Liquid
|
||||
before(function () {
|
||||
beforeEach(function () {
|
||||
mock({
|
||||
'/root/foo.html': 'foo',
|
||||
'/root/error.html': 'A{%throwingTag%}B'
|
||||
@@ -226,14 +219,14 @@ describe('Liquid', function () {
|
||||
}
|
||||
})
|
||||
})
|
||||
after(restore)
|
||||
afterEach(restore)
|
||||
it('should render a simple value', async () => {
|
||||
const stream = await engine.renderFileToNodeStream('foo.html')
|
||||
expect(drainStream(stream)).to.be.eventually.equal('foo')
|
||||
expect(drainStream(stream)).resolves.toBe('foo')
|
||||
})
|
||||
it('should throw RenderError when tag throws', async () => {
|
||||
const stream = await engine.renderFileToNodeStream('error.html')
|
||||
expect(drainStream(stream)).to.be.rejectedWith(/intended render error/)
|
||||
expect(drainStream(stream)).rejects.toThrow(/intended render error/)
|
||||
})
|
||||
})
|
||||
})
|
||||
+6
-7
@@ -1,4 +1,3 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid, defaultOperators } from '../../../src'
|
||||
|
||||
describe('LiquidOptions#operators', function () {
|
||||
@@ -8,27 +7,27 @@ describe('LiquidOptions#operators', function () {
|
||||
engine = new Liquid({
|
||||
operators: {
|
||||
...defaultOperators,
|
||||
isFooBar: (l, r) => l === 'foo' && r === 'bar'
|
||||
isFooBar: (l: string, r: string) => l === 'foo' && r === 'bar'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should evaluate the default operators', async function () {
|
||||
const result = await engine.parseAndRender('{% if "foo" == "foo" %}True{% endif %}')
|
||||
expect(result).to.equal('True')
|
||||
expect(result).toBe('True')
|
||||
})
|
||||
|
||||
it('should evaluate a custom operator', async function () {
|
||||
const first = await engine.parseAndRender('{% if "foo" isFooBar "bar" %}True{% else %}False{% endif %}')
|
||||
expect(first).to.equal('True')
|
||||
expect(first).toBe('True')
|
||||
const second = await engine.parseAndRender('{% if "foo" isFooBar "foo" %}True{% else %}False{% endif %}')
|
||||
expect(second).to.equal('False')
|
||||
expect(second).toBe('False')
|
||||
})
|
||||
|
||||
it('should evaluate a custom operator with the correct precedence', async function () {
|
||||
const first = await engine.parseAndRender('{% if "foo" isFooBar "bar" or "foo" == "bar" %}True{% else %}False{% endif %}')
|
||||
expect(first).to.equal('True')
|
||||
expect(first).toBe('True')
|
||||
const second = await engine.parseAndRender('{% if "foo" isFooBar "foo" or "foo" == "bar" %}True{% else %}False{% endif %}')
|
||||
expect(second).to.equal('False')
|
||||
expect(second).toBe('False')
|
||||
})
|
||||
})
|
||||
+5
-6
@@ -1,11 +1,10 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('LiquidOptions#*outputEscape*', function () {
|
||||
it('when outputEscape is not set', async function () {
|
||||
const engine = new Liquid()
|
||||
const html = await engine.parseAndRender('{{"<"}}')
|
||||
expect(html).to.equal('<')
|
||||
expect(html).toBe('<')
|
||||
})
|
||||
|
||||
it('should escape when outputEscape="escape"', async function () {
|
||||
@@ -13,7 +12,7 @@ describe('LiquidOptions#*outputEscape*', function () {
|
||||
outputEscape: 'escape'
|
||||
})
|
||||
const html = await engine.parseAndRender('{{"<"}}')
|
||||
expect(html).to.equal('<')
|
||||
expect(html).toBe('<')
|
||||
})
|
||||
|
||||
it('should json stringify when outputEscape="json"', async function () {
|
||||
@@ -21,7 +20,7 @@ describe('LiquidOptions#*outputEscape*', function () {
|
||||
outputEscape: 'json'
|
||||
})
|
||||
const html = await engine.parseAndRender('{{"<"}}')
|
||||
expect(html).to.equal('"<"')
|
||||
expect(html).toBe('"<"')
|
||||
})
|
||||
|
||||
it('should support outputEscape=Function', async function () {
|
||||
@@ -29,7 +28,7 @@ describe('LiquidOptions#*outputEscape*', function () {
|
||||
outputEscape: (v: any) => `{${v}}`
|
||||
})
|
||||
const html = await engine.parseAndRender('{{"<"}}')
|
||||
expect(html).to.equal('{<}')
|
||||
expect(html).toBe('{<}')
|
||||
})
|
||||
|
||||
it('should skip escape for output with filter "| raw"', async function () {
|
||||
@@ -37,6 +36,6 @@ describe('LiquidOptions#*outputEscape*', function () {
|
||||
outputEscape: 'escape'
|
||||
})
|
||||
const html = await engine.parseAndRender('{{"<" | raw}}')
|
||||
expect(html).to.equal('<')
|
||||
expect(html).toBe('<')
|
||||
})
|
||||
})
|
||||
+5
-6
@@ -1,4 +1,3 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('liquid#registerFilter()', function () {
|
||||
@@ -15,13 +14,13 @@ describe('liquid#registerFilter()', function () {
|
||||
const src = `{{ "a" | obj_test: k1: "v1", k2: foo }}`
|
||||
const dst = '["a",["k1","v1"],["k2","bar"]]'
|
||||
const html = await liquid.parseAndRender(src, { foo: 'bar' })
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
it('should support mixed arguments', async () => {
|
||||
const src = `{{ "a" | obj_test: "something", k1: "v1", k2: foo }}`
|
||||
const dst = '["a","something",["k1","v1"],["k2","bar"]]'
|
||||
const html = await liquid.parseAndRender(src, { foo: 'bar' })
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -33,7 +32,7 @@ describe('liquid#registerFilter()', function () {
|
||||
const src = `{{ userId | get_user_data | json }}`
|
||||
const dst = '{"userId":"alice","userName":"ALICE"}'
|
||||
const html = await liquid.parseAndRender(src, { userId: 'alice' })
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -48,7 +47,7 @@ describe('liquid#registerFilter()', function () {
|
||||
const src = `{{ "a\nb" | break }}`
|
||||
const dst = 'a<br/>b'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
it('should not escape filter output when registered as "raw"', async () => {
|
||||
liquid.registerFilter('break', {
|
||||
@@ -58,7 +57,7 @@ describe('liquid#registerFilter()', function () {
|
||||
const src = `{{ "a\nb" | break }}`
|
||||
const dst = 'a<br/>b'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
})
|
||||
})
|
||||
+4
-5
@@ -1,4 +1,3 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('liquid#registerTag()', function () {
|
||||
@@ -8,7 +7,7 @@ describe('liquid#registerTag()', function () {
|
||||
render: () => 'B'
|
||||
})
|
||||
const html = await liquid.parseAndRender(`A{% simple-string %}C`)
|
||||
return expect(html).to.equal('ABC')
|
||||
return expect(html).toBe('ABC')
|
||||
})
|
||||
it('should support async tag render', async () => {
|
||||
const liquid = new Liquid()
|
||||
@@ -16,7 +15,7 @@ describe('liquid#registerTag()', function () {
|
||||
render: async () => 'B'
|
||||
})
|
||||
const html = await liquid.parseAndRender(`A{% async-string %}C`)
|
||||
return expect(html).to.equal('ABC')
|
||||
return expect(html).toBe('ABC')
|
||||
})
|
||||
it('should have access to ctx in render()', async () => {
|
||||
const liquid = new Liquid()
|
||||
@@ -26,7 +25,7 @@ describe('liquid#registerTag()', function () {
|
||||
const html = await liquid.parseAndRender(`A{% dynamic-string %}C`, {
|
||||
c: 'B'
|
||||
})
|
||||
return expect(html).to.equal('ABC')
|
||||
return expect(html).toBe('ABC')
|
||||
})
|
||||
it('should have access to tag arguments', async () => {
|
||||
const liquid = new Liquid()
|
||||
@@ -37,6 +36,6 @@ describe('liquid#registerTag()', function () {
|
||||
const html = await liquid.parseAndRender(`A{% argument-reflector variable=c %}C`, {
|
||||
c: 'B'
|
||||
})
|
||||
return expect(html).to.equal('ABC')
|
||||
return expect(html).toBe('ABC')
|
||||
})
|
||||
})
|
||||
@@ -1,15 +1,14 @@
|
||||
import { normalize } from '../../../src/liquid-options'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('LiquidOptions#root', function () {
|
||||
describe('#normalize ()', function () {
|
||||
it('should normalize string typed root array', function () {
|
||||
const options = normalize({ root: 'foo' })
|
||||
expect(options.root).to.eql(['foo'])
|
||||
expect(options.root).toEqual(['foo'])
|
||||
})
|
||||
it('should normalize null typed root as empty array', function () {
|
||||
const options = normalize({ root: null } as any)
|
||||
expect(options.root).to.eql([])
|
||||
expect(options.root).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,9 +1,4 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import * as chai from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
chai.use(chaiAsPromised)
|
||||
const expect = chai.expect
|
||||
|
||||
describe('LiquidOptions#strict*', function () {
|
||||
let engine: Liquid
|
||||
@@ -16,7 +11,7 @@ describe('LiquidOptions#strict*', function () {
|
||||
})
|
||||
it('should not throw when strictVariables false (default)', async function () {
|
||||
const html = await engine.parseAndRender('before{{notdefined}}after', ctx)
|
||||
return expect(html).to.equal('beforeafter')
|
||||
return expect(html).toBe('beforeafter')
|
||||
})
|
||||
it('should throw when strictVariables true', function () {
|
||||
const tpl = engine.parse('before{{notdefined}}after')
|
||||
@@ -25,8 +20,7 @@ describe('LiquidOptions#strict*', function () {
|
||||
extname: '.html',
|
||||
strictVariables: true
|
||||
})
|
||||
return expect(engine.render(tpl, ctx)).to
|
||||
.be.rejectedWith(/undefined variable: notdefined/)
|
||||
return expect(engine.render(tpl, ctx)).rejects.toThrow(/undefined variable: notdefined/)
|
||||
})
|
||||
it('should pass strictVariables to render by parseAndRender', function () {
|
||||
const html = 'before{{notdefined}}after'
|
||||
@@ -35,8 +29,7 @@ describe('LiquidOptions#strict*', function () {
|
||||
extname: '.html',
|
||||
strictVariables: true
|
||||
})
|
||||
return expect(engine.parseAndRender(html, ctx)).to
|
||||
.be.rejectedWith(/undefined variable: notdefined/)
|
||||
return expect(engine.parseAndRender(html, ctx)).rejects.toThrow(/undefined variable: notdefined/)
|
||||
})
|
||||
describe('with strictVariables and lenientIf', function () {
|
||||
beforeEach(() => {
|
||||
@@ -50,31 +43,31 @@ describe('LiquidOptions#strict*', function () {
|
||||
it('should not throw in `if` with a single variable', async function () {
|
||||
const tpl = engine.parse('before{% if notdefined %}{{notdefined}}{% endif %}after')
|
||||
const html = await engine.render(tpl, ctx)
|
||||
return expect(html).to.equal('beforeafter')
|
||||
return expect(html).toBe('beforeafter')
|
||||
})
|
||||
it('should support elsif with undefined variables', async function () {
|
||||
const tpl = engine.parse('{% if notdefined1 %}a{% elsif notdefined2 %}b{% elsif defined3 %}{{defined3}}{% else %}d{% endif %}')
|
||||
const html = await engine.render(tpl, { 'defined3': 'bla' })
|
||||
return expect(html).to.equal('bla')
|
||||
return expect(html).toBe('bla')
|
||||
})
|
||||
it('should not throw in `unless` with a single variable', async function () {
|
||||
const tpl = engine.parse('before{% unless notdefined %}X{% else %}{{notdefined}}{% endunless %}after')
|
||||
const html = await engine.render(tpl, ctx)
|
||||
return expect(html).to.equal('beforeXafter')
|
||||
return expect(html).toBe('beforeXafter')
|
||||
})
|
||||
it('should still throw with an undefined variable in a compound `if` expression', function () {
|
||||
const tpl = engine.parse('{% if notdefined == 15 %}a{% endif %}')
|
||||
const fhtml = engine.render(tpl, ctx)
|
||||
return expect(fhtml).to.be.rejectedWith(/undefined variable: notdefined/)
|
||||
return expect(fhtml).rejects.toThrow(/undefined variable: notdefined/)
|
||||
})
|
||||
it('should allow an undefined variable when before the `default` filter', async function () {
|
||||
const tpl = engine.parse('{{notdefined | default: "a" | tolower}}')
|
||||
const html = await engine.render(tpl, ctx)
|
||||
return expect(html).to.equal('a')
|
||||
return expect(html).toBe('a')
|
||||
})
|
||||
it('should not allow undefined variable even if `lenientIf` set', async function () {
|
||||
const tpl = engine.parse('{{notdefined | tolower}}')
|
||||
return expect(() => engine.renderSync(tpl, ctx)).to.throw('undefined variable: notdefined')
|
||||
return expect(() => engine.renderSync(tpl, ctx)).toThrow('undefined variable: notdefined')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,3 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('LiquidOptions#trimming', function () {
|
||||
@@ -8,34 +7,34 @@ describe('LiquidOptions#trimming', function () {
|
||||
it('should respect trimTagLeft', async function () {
|
||||
const engine = new Liquid({ trimTagLeft: true })
|
||||
const html = await engine.parseAndRender(' \n \t{%if true%}foo{%endif%} ')
|
||||
return expect(html).to.equal('foo ')
|
||||
return expect(html).toBe('foo ')
|
||||
})
|
||||
it('should respect trimTagRight', async function () {
|
||||
const engine = new Liquid({ trimTagRight: true } as any)
|
||||
const html = await engine.parseAndRender('\t{%if true%}foo{%endif%} \n')
|
||||
return expect(html).to.equal('\tfoo')
|
||||
return expect(html).toBe('\tfoo')
|
||||
})
|
||||
it('should not trim value', async function () {
|
||||
const engine = new Liquid({ trimTagLeft: true, trimTagRight: true } as any)
|
||||
const html = await engine.parseAndRender('{%if true%}a {{name}} b{%endif%}', ctx)
|
||||
return expect(html).to.equal('a harttle b')
|
||||
return expect(html).toBe('a harttle b')
|
||||
})
|
||||
})
|
||||
describe('value trimming', function () {
|
||||
it('should respect trimOutputLeft', async function () {
|
||||
const engine = new Liquid({ trimOutputLeft: true } as any)
|
||||
const html = await engine.parseAndRender(' \n \t{{name}} ', ctx)
|
||||
return expect(html).to.equal('harttle ')
|
||||
return expect(html).toBe('harttle ')
|
||||
})
|
||||
it('should respect trimOutputRight', async function () {
|
||||
const engine = new Liquid({ trimOutputRight: true } as any)
|
||||
const html = await engine.parseAndRender(' \n \t{{name}} ', ctx)
|
||||
return expect(html).to.equal(' \n \tharttle')
|
||||
return expect(html).toBe(' \n \tharttle')
|
||||
})
|
||||
it('should respect not trim tag', async function () {
|
||||
const engine = new Liquid({ trimOutputLeft: true, trimOutputRight: true } as any)
|
||||
const html = await engine.parseAndRender('\t{% if true %} aha {%endif%}\t')
|
||||
return expect(html).to.equal('\t aha \t')
|
||||
return expect(html).toBe('\t aha \t')
|
||||
})
|
||||
})
|
||||
describe('greedy', function () {
|
||||
@@ -43,12 +42,12 @@ describe('LiquidOptions#trimming', function () {
|
||||
it('should enable greedy by default', async function () {
|
||||
const engine = new Liquid()
|
||||
const html = await engine.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('aharttle')
|
||||
return expect(html).toBe('aharttle')
|
||||
})
|
||||
it('should allow greedy:false', async function () {
|
||||
const engine = new Liquid({ greedy: false } as any)
|
||||
const html = await engine.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('\n a \nharttle ')
|
||||
return expect(html).toBe('\n a \nharttle ')
|
||||
})
|
||||
})
|
||||
describe('markup', function () {
|
||||
@@ -64,7 +63,7 @@ describe('LiquidOptions#trimming', function () {
|
||||
].join('\n')
|
||||
const dst = 'Wow, John G. Chalmers-Smith, you have a long name!'
|
||||
const html = await engine.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
it('should not trim when not specified', async function () {
|
||||
const engine = new Liquid()
|
||||
@@ -78,7 +77,7 @@ describe('LiquidOptions#trimming', function () {
|
||||
].join('\n')
|
||||
const dst = '\n\n Wow, John G. Chalmers-Smith, you have a long name!\n'
|
||||
const html = await engine.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
})
|
||||
})
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
import { expect } from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
const liquid = new Liquid()
|
||||
@@ -444,7 +443,7 @@ describe('Whitespace Control', function () {
|
||||
item.text,
|
||||
async () => {
|
||||
const html = await liquid.parseAndRender(item.text)
|
||||
expect(html).to.equal(item.expected)
|
||||
expect(html).toBe(item.expected)
|
||||
}
|
||||
))
|
||||
})
|
||||
@@ -1,41 +1,37 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { ParseError } from '../../../src'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/assign', function () {
|
||||
const liquid = new Liquid()
|
||||
it('should throw when variable name illegal', function () {
|
||||
const src = '{% assign / %}'
|
||||
const ctx = {}
|
||||
return expect(liquid.parseAndRender(src, ctx)).to.be.rejectedWith(/illegal/)
|
||||
return expect(liquid.parseAndRender(src, ctx)).rejects.toThrow(/illegal/)
|
||||
})
|
||||
it('should support assign to a string', async function () {
|
||||
const src = '{% assign foo="bar" %}{{foo}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('bar')
|
||||
return expect(html).toBe('bar')
|
||||
})
|
||||
it('should throw when variable value illegal', function () {
|
||||
const src = '{% assign foo = “bar” %}'
|
||||
expect(() => liquid.parse(src)).to.throw(/unexpected token at "“bar”"/)
|
||||
expect(() => liquid.parse(src)).to.throw(ParseError)
|
||||
expect(() => liquid.parse(src)).toThrow(/unexpected token at "“bar”"/)
|
||||
expect(() => liquid.parse(src)).toThrow(ParseError)
|
||||
})
|
||||
it('should support assign to a number', async function () {
|
||||
const src = '{% assign foo=10086 %}{{foo}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('10086')
|
||||
return expect(html).toBe('10086')
|
||||
})
|
||||
it('should assign as array', async function () {
|
||||
const src = '{% assign foo=(1..3) %}{{foo}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('123')
|
||||
return expect(html).toBe('123')
|
||||
})
|
||||
it('should assign as filter result', async function () {
|
||||
const src = '{% assign foo="a b" | capitalize | split: " " | first %}{{foo}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('A')
|
||||
return expect(html).toBe('A')
|
||||
})
|
||||
it('should assign as filter across multiple lines as result', async function () {
|
||||
const src = `{% assign foo="a b"
|
||||
@@ -43,64 +39,64 @@ describe('tags/assign', function () {
|
||||
| split: " "
|
||||
| first %}{{foo}}`
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('A')
|
||||
return expect(html).toBe('A')
|
||||
})
|
||||
it('should assign var-1', async function () {
|
||||
const src = '{% assign var-1 = 5 %}{{ var-1 }}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('5')
|
||||
return expect(html).toBe('5')
|
||||
})
|
||||
it('should assign var-', async function () {
|
||||
const src = '{% assign var- = 5 %}{{ var- }}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('5')
|
||||
return expect(html).toBe('5')
|
||||
})
|
||||
it('should assign -var', async function () {
|
||||
const src = '{% assign -let = 5 %}{{ -let }}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('5')
|
||||
return expect(html).toBe('5')
|
||||
})
|
||||
it('should assign -5-5', async function () {
|
||||
const src = '{% assign -5-5 = 5 %}{{ -5-5 }}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('5')
|
||||
return expect(html).toBe('5')
|
||||
})
|
||||
it('should assign 4-3', async function () {
|
||||
const src = '{% assign 4-3 = 5 %}{{ 4-3 }}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('5')
|
||||
return expect(html).toBe('5')
|
||||
})
|
||||
it('should not assign -6', async function () {
|
||||
const src = '{% assign -6 = 5 %}{{ -6 }}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('-6')
|
||||
return expect(html).toBe('-6')
|
||||
})
|
||||
it('should allow reassignment', async function () {
|
||||
const src = '{% assign var = 1 %}{% assign var = 2 %}{{ var }}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('2')
|
||||
return expect(html).toBe('2')
|
||||
})
|
||||
describe('scope', function () {
|
||||
it('should read from parent scope', async function () {
|
||||
const src = '{%for a in (1..2)%}{{num}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, { num: 1 })
|
||||
return expect(html).to.equal('11')
|
||||
return expect(html).toBe('11')
|
||||
})
|
||||
it('should write to the root scope', async function () {
|
||||
const src = '{%for a in (1..2)%}{%assign num = a%}{{a}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, { num: 1 })
|
||||
return expect(html).to.equal('12')
|
||||
return expect(html).toBe('12')
|
||||
})
|
||||
it('should not change input scope', async function () {
|
||||
const src = '{%for a in (1..2)%}{%assign num = a%}{{a}}{%endfor%} {{num}}'
|
||||
const ctx = { num: 1 }
|
||||
await liquid.parseAndRender(src, ctx)
|
||||
return expect(ctx.num).to.equal(1)
|
||||
return expect(ctx.num).toBe(1)
|
||||
})
|
||||
})
|
||||
it('should support sync', function () {
|
||||
const src = '{% assign foo="bar" %}{{foo}}'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
return expect(html).to.equal('bar')
|
||||
return expect(html).toBe('bar')
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,4 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/capture', function () {
|
||||
const liquid = new Liquid()
|
||||
@@ -10,37 +6,37 @@ describe('tags/capture', function () {
|
||||
it('should support capture', async function () {
|
||||
const src = '{% capture f %}{{"a" | capitalize}}{%endcapture%}{{f}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('A')
|
||||
return expect(html).toBe('A')
|
||||
})
|
||||
|
||||
it('should support quoted variable name', async function () {
|
||||
const src = '{% capture "f" %}{{"a" | capitalize}}{%endcapture%}{{f}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('A')
|
||||
return expect(html).toBe('A')
|
||||
})
|
||||
|
||||
it('should not change root scope', async function () {
|
||||
const src = '{% capture var %}10{% endcapture %}{{var}}'
|
||||
const ctx = { 'var': 20 }
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
expect(html).to.equal('10')
|
||||
expect(ctx.var).to.equal(20)
|
||||
expect(html).toBe('10')
|
||||
expect(ctx.var).toBe(20)
|
||||
})
|
||||
|
||||
it('should throw on invalid identifier', function () {
|
||||
const src = '{% capture = %}{%endcapture%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/= not valid identifier/)
|
||||
.rejects.toThrow(/= not valid identifier/)
|
||||
})
|
||||
|
||||
it('should throw when capture not closed', function () {
|
||||
const src = '{%capture c%}{{c}}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/tag .* not closed/)
|
||||
.rejects.toThrow(/tag .* not closed/)
|
||||
})
|
||||
it('should support sync', function () {
|
||||
const src = '{% capture f %}{{"a" | capitalize}}{%endcapture%}{{f}}'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
return expect(html).to.equal('A')
|
||||
return expect(html).toBe('A')
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,4 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/case', function () {
|
||||
const liquid = new Liquid()
|
||||
@@ -10,43 +6,43 @@ describe('tags/case', function () {
|
||||
it('should reject if not closed', function () {
|
||||
const src = '{% case "foo"%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/{% case "foo"%} not closed/)
|
||||
.rejects.toThrow(/{% case "foo"%} not closed/)
|
||||
})
|
||||
it('should hit the specified case', async function () {
|
||||
const src = '{% case "foo"%}' +
|
||||
'{% when "foo" %}foo{% when "bar"%}bar' +
|
||||
'{%endcase%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('foo')
|
||||
return expect(html).toBe('foo')
|
||||
})
|
||||
it('should resolve blank as empty string', async function () {
|
||||
const src = '{% case blank %}{% when ""%}bar{%endcase%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('bar')
|
||||
return expect(html).toBe('bar')
|
||||
})
|
||||
it('should resolve empty as empty string', async function () {
|
||||
const src = '{% case empty %}{% when ""%}bar{%endcase%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('bar')
|
||||
return expect(html).toBe('bar')
|
||||
})
|
||||
it('should accept empty string as branch name', async function () {
|
||||
const src = '{% case "" %}{% when ""%}bar{%endcase%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('bar')
|
||||
return expect(html).toBe('bar')
|
||||
})
|
||||
it('should support boolean case', async function () {
|
||||
const src = '{% case false %}' +
|
||||
'{% when "foo" %}foo{% when false%}bar' +
|
||||
'{%endcase%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('bar')
|
||||
return expect(html).toBe('bar')
|
||||
})
|
||||
it('should support else branch', async function () {
|
||||
const src = '{% case "a" %}' +
|
||||
'{% when "b" %}b{% when "c"%}c{%else %}d' +
|
||||
'{%endcase%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('d')
|
||||
return expect(html).toBe('d')
|
||||
})
|
||||
describe('sync support', function () {
|
||||
it('should hit the specified case', function () {
|
||||
@@ -54,14 +50,14 @@ describe('tags/case', function () {
|
||||
'{% when "foo" %}foo{% when "bar"%}bar' +
|
||||
'{%endcase%}'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
return expect(html).to.equal('foo')
|
||||
return expect(html).toBe('foo')
|
||||
})
|
||||
it('should support else branch', function () {
|
||||
const src = '{% case "a" %}' +
|
||||
'{% when "b" %}b{% when "c"%}c{%else %}d' +
|
||||
'{%endcase%}'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
return expect(html).to.equal('d')
|
||||
return expect(html).toBe('d')
|
||||
})
|
||||
})
|
||||
it('should support case with multiple values', async function () {
|
||||
@@ -69,7 +65,7 @@ describe('tags/case', function () {
|
||||
'{% when "a", "b" %}foo' +
|
||||
'{%endcase%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('foo')
|
||||
return expect(html).toBe('foo')
|
||||
})
|
||||
it('should render multiple matching branches', async function () {
|
||||
const src = '{% case "b" %}' +
|
||||
@@ -77,6 +73,6 @@ describe('tags/case', function () {
|
||||
'{% when "b" %}second' +
|
||||
'{%endcase%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('firstsecond')
|
||||
return expect(html).toBe('firstsecond')
|
||||
})
|
||||
})
|
||||
@@ -1,41 +1,37 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/comment', function () {
|
||||
const liquid = new Liquid()
|
||||
it('should support empty content', function () {
|
||||
const src = '{% comment %}{% raw%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/{% comment %} not closed/)
|
||||
.rejects.toThrow(/{% comment %} not closed/)
|
||||
})
|
||||
it('should ignore plain string', async function () {
|
||||
const src = 'My name is {% comment %}super{% endcomment %} Shopify.'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('My name is Shopify.')
|
||||
return expect(html).toBe('My name is Shopify.')
|
||||
})
|
||||
it('should ignore output tokens', async function () {
|
||||
const src = '{% comment %}\n{{ foo}} \n{% endcomment %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
it('should ignore tag tokens', async function () {
|
||||
const src = '{% comment %}{%if true%}true{%else%}false{%endif%}{% endcomment %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
it('should ignore un-balenced tag tokens', async function () {
|
||||
const src = '{% comment %}{%if true%}true{%else%}false{% endcomment %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
describe('sync support', function () {
|
||||
it('should ignore plain string', function () {
|
||||
const src = 'My name is {% comment %}super{% endcomment %} Shopify.'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
return expect(html).to.equal('My name is Shopify.')
|
||||
return expect(html).toBe('My name is Shopify.')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,4 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/cycle', function () {
|
||||
const liquid = new Liquid()
|
||||
@@ -10,12 +6,12 @@ describe('tags/cycle', function () {
|
||||
it('should support cycle', async function () {
|
||||
const src = "{% cycle '1', '2', '3' %}"
|
||||
const html = await liquid.parseAndRender(src + src + src + src)
|
||||
return expect(html).to.equal('1231')
|
||||
return expect(html).toBe('1231')
|
||||
})
|
||||
|
||||
it('should throw when cycle candidates empty', function () {
|
||||
return expect(liquid.parseAndRender('{%cycle%}'))
|
||||
.to.be.rejectedWith(/empty candidates/)
|
||||
.rejects.toThrow(/empty candidates/)
|
||||
})
|
||||
|
||||
it('should support cycle in for block', async function () {
|
||||
@@ -24,7 +20,7 @@ describe('tags/cycle', function () {
|
||||
one: 1
|
||||
}
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('1e1e1')
|
||||
return expect(html).toBe('1e1e1')
|
||||
})
|
||||
|
||||
it('should considered different groups for different arguments', async function () {
|
||||
@@ -32,7 +28,7 @@ describe('tags/cycle', function () {
|
||||
"{% cycle '1', '2'%}" +
|
||||
"{% cycle '1', '2', '3'%}"
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('112')
|
||||
return expect(html).toBe('112')
|
||||
})
|
||||
|
||||
it('should support cycle group', async function () {
|
||||
@@ -41,11 +37,11 @@ describe('tags/cycle', function () {
|
||||
"{% cycle 2: '1', '2', '3'%}"
|
||||
const ctx = { one: 1 }
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('121')
|
||||
return expect(html).toBe('121')
|
||||
})
|
||||
it('should support sync', function () {
|
||||
const src = "{% cycle '1', '2', '3' %}"
|
||||
const html = liquid.parseAndRenderSync(src + src + src + src)
|
||||
return expect(html).to.equal('1231')
|
||||
return expect(html).toBe('1231')
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,4 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/decrement', function () {
|
||||
const liquid = new Liquid()
|
||||
@@ -10,44 +6,44 @@ describe('tags/decrement', function () {
|
||||
it('should decrement undefined variable', async function () {
|
||||
const src = '{% decrement var %}{% decrement var %}{% decrement var %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('-1-2-3')
|
||||
return expect(html).toBe('-1-2-3')
|
||||
})
|
||||
|
||||
it('should decrement defined variable', async function () {
|
||||
const src = '{% decrement var %}{% decrement var %}{% decrement var %}'
|
||||
const ctx = { 'var': 10 }
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
expect(html).to.equal('987')
|
||||
expect(ctx.var).to.equal(7)
|
||||
expect(html).toBe('987')
|
||||
expect(ctx.var).toBe(7)
|
||||
})
|
||||
|
||||
it('should be independent from assign', async function () {
|
||||
const src = '{% assign var=10 %}{% decrement var %}{% decrement var %}{% decrement var %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('-1-2-3')
|
||||
return expect(html).toBe('-1-2-3')
|
||||
})
|
||||
|
||||
it('should be independent from capture', async function () {
|
||||
const src = '{% capture var %}10{% endcapture %}{% decrement var %}{% decrement var %}{% decrement var %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('-1-2-3')
|
||||
return expect(html).toBe('-1-2-3')
|
||||
})
|
||||
|
||||
it('should not shading assign', async function () {
|
||||
const src = '{% assign var=10 %}{% decrement var %}{% decrement var %}{% decrement var %} {{var}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('-1-2-3 10')
|
||||
return expect(html).toBe('-1-2-3 10')
|
||||
})
|
||||
|
||||
it('should not shading capture', async function () {
|
||||
const src = '{% capture var %}10{% endcapture %}{% decrement var %}{% decrement var %}{% decrement var %} {{var}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('-1-2-3 10')
|
||||
return expect(html).toBe('-1-2-3 10')
|
||||
})
|
||||
|
||||
it('should share the same variable with increment', async function () {
|
||||
const src = '{%increment var%}{%increment var%}{%decrement var%}{%decrement var%}{%increment var%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('01100')
|
||||
return expect(html).toBe('01100')
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,4 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/echo', function () {
|
||||
const liquid = new Liquid()
|
||||
@@ -10,25 +6,25 @@ describe('tags/echo', function () {
|
||||
it('should output literals', async function () {
|
||||
const src = '{% echo 1 %} {% echo "1" %} {% echo 1.1 %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('1 1 1.1')
|
||||
return expect(html).toBe('1 1 1.1')
|
||||
})
|
||||
|
||||
it('should output variables', async function () {
|
||||
const src = '{% echo people.users[0].name %}'
|
||||
const html = await liquid.parseAndRender(src, { people: { users: [ { name: 'Sally' } ] } })
|
||||
return expect(html).to.equal('Sally')
|
||||
return expect(html).toBe('Sally')
|
||||
})
|
||||
|
||||
it('should apply filters before output', async function () {
|
||||
const src = '{% echo user.name | upcase | prepend: "Hello, " | append: "!" %}'
|
||||
const html = await liquid.parseAndRender(src, { user: { name: 'Sally' } })
|
||||
return expect(html).to.equal('Hello, SALLY!')
|
||||
return expect(html).toBe('Hello, SALLY!')
|
||||
})
|
||||
|
||||
it('should handle empty tag', async function () {
|
||||
const src = '{% echo %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
|
||||
it('should handle extra whitespace', async function () {
|
||||
@@ -38,6 +34,6 @@ describe('tags/echo', function () {
|
||||
"Hello, " | append: "!"
|
||||
%}`
|
||||
const html = await liquid.parseAndRender(src, { user: { name: 'Sally' } })
|
||||
return expect(html).to.equal('Hello, SALLY!')
|
||||
return expect(html).toBe('Hello, SALLY!')
|
||||
})
|
||||
})
|
||||
@@ -1,14 +1,10 @@
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { Drop } from '../../../src/drop/drop'
|
||||
import { Scope } from '../../../src/context/scope'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/for', function () {
|
||||
let liquid: Liquid, scope: Scope
|
||||
before(function () {
|
||||
beforeEach(function () {
|
||||
liquid = new Liquid()
|
||||
liquid.registerTag('throwingTag', {
|
||||
render: function () { throw new Error('intended render error') }
|
||||
@@ -29,57 +25,57 @@ describe('tags/for', function () {
|
||||
it('should support array', async function () {
|
||||
const src = '{%for c in alpha%}{{c}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('abc')
|
||||
return expect(html).toBe('abc')
|
||||
})
|
||||
|
||||
it('should support promise of array', async function () {
|
||||
const src = '{%for c in promiseArray%}{{c}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('abc')
|
||||
return expect(html).toBe('abc')
|
||||
})
|
||||
|
||||
it('should support object', async function () {
|
||||
const src = '{%for item in obj%}{{item[0]}},{{item[1]}}-{%else%}b{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('foo,bar-coo,haa-')
|
||||
return expect(html).toBe('foo,bar-coo,haa-')
|
||||
})
|
||||
it('should output forloop', async function () {
|
||||
const src = '{%for i in (1..1)%}{{forloop}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('{"i":0,"length":1,"name":"i-(1..1)"}')
|
||||
return expect(html).toBe('{"i":0,"length":1,"name":"i-(1..1)"}')
|
||||
})
|
||||
it('should output forloop collection name', async function () {
|
||||
const src = '{%for c in alpha%}{{forloop.name}}-{{c}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('c-alpha-ac-alpha-bc-alpha-c')
|
||||
return expect(html).toBe('c-alpha-ac-alpha-bc-alpha-c')
|
||||
})
|
||||
it('should output forloop property accessor name', async function () {
|
||||
const src = '{%for c in obj.foo%}{{forloop.name}}-{{c}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('c-obj.foo-bar')
|
||||
return expect(html).toBe('c-obj.foo-bar')
|
||||
})
|
||||
it('should output forloop quoted name', async function () {
|
||||
const src = '{%for str in "string"%}{{forloop.name}}-{{str}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('str-"string"-string')
|
||||
return expect(html).toBe('str-"string"-string')
|
||||
})
|
||||
describe('illegal', function () {
|
||||
it('should reject when for not closed', function () {
|
||||
const src = '{%for c in alpha%}{{c}}'
|
||||
return expect(liquid.parseAndRender(src, scope))
|
||||
.to.be.rejectedWith(/tag .* not closed/)
|
||||
.rejects.toThrow(/tag .* not closed/)
|
||||
})
|
||||
|
||||
it('should reject when for in not found', function () {
|
||||
const src = '{%for c alpha%}{{c}}'
|
||||
return expect(liquid.parseAndRender(src, scope))
|
||||
.to.be.rejectedWith('illegal tag: {%for c alpha%}, line:1, col:1')
|
||||
.rejects.toThrow('illegal tag: {%for c alpha%}, line:1, col:1')
|
||||
})
|
||||
|
||||
it('should reject when inner templates rejected', function () {
|
||||
const src = '{%for c in alpha%}{%throwingTag%}{%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, scope))
|
||||
.to.be.rejectedWith(/intended render error/)
|
||||
.rejects.toThrow(/intended render error/)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -87,38 +83,38 @@ describe('tags/for', function () {
|
||||
it('should goto else for empty array', async function () {
|
||||
const src = '{%for c in emptyArray%}a{%else%}b{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('b')
|
||||
return expect(html).toBe('b')
|
||||
})
|
||||
|
||||
it('should treat non-empty string as one single element', async function () {
|
||||
const src = '{%for c in "abc"%}x{{c}}{%else%}y{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('xabc')
|
||||
return expect(html).toBe('xabc')
|
||||
})
|
||||
|
||||
it('should goto else for empty string', async function () {
|
||||
const src = '{%for c in ""%}a{%else%}b{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('b')
|
||||
return expect(html).toBe('b')
|
||||
})
|
||||
|
||||
it('should goto else for empty string object', async function () {
|
||||
// it should be false although `new String` is none-conform
|
||||
const src = '{%for c in strObj%}a{%else%}b{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('b')
|
||||
return expect(html).toBe('b')
|
||||
})
|
||||
|
||||
it('should goto else for empty object', async function () {
|
||||
const src = '{%for c in emptyObj%}a{%else%}b{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('b')
|
||||
return expect(html).toBe('b')
|
||||
})
|
||||
|
||||
it('should goto else for null-prototyped object', async function () {
|
||||
const src = '{%for c in nullProtoObj%}a{%else%}b{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('b')
|
||||
return expect(html).toBe('b')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -133,7 +129,7 @@ describe('tags/for', function () {
|
||||
'false.2.1.false.3.2.1b\n' +
|
||||
'false.3.2.true.3.1.0c\n'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
describe('continue', function () {
|
||||
@@ -142,7 +138,7 @@ describe('tags/for', function () {
|
||||
'{% if i == 4 %}continue{% continue %}{% endif %}{{i}}' +
|
||||
'{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('123continue5')
|
||||
return expect(html).toBe('123continue5')
|
||||
})
|
||||
it('should output contents before continue', async function () {
|
||||
const src = '{% for i in (1..5) %}' +
|
||||
@@ -150,7 +146,7 @@ describe('tags/for', function () {
|
||||
'{{ i }}' +
|
||||
'{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('123continue5')
|
||||
return expect(html).toBe('123continue5')
|
||||
})
|
||||
})
|
||||
describe('break', function () {
|
||||
@@ -160,7 +156,7 @@ describe('tags/for', function () {
|
||||
'{{ i }}' +
|
||||
'{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('123')
|
||||
return expect(html).toBe('123')
|
||||
})
|
||||
it('should output contents before break', async function () {
|
||||
const src = '{% for i in (1..5) %}' +
|
||||
@@ -168,7 +164,7 @@ describe('tags/for', function () {
|
||||
'{{ i }}' +
|
||||
'{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('123breaking')
|
||||
return expect(html).toBe('123breaking')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -176,22 +172,22 @@ describe('tags/for', function () {
|
||||
it('should support for with limit', async function () {
|
||||
const src = '{% for i in (1..5) limit:2 %}{{ i }}{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('12')
|
||||
return expect(html).toBe('12')
|
||||
})
|
||||
it('should set forloop.last properly', async function () {
|
||||
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.last}} {%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('false true ')
|
||||
return expect(html).toBe('false true ')
|
||||
})
|
||||
it('should set forloop.first properly', async function () {
|
||||
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.first}} {%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('true false ')
|
||||
return expect(html).toBe('true false ')
|
||||
})
|
||||
it('should set forloop.length properly', function () {
|
||||
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.length}} {%endfor%}'
|
||||
return expect(liquid.parseAndRender(src, scope))
|
||||
.to.eventually.equal('2 2 ')
|
||||
.resolves.toBe('2 2 ')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -199,48 +195,48 @@ describe('tags/for', function () {
|
||||
it('should support offset with limit', async function () {
|
||||
const src = '{% for i in (1..10) limit:2 offset:5%}{{ i }}{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('67')
|
||||
return expect(html).toBe('67')
|
||||
})
|
||||
it('should set index properly', async function () {
|
||||
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.index}} {%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('1 2 ')
|
||||
return expect(html).toBe('1 2 ')
|
||||
})
|
||||
it('should set index0 properly', async function () {
|
||||
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.index0}} {%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('0 1 ')
|
||||
return expect(html).toBe('0 1 ')
|
||||
})
|
||||
it('should set rindex properly', async function () {
|
||||
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.rindex}} {%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('2 1 ')
|
||||
return expect(html).toBe('2 1 ')
|
||||
})
|
||||
it('should set rindex0 properly', async function () {
|
||||
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.rindex0}} {%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('1 0 ')
|
||||
return expect(html).toBe('1 0 ')
|
||||
})
|
||||
it('should continue from limit-ed loop', async function () {
|
||||
const src = '{%for i in arr limit:2%}{{i}}{%endfor%}-{%for i in arr offset:continue%}{{i}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, { arr: [1, 2, 3, 4, 5] })
|
||||
return expect(html).to.equal('12-345')
|
||||
return expect(html).toBe('12-345')
|
||||
})
|
||||
it('should continue nothing for fully iterated loop', async function () {
|
||||
const src = '{%for i in arr%}{{i}}{%endfor%}-{%for i in arr offset:continue%}{{i}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, { arr: [1, 2, 3, 4, 5] })
|
||||
return expect(html).to.equal('12345-')
|
||||
return expect(html).toBe('12345-')
|
||||
})
|
||||
it('should treat different variable names as different forloop', async function () {
|
||||
const src = '{%for i in (1..5)%}{{i}}{%endfor%}-{%for j in (1..5) offset:continue%}{{j}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, {})
|
||||
return expect(html).to.equal('12345-12345')
|
||||
return expect(html).toBe('12345-12345')
|
||||
})
|
||||
it('should treat different collection names as different forloop', async function () {
|
||||
const src = '{%for i in arr1%}{{i}}{%endfor%}-{%for i in arr2 offset:continue%}{{i}}{%endfor%}'
|
||||
const arr = [1, 2, 3, 4, 5]
|
||||
const html = await liquid.parseAndRender(src, { arr1: arr, arr2: arr })
|
||||
return expect(html).to.equal('12345-12345')
|
||||
return expect(html).toBe('12345-12345')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -248,33 +244,33 @@ describe('tags/for', function () {
|
||||
it('should support for reversed in the last position', async function () {
|
||||
const src = '{% for i in (1..8) limit:2 reversed %}{{ i }}{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('21')
|
||||
return expect(html).toBe('21')
|
||||
})
|
||||
|
||||
it('should support for reversed in the first position', async function () {
|
||||
const src = '{% for i in (1..8) reversed limit:2 %}{{ i }}{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('21')
|
||||
return expect(html).toBe('21')
|
||||
})
|
||||
|
||||
it('should support for reversed in the first position with orderedFilterParameters=true', async function () {
|
||||
const liquid = new Liquid({ orderedFilterParameters: true })
|
||||
const src = '{% for i in (1..8) reversed limit:2 %}{{ i }}{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('87')
|
||||
return expect(html).toBe('87')
|
||||
})
|
||||
|
||||
it('should support for reversed in the middle position', async function () {
|
||||
const src = '{% for i in (1..8) offset:2 reversed limit:3 %}{{ i }}{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('543')
|
||||
return expect(html).toBe('543')
|
||||
})
|
||||
|
||||
it('should support for reversed in the middle position with orderedFilterParameters=true', async function () {
|
||||
const liquid = new Liquid({ orderedFilterParameters: true })
|
||||
const src = '{% for i in (1..8) offset:2 reversed limit:3 %}{{ i }}{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('876')
|
||||
return expect(html).toBe('876')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -282,7 +278,7 @@ describe('tags/for', function () {
|
||||
it('should support sync', function () {
|
||||
const src = '{% for i in (1..5) %}{{i}}{%endfor%}'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
return expect(html).to.equal('12345')
|
||||
return expect(html).toBe('12345')
|
||||
})
|
||||
it('should output contents before break', function () {
|
||||
const src = '{% for i in (1..5) %}' +
|
||||
@@ -290,19 +286,19 @@ describe('tags/for', function () {
|
||||
'{{ i }}' +
|
||||
'{% endfor %}'
|
||||
const html = liquid.parseAndRenderSync(src, scope)
|
||||
return expect(html).to.equal('123breaking')
|
||||
return expect(html).toBe('123breaking')
|
||||
})
|
||||
it('should support for with continue', function () {
|
||||
const src = '{% for i in (1..5) %}' +
|
||||
'{% if i == 4 %}continue{% continue %}{% endif %}{{i}}' +
|
||||
'{% endfor %}'
|
||||
const html = liquid.parseAndRenderSync(src, scope)
|
||||
return expect(html).to.equal('123continue5')
|
||||
return expect(html).toBe('123continue5')
|
||||
})
|
||||
it('should goto else for empty array', async function () {
|
||||
const src = '{%for c in emptyArray%}a{%else%}b{%endfor%}'
|
||||
const html = await liquid.parseAndRenderSync(src, scope)
|
||||
return expect(html).to.equal('b')
|
||||
return expect(html).toBe('b')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -333,37 +329,37 @@ describe('tags/for', function () {
|
||||
it('should loop over iterable objects', function () {
|
||||
const src = '{% for i in someIterable %}{{i}}{%endfor%}'
|
||||
const html = liquid.parseAndRenderSync(src, { someIterable: new MockIterable() })
|
||||
return expect(html).to.equal('abc')
|
||||
return expect(html).toBe('abc')
|
||||
})
|
||||
it('should loop over iterable drops', function () {
|
||||
const src = '{{ someDrop }}: {% for i in someDrop %}{{i}}{%endfor%}'
|
||||
const html = liquid.parseAndRenderSync(src, { someDrop: new MockIterableDrop() })
|
||||
return expect(html).to.equal('MockIterableDrop: abc')
|
||||
return expect(html).toBe('MockIterableDrop: abc')
|
||||
})
|
||||
it('should loop over iterable objects with a limit', function () {
|
||||
const src = '{% for i in someIterable limit:2 %}{{i}}{%endfor%}'
|
||||
const html = liquid.parseAndRenderSync(src, { someIterable: new MockIterable() })
|
||||
return expect(html).to.equal('ab')
|
||||
return expect(html).toBe('ab')
|
||||
})
|
||||
it('should loop over iterable objects with an offset', function () {
|
||||
const src = '{% for i in someIterable offset:1 %}{{i}}{%endfor%}'
|
||||
const html = liquid.parseAndRenderSync(src, { someIterable: new MockIterable() })
|
||||
return expect(html).to.equal('bc')
|
||||
return expect(html).toBe('bc')
|
||||
})
|
||||
it('should loop over iterable objects in reverse', function () {
|
||||
const src = '{% for i in someIterable reversed %}{{i}}{%endfor%}'
|
||||
const html = liquid.parseAndRenderSync(src, { someIterable: new MockIterable() })
|
||||
return expect(html).to.equal('cba')
|
||||
return expect(html).toBe('cba')
|
||||
})
|
||||
it('should go to else for an empty iterable', function () {
|
||||
const src = '{% for i in emptyIterable reversed %}{{i}}{%else%}EMPTY{%endfor%}'
|
||||
const html = liquid.parseAndRenderSync(src, { emptyIterable: new MockEmptyIterable() })
|
||||
return expect(html).to.equal('EMPTY')
|
||||
return expect(html).toBe('EMPTY')
|
||||
})
|
||||
it('should support iterable names', function () {
|
||||
const src = '{% for i in someDrop %}{{forloop.name}} {%else%}EMPTY{%endfor%}'
|
||||
const html = liquid.parseAndRenderSync(src, { someDrop: new MockIterableDrop() })
|
||||
return expect(html).to.equal('i-someDrop i-someDrop i-someDrop ')
|
||||
return expect(html).toBe('i-someDrop i-someDrop i-someDrop ')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,9 +1,4 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import * as chai from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
const expect = chai.expect
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
describe('tags/if', function () {
|
||||
const liquid = new Liquid()
|
||||
@@ -17,67 +12,67 @@ describe('tags/if', function () {
|
||||
it('should throw if not closed', function () {
|
||||
const src = '{% if false%}yes'
|
||||
return expect(liquid.parseAndRender(src, scope))
|
||||
.to.be.rejectedWith(/tag {% if false%} not closed/)
|
||||
.rejects.toThrow(/tag {% if false%} not closed/)
|
||||
})
|
||||
it('should support nested', async function () {
|
||||
const src = '{%if false%}{%if true%}{%else%}a{%endif%}{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
|
||||
describe('single value as condition', function () {
|
||||
it('should support boolean', async function () {
|
||||
const src = '{% if false %}1{%elsif true%}2{%else%}3{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('2')
|
||||
return expect(html).toBe('2')
|
||||
})
|
||||
it('should treat Array truthy', async function () {
|
||||
const src = '{%if emptyArray%}a{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('a')
|
||||
return expect(html).toBe('a')
|
||||
})
|
||||
it('should return true if empty string', async function () {
|
||||
const src = '{%if emptyString%}a{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('a')
|
||||
return expect(html).toBe('a')
|
||||
})
|
||||
})
|
||||
describe('expression as condition', function () {
|
||||
it('should support ==', async function () {
|
||||
const src = '{% if 2 == 3 %}yes{%else%}no{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
it('should support >=', async function () {
|
||||
const src = '{% if 1 >= 2 and one<two %}a{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
it('should support !=', async function () {
|
||||
const src = '{% if one != two %}yes{%else%}no{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('yes')
|
||||
return expect(html).toBe('yes')
|
||||
})
|
||||
it('should support value and expression', async function () {
|
||||
const src = `X{%if version and version != '' %}x{{version}}y{%endif%}Y`
|
||||
const scope = { 'version': '' }
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('XY')
|
||||
return expect(html).toBe('XY')
|
||||
})
|
||||
it('should evaluate right to left', async function () {
|
||||
const src = `{% if false and false or true %}true{%endif%}`
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
it('should allow no spaces around operator for literal', async function () {
|
||||
const src = `{% if true==true %}success{%else%}fail{% endif %}`
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('success')
|
||||
return expect(html).toBe('success')
|
||||
})
|
||||
it('should allow no spaces around operator for variables', async function () {
|
||||
const src = `{%assign var = 1%}{%if var ==1%}success{%else%}fail{%endif%}`
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('success')
|
||||
return expect(html).toBe('success')
|
||||
})
|
||||
})
|
||||
describe('filters as condition', function () {
|
||||
@@ -85,67 +80,67 @@ describe('tags/if', function () {
|
||||
liquid.registerFilter('negate', (val) => !val)
|
||||
const src = '{% if 2 == 3 | negate %}yes{%else%}no{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('yes')
|
||||
return expect(html).toBe('yes')
|
||||
})
|
||||
})
|
||||
describe('compare to null', function () {
|
||||
it('should evaluate false for null < 10', async function () {
|
||||
const src = '{% if null < 10 %}yes{% else %}no{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for null > 10', async function () {
|
||||
const src = '{% if null > 10 %}yes{% else %}no{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for null <= 10', async function () {
|
||||
const src = '{% if null <= 10 %}yes{% else %}no{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for null >= 10', async function () {
|
||||
const src = '{% if null >= 10 %}yes{% else %}no{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for 10 < null', async function () {
|
||||
const src = '{% if 10 < null %}yes{% else %}no{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for 10 > null', async function () {
|
||||
const src = '{% if 10 > null %}yes{% else %}no{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for 10 <= null', async function () {
|
||||
const src = '{% if 10 <= null %}yes{% else %}no{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
|
||||
it('should evaluate false for 10 >= null', async function () {
|
||||
const src = '{% if 10 >= null %}yes{% else %}no{% endif %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
})
|
||||
it('should support sync', function () {
|
||||
const src = '{%if true%}true{%else%}false{%endif%}'
|
||||
const html = liquid.parseAndRenderSync(src, scope)
|
||||
return expect(html).to.equal('true')
|
||||
return expect(html).toBe('true')
|
||||
})
|
||||
it('should support async variables', async () => {
|
||||
const src = `{%if var == 'var' %}success{%endif%}`
|
||||
const scope = { 'var': Promise.resolve('var') }
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('success')
|
||||
return expect(html).toBe('success')
|
||||
})
|
||||
})
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { Drop } from '../../../src/drop/drop'
|
||||
import { expect } from 'chai'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
|
||||
describe('tags/include', function () {
|
||||
let liquid: Liquid
|
||||
before(function () {
|
||||
beforeEach(function () {
|
||||
liquid = new Liquid({
|
||||
root: '/',
|
||||
extname: '.html'
|
||||
@@ -18,7 +17,7 @@ describe('tags/include', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = await liquid.renderFile('/current.html')
|
||||
return expect(html).to.equal('barfoobar')
|
||||
return expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should support relative reference', async function () {
|
||||
mock({
|
||||
@@ -26,7 +25,7 @@ describe('tags/include', function () {
|
||||
'/foo/coo/foo.html': 'foo'
|
||||
})
|
||||
const html = await liquid.renderFile('/foo/bar/current.html')
|
||||
return expect(html).to.equal('barfoobar')
|
||||
return expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should support template string', async function () {
|
||||
mock({
|
||||
@@ -34,7 +33,7 @@ describe('tags/include', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = await liquid.renderFile('/current.html', { name: 'foo.html' })
|
||||
return expect(html).to.equal('barfoobar')
|
||||
return expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should allow escape in template string', async function () {
|
||||
mock({
|
||||
@@ -42,7 +41,7 @@ describe('tags/include', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = await liquid.renderFile('/current.html', { name: 'foo' })
|
||||
return expect(html).to.equal('barfoobar')
|
||||
return expect(html).toBe('barfoobar')
|
||||
})
|
||||
|
||||
it('should throw when not specified', function () {
|
||||
@@ -50,8 +49,8 @@ describe('tags/include', function () {
|
||||
'/parent.html': '{%include , %}'
|
||||
})
|
||||
return liquid.renderFile('/parent.html').catch(function (e) {
|
||||
expect(e.name).to.equal('ParseError')
|
||||
expect(e.message).to.match(/illegal argument ","/)
|
||||
expect(e.name).toBe('ParseError')
|
||||
expect(e.message).toMatch(/illegal argument ","/)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -60,8 +59,8 @@ describe('tags/include', function () {
|
||||
'/parent.html': '{%include not-exist%}'
|
||||
})
|
||||
return liquid.renderFile('/parent.html').catch(function (e) {
|
||||
expect(e.name).to.equal('RenderError')
|
||||
expect(e.message).to.match(/illegal filename "undefined"/)
|
||||
expect(e.name).toBe('RenderError')
|
||||
expect(e.message).toMatch(/illegal filename "undefined"/)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -71,7 +70,7 @@ describe('tags/include', function () {
|
||||
'/foo/relative.html': 'bar{% include "../bar/foo.html" %}bar'
|
||||
})
|
||||
const html = await liquid.renderFile('foo/relative.html')
|
||||
return expect(html).to.equal('barfoobar')
|
||||
return expect(html).toBe('barfoobar')
|
||||
})
|
||||
|
||||
it('should support include: hash list', async function () {
|
||||
@@ -80,7 +79,7 @@ describe('tags/include', function () {
|
||||
'/user.html': '{{name}} : {{role}} : {{alias}}'
|
||||
})
|
||||
const html = await liquid.renderFile('hash.html')
|
||||
return expect(html).to.equal('harttle : admin : harttle')
|
||||
return expect(html).toBe('harttle : admin : harttle')
|
||||
})
|
||||
|
||||
it('should support include: parent scope', async function () {
|
||||
@@ -89,7 +88,7 @@ describe('tags/include', function () {
|
||||
'/color.html': 'color:{{color}}, shape:{{shape}}'
|
||||
})
|
||||
const html = await liquid.renderFile('scope.html')
|
||||
return expect(html).to.equal('color:yellow, shape:triangle')
|
||||
return expect(html).toBe('color:yellow, shape:triangle')
|
||||
})
|
||||
|
||||
it('should support include: with', async function () {
|
||||
@@ -98,7 +97,7 @@ describe('tags/include', function () {
|
||||
'/color.html': 'color:{{color}}, shape:{{shape}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html')
|
||||
return expect(html).to.equal('color:red, shape:rect')
|
||||
return expect(html).toBe('color:red, shape:rect')
|
||||
})
|
||||
it('should ignore if with value not specified', async function () {
|
||||
mock({
|
||||
@@ -106,7 +105,7 @@ describe('tags/include', function () {
|
||||
'/color.html': 'color:{{color}}, shape:{{shape}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html')
|
||||
return expect(html).to.equal('color:, shape:rect')
|
||||
return expect(html).toBe('color:, shape:rect')
|
||||
})
|
||||
it('should treat with as a valid key', async function () {
|
||||
mock({
|
||||
@@ -114,7 +113,7 @@ describe('tags/include', function () {
|
||||
'/color.html': 'with:{{with}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html')
|
||||
return expect(html).to.equal('with:foo')
|
||||
return expect(html).toBe('with:foo')
|
||||
})
|
||||
it('should support include: with as Drop', async function () {
|
||||
class ColorDrop extends Drop {
|
||||
@@ -127,7 +126,7 @@ describe('tags/include', function () {
|
||||
'/color.html': 'color:{{color}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html', { color: new ColorDrop() })
|
||||
expect(html).to.equal('color:red!')
|
||||
expect(html).toBe('color:red!')
|
||||
})
|
||||
it('should support include: with passed as Drop', async function () {
|
||||
class ColorDrop extends Drop {
|
||||
@@ -141,7 +140,7 @@ describe('tags/include', function () {
|
||||
'/color.html': '{{color | name}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html', { color: new ColorDrop() })
|
||||
expect(html).to.equal('ColorDrop')
|
||||
expect(html).toBe('ColorDrop')
|
||||
})
|
||||
|
||||
it('should support nested includes', async function () {
|
||||
@@ -160,7 +159,7 @@ describe('tags/include', function () {
|
||||
}
|
||||
}
|
||||
const html = await liquid.renderFile('personInfo.html', ctx)
|
||||
return expect(html).to.equal('This is a person <p>Joe Shmoe<br/>City: Dallas</p>')
|
||||
return expect(html).toBe('This is a person <p>Joe Shmoe<br/>City: Dallas</p>')
|
||||
})
|
||||
|
||||
describe('static partial', function () {
|
||||
@@ -171,7 +170,7 @@ describe('tags/include', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
|
||||
const html = await staticLiquid.renderFile('parent.html')
|
||||
return expect(html).to.equal('Xchild with redY')
|
||||
return expect(html).toBe('Xchild with redY')
|
||||
})
|
||||
|
||||
it('should support parent paths', async function () {
|
||||
@@ -181,7 +180,7 @@ describe('tags/include', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
|
||||
const html = await staticLiquid.renderFile('parent.html')
|
||||
return expect(html).to.equal('XchildY')
|
||||
return expect(html).toBe('XchildY')
|
||||
})
|
||||
|
||||
it('should support subpaths', async function () {
|
||||
@@ -191,7 +190,7 @@ describe('tags/include', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
|
||||
const html = await staticLiquid.renderFile('parent.html')
|
||||
return expect(html).to.equal('XchildY')
|
||||
return expect(html).toBe('XchildY')
|
||||
})
|
||||
|
||||
it('should support comma separated arguments', async function () {
|
||||
@@ -201,7 +200,7 @@ describe('tags/include', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
|
||||
const html = await staticLiquid.renderFile('parent.html')
|
||||
return expect(html).to.equal('Xchild with redY')
|
||||
return expect(html).toBe('Xchild with redY')
|
||||
})
|
||||
|
||||
it('should support single liquid output', async function () {
|
||||
@@ -211,7 +210,7 @@ describe('tags/include', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
|
||||
const html = await staticLiquid.renderFile('parent.html', { child: 'child.html' })
|
||||
return expect(html).to.equal('Xchild with redY')
|
||||
return expect(html).toBe('Xchild with redY')
|
||||
})
|
||||
})
|
||||
describe('sync support', function () {
|
||||
@@ -221,7 +220,7 @@ describe('tags/include', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = liquid.renderFileSync('/current.html')
|
||||
return expect(html).to.equal('barfoobar')
|
||||
return expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should support variable', function () {
|
||||
mock({
|
||||
@@ -229,7 +228,7 @@ describe('tags/include', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = liquid.renderFileSync('/current.html', { name: '/bar/foo.html' })
|
||||
return expect(html).to.equal('barfoobar')
|
||||
return expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should support include: with', function () {
|
||||
mock({
|
||||
@@ -237,7 +236,7 @@ describe('tags/include', function () {
|
||||
'/color.html': 'color:{{color}}, shape:{{shape}}'
|
||||
})
|
||||
const html = liquid.renderFileSync('with.html')
|
||||
return expect(html).to.equal('color:red, shape:rect')
|
||||
return expect(html).toBe('color:red, shape:rect')
|
||||
})
|
||||
it('should support filename with extension', function () {
|
||||
mock({
|
||||
@@ -246,12 +245,12 @@ describe('tags/include', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
|
||||
const html = staticLiquid.renderFileSync('parent.html')
|
||||
return expect(html).to.equal('Xchild with redY')
|
||||
return expect(html).toBe('Xchild with redY')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Jekyll include', function () {
|
||||
before(function () {
|
||||
beforeEach(function () {
|
||||
liquid = new Liquid({
|
||||
root: '/',
|
||||
extname: '.html',
|
||||
@@ -264,7 +263,7 @@ describe('tags/include', function () {
|
||||
'/bar/foo.html': '{{include.content}}-{{content}}'
|
||||
})
|
||||
const html = liquid.renderFileSync('/current.html')
|
||||
return expect(html).to.equal('FOO-')
|
||||
return expect(html).toBe('FOO-')
|
||||
})
|
||||
it('should support multiple parameters', function () {
|
||||
mock({
|
||||
@@ -272,7 +271,7 @@ describe('tags/include', function () {
|
||||
'/bar/foo.html': '<h2>{{include.header}}</h2>{{include.content}}'
|
||||
})
|
||||
const html = liquid.renderFileSync('/current.html')
|
||||
return expect(html).to.equal('<h2>HEADER</h2>CONTENT')
|
||||
return expect(html).toBe('<h2>HEADER</h2>CONTENT')
|
||||
})
|
||||
it('should support dynamicPartials=true', function () {
|
||||
mock({
|
||||
@@ -286,7 +285,7 @@ describe('tags/include', function () {
|
||||
dynamicPartials: true
|
||||
})
|
||||
const html = liquid.renderFileSync('/current.html')
|
||||
return expect(html).to.equal('FOO-')
|
||||
return expect(html).toBe('FOO-')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,4 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/increment', function () {
|
||||
const liquid = new Liquid()
|
||||
@@ -10,38 +6,38 @@ describe('tags/increment', function () {
|
||||
it('should increment undefined variable', async function () {
|
||||
const src = '{% increment one %}{% increment one %}{% increment one %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('012')
|
||||
return expect(html).toBe('012')
|
||||
})
|
||||
|
||||
it('should increment defined variable', async function () {
|
||||
const src = '{% increment one %}{% increment one %}{% increment one %}'
|
||||
const ctx = { one: 7 }
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
expect(html).to.equal('789')
|
||||
expect(ctx.one).to.equal(10)
|
||||
expect(html).toBe('789')
|
||||
expect(ctx.one).toBe(10)
|
||||
})
|
||||
|
||||
it('should be independent from assign', async function () {
|
||||
const src = '{% assign var=10 %}{% increment var %}{% increment var %}{% increment var %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('012')
|
||||
return expect(html).toBe('012')
|
||||
})
|
||||
|
||||
it('should be independent from capture', async function () {
|
||||
const src = '{% capture var %}10{% endcapture %}{% increment var %}{% increment var %}{% increment var %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('012')
|
||||
return expect(html).toBe('012')
|
||||
})
|
||||
|
||||
it('should not shading assign', async function () {
|
||||
const src = '{% assign var=10 %}{% increment var %}{% increment var %}{% increment var %} {{var}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('012 10')
|
||||
return expect(html).toBe('012 10')
|
||||
})
|
||||
|
||||
it('should not hide capture', async function () {
|
||||
const src = '{% capture var %}10{% endcapture %}{% increment var %}{% increment var %}{% increment var %} {{var}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('012 10')
|
||||
return expect(html).toBe('012 10')
|
||||
})
|
||||
})
|
||||
+11
-15
@@ -1,40 +1,36 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/inline-comment', function () {
|
||||
const liquid = new Liquid()
|
||||
it('should ignore plain string', async function () {
|
||||
const src = 'My name is {% # super %} Shopify.'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('My name is Shopify.')
|
||||
return expect(html).toBe('My name is Shopify.')
|
||||
})
|
||||
it('should ignore output tokens', async function () {
|
||||
const src = '{% #\n{{ foo}} \n %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
it('should support whitespace control', async function () {
|
||||
const src = '{%- # some comment \n -%}\nfoo'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('foo')
|
||||
return expect(html).toBe('foo')
|
||||
})
|
||||
it('should handle hash without trailing whitespace', async function () {
|
||||
const src = '{% #some comment %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
it('should handle hash without leading whitespace', async function () {
|
||||
const src = '{%#some comment %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
it('should handle empty comment', async function () {
|
||||
const src = '{%#%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
it('should support multiple lines', async function () {
|
||||
const src = [
|
||||
@@ -44,7 +40,7 @@ describe('tags/inline-comment', function () {
|
||||
'-%}'
|
||||
].join('\n')
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
it('should enforce leading hashes', async function () {
|
||||
const src = [
|
||||
@@ -54,13 +50,13 @@ describe('tags/inline-comment', function () {
|
||||
'-%}'
|
||||
].join('\n')
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/every line of an inline comment must start with a '#' character/)
|
||||
.rejects.toThrow(/every line of an inline comment must start with a '#' character/)
|
||||
})
|
||||
describe('sync support', function () {
|
||||
it('should ignore plain string', function () {
|
||||
const src = 'My name is {% # super %} Shopify.'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
return expect(html).to.equal('My name is Shopify.')
|
||||
return expect(html).toBe('My name is Shopify.')
|
||||
})
|
||||
})
|
||||
describe('liquid tag', function () {
|
||||
@@ -78,7 +74,7 @@ describe('tags/inline-comment', function () {
|
||||
'-%}'
|
||||
].join('\n')
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('Hello goodbye')
|
||||
return expect(html).toBe('Hello goodbye')
|
||||
})
|
||||
it('should handle lots of hashes', async function () {
|
||||
const src = [
|
||||
@@ -89,7 +85,7 @@ describe('tags/inline-comment', function () {
|
||||
'-%}'
|
||||
].join('\n')
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,13 +1,9 @@
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/layout', function () {
|
||||
let liquid: Liquid
|
||||
before(function () {
|
||||
beforeEach(function () {
|
||||
liquid = new Liquid({
|
||||
root: '/',
|
||||
extname: '.html'
|
||||
@@ -20,16 +16,15 @@ describe('tags/layout', function () {
|
||||
'/parent.html': 'parent'
|
||||
})
|
||||
const src = '{% layout "parent" %}{%block%}A'
|
||||
return expect(liquid.parseAndRender(src)).to
|
||||
.be.rejectedWith(/tag {%block%} not closed/)
|
||||
return expect(liquid.parseAndRender(src)).rejects.toThrow(/tag {%block%} not closed/)
|
||||
})
|
||||
it('should throw when filename not specified', function () {
|
||||
mock({
|
||||
'/parent.html': '{%layout%}'
|
||||
})
|
||||
return liquid.renderFile('/parent.html').catch(function (e) {
|
||||
expect(e.name).to.equal('ParseError')
|
||||
expect(e.message).to.match(/illegal argument ""/)
|
||||
expect(e.name).toBe('ParseError')
|
||||
expect(e.message).toMatch(/illegal argument ""/)
|
||||
})
|
||||
})
|
||||
it('should throw when filename resolved to falsy', function () {
|
||||
@@ -37,8 +32,8 @@ describe('tags/layout', function () {
|
||||
'/parent.html': '{%layout foo%}'
|
||||
})
|
||||
return liquid.renderFile('/parent.html').catch(function (e) {
|
||||
expect(e.name).to.equal('RenderError')
|
||||
expect(e.message).to.contain('illegal filename "undefined"')
|
||||
expect(e.name).toBe('RenderError')
|
||||
expect(e.message).toContain('illegal filename "undefined"')
|
||||
})
|
||||
})
|
||||
it('should handle layout none', async function () {
|
||||
@@ -46,7 +41,7 @@ describe('tags/layout', function () {
|
||||
'{%block a%}A{%endblock%}' +
|
||||
'B'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('AB')
|
||||
return expect(html).toBe('AB')
|
||||
})
|
||||
describe('anonymous block', function () {
|
||||
it('should handle anonymous block', async function () {
|
||||
@@ -55,7 +50,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const src = '{% layout "parent.html" %}{%block%}A{%endblock%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('XAY')
|
||||
return expect(html).toBe('XAY')
|
||||
})
|
||||
it('should handle top level contents as anonymous block', async function () {
|
||||
mock({
|
||||
@@ -63,7 +58,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const src = '{% layout "parent.html" %}A'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('XAY')
|
||||
return expect(html).toBe('XAY')
|
||||
})
|
||||
})
|
||||
it('should handle named blocks', async function () {
|
||||
@@ -74,7 +69,7 @@ describe('tags/layout', function () {
|
||||
'{%block a%}A{%endblock%}' +
|
||||
'{%block b%}B{%endblock%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('XAYBZ')
|
||||
return expect(html).toBe('XAYBZ')
|
||||
})
|
||||
it('should support `options.layouts`', async () => {
|
||||
mock({
|
||||
@@ -83,7 +78,7 @@ describe('tags/layout', function () {
|
||||
const src = '{% layout "parent.html" %}{%block a%}A{%endblock%}'
|
||||
const liquid = new Liquid({ layouts: '/layouts' })
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('XAY')
|
||||
return expect(html).toBe('XAY')
|
||||
})
|
||||
it('should use `layouts` if specified', async function () {
|
||||
mock({
|
||||
@@ -93,7 +88,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ root: '/root', layouts: '/layouts', dynamicPartials: false })
|
||||
const html = await staticLiquid.renderFile('main.html')
|
||||
return expect(html).to.equal('LAYOUTS A')
|
||||
return expect(html).toBe('LAYOUTS A')
|
||||
})
|
||||
|
||||
it('should support block.super', async function () {
|
||||
@@ -104,7 +99,7 @@ describe('tags/layout', function () {
|
||||
'{%block css%}{{block.super}}<link href="extra.css" rel="stylesheet">{%endblock%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
const output = '<link href="base.css" rel="stylesheet"><link href="extra.css" rel="stylesheet">'
|
||||
return expect(html).to.equal(output)
|
||||
return expect(html).toBe(output)
|
||||
})
|
||||
it('should render block.super to empty if no parent exists', async function () {
|
||||
mock({
|
||||
@@ -114,7 +109,7 @@ describe('tags/layout', function () {
|
||||
'{%block css%}{{block.super}}<link href="extra.css" rel="stylesheet">{%endblock%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
const output = '<link href="base.css" rel="stylesheet"><link href="extra.css" rel="stylesheet">'
|
||||
return expect(html).to.equal(output)
|
||||
return expect(html).toBe(output)
|
||||
})
|
||||
it('should support nested block.super', async function () {
|
||||
mock({
|
||||
@@ -124,7 +119,7 @@ describe('tags/layout', function () {
|
||||
const src = '{% layout "parent.html" %}{%block css%}{{block.super}}<link href="extra.css" rel="stylesheet">{%endblock%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
const output = '<link href="root.css" rel="stylesheet"><link href="parent.css" rel="stylesheet"><link href="extra.css" rel="stylesheet">'
|
||||
return expect(html).to.equal(output)
|
||||
return expect(html).toBe(output)
|
||||
})
|
||||
it('should support variable as layout name', async function () {
|
||||
mock({
|
||||
@@ -132,7 +127,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const src = '{% layout parent %}{%block a%}A{%endblock%}'
|
||||
const html = await liquid.parseAndRender(src, { parent: 'parent.html' })
|
||||
return expect(html).to.equal('XAY')
|
||||
return expect(html).toBe('XAY')
|
||||
})
|
||||
it('should support default block content', async function () {
|
||||
mock({
|
||||
@@ -140,7 +135,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const src = '{% layout "parent.html" %}{%block a%}a{%endblock%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('XaYBZ')
|
||||
return expect(html).toBe('XaYBZ')
|
||||
})
|
||||
it('should handle nested block', async function () {
|
||||
mock({
|
||||
@@ -149,7 +144,7 @@ describe('tags/layout', function () {
|
||||
'/main.html': '{%layout "parent"%}{%block a%}A{%endblock%}'
|
||||
})
|
||||
const html = await liquid.renderFile('/main.html')
|
||||
return expect(html).to.equal('XAY')
|
||||
return expect(html).toBe('XAY')
|
||||
})
|
||||
it('should not bleed scope into `include` layout', async function () {
|
||||
mock({
|
||||
@@ -160,7 +155,7 @@ describe('tags/layout', function () {
|
||||
'/included.html': '{%layout "parent"%}{%block a%}a{%endblock%}'
|
||||
})
|
||||
const html = await liquid.renderFile('main')
|
||||
return expect(html).to.equal('XAYIXaYZJZ')
|
||||
return expect(html).toBe('XAYIXaYZJZ')
|
||||
})
|
||||
it('should not bleed scope into `render` layout', async function () {
|
||||
mock({
|
||||
@@ -171,7 +166,7 @@ describe('tags/layout', function () {
|
||||
'/included.html': '{%layout "parent"%}{%block a%}a{%endblock%}'
|
||||
})
|
||||
const html = await liquid.renderFile('main')
|
||||
return expect(html).to.equal('XAYIXaYZJZ')
|
||||
return expect(html).toBe('XAYIXaYZJZ')
|
||||
})
|
||||
it('should support hash list', async function () {
|
||||
mock({
|
||||
@@ -179,7 +174,7 @@ describe('tags/layout', function () {
|
||||
'/main.html': '{% layout "parent.html" color:"black"%}{%block%}A{%endblock%}'
|
||||
})
|
||||
const html = await liquid.renderFile('/main.html')
|
||||
return expect(html).to.equal('blackA')
|
||||
return expect(html).toBe('blackA')
|
||||
})
|
||||
it('should support multiple hash', async function () {
|
||||
mock({
|
||||
@@ -187,7 +182,7 @@ describe('tags/layout', function () {
|
||||
'/main.html': '{% layout "parent.html" color:"black", bg:"red"%}{%block%}A{%endblock%}'
|
||||
})
|
||||
const html = await liquid.renderFile('/main.html')
|
||||
return expect(html).to.equal('blackredA')
|
||||
return expect(html).toBe('blackredA')
|
||||
})
|
||||
|
||||
it('should support relative reference', async function () {
|
||||
@@ -197,7 +192,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ root: '/', dynamicPartials: false })
|
||||
const html = await staticLiquid.renderFile('/foo/bar/main.html')
|
||||
return expect(html).to.equal('blackA')
|
||||
return expect(html).toBe('blackA')
|
||||
})
|
||||
|
||||
it('should support relative root', async function () {
|
||||
@@ -207,7 +202,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ root: './foo', dynamicPartials: false })
|
||||
const html = await staticLiquid.renderFile('bar/main.html')
|
||||
return expect(html).to.equal('blackA')
|
||||
return expect(html).toBe('blackA')
|
||||
})
|
||||
|
||||
describe('static partial', function () {
|
||||
@@ -218,7 +213,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ root: '/', dynamicPartials: false })
|
||||
const html = await staticLiquid.renderFile('/main.html')
|
||||
return expect(html).to.equal('blackA')
|
||||
return expect(html).toBe('blackA')
|
||||
})
|
||||
|
||||
it('should support parent paths', async function () {
|
||||
@@ -228,7 +223,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ root: '/', dynamicPartials: false })
|
||||
const html = await staticLiquid.renderFile('/main.html')
|
||||
return expect(html).to.equal('blackA')
|
||||
return expect(html).toBe('blackA')
|
||||
})
|
||||
|
||||
it('should support none', async function () {
|
||||
@@ -237,7 +232,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ root: '/', dynamicPartials: false })
|
||||
const html = await staticLiquid.renderFile('/main.html')
|
||||
return expect(html).to.equal('foo')
|
||||
return expect(html).toBe('foo')
|
||||
})
|
||||
|
||||
it('should support subpaths', async function () {
|
||||
@@ -247,7 +242,7 @@ describe('tags/layout', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ root: '/', dynamicPartials: false })
|
||||
const html = await staticLiquid.renderFile('/main.html')
|
||||
return expect(html).to.equal('blackA')
|
||||
return expect(html).toBe('blackA')
|
||||
})
|
||||
})
|
||||
it('should support sync', function () {
|
||||
@@ -257,6 +252,6 @@ describe('tags/layout', function () {
|
||||
'/main.html': '{%layout "parent"%}{%block a%}A{%endblock%}'
|
||||
})
|
||||
const html = liquid.renderFileSync('/main.html')
|
||||
return expect(html).to.equal('XAY')
|
||||
return expect(html).toBe('XAY')
|
||||
})
|
||||
})
|
||||
@@ -1,9 +1,5 @@
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/liquid', function () {
|
||||
const liquid = new Liquid()
|
||||
|
||||
@@ -19,7 +15,7 @@ describe('tags/liquid', function () {
|
||||
-%}
|
||||
`
|
||||
const html = await liquid.parseAndRender(src, { array: [1, 2, 3] })
|
||||
return expect(html).to.equal('1#2#3')
|
||||
return expect(html).toBe('1#2#3')
|
||||
})
|
||||
|
||||
it('should support shorthand syntax with assignments and filters', async function () {
|
||||
@@ -38,13 +34,13 @@ describe('tags/liquid', function () {
|
||||
-%}
|
||||
`
|
||||
const html = await liquid.parseAndRender(src, { array: [1, 2, 3] })
|
||||
return expect(html).to.equal('4#8#12#6')
|
||||
return expect(html).toBe('4#8#12#6')
|
||||
})
|
||||
|
||||
it('should handle empty tag', async function () {
|
||||
const src = '{% liquid %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
|
||||
it('should handle lines containing only whitespace', async function () {
|
||||
@@ -56,7 +52,7 @@ describe('tags/liquid', function () {
|
||||
echo 'goodbye'
|
||||
%}`
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('hello goodbye')
|
||||
return expect(html).toBe('hello goodbye')
|
||||
})
|
||||
|
||||
it('should fail with carriage return terminated tags', async function () {
|
||||
@@ -71,6 +67,6 @@ describe('tags/liquid', function () {
|
||||
'-%}'
|
||||
].join('\r')
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/not closed/)
|
||||
.rejects.toThrow(/not closed/)
|
||||
})
|
||||
})
|
||||
@@ -1,30 +1,25 @@
|
||||
import * as chai from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
const expect = chai.expect
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
describe('tags/raw', function () {
|
||||
const liquid = new Liquid()
|
||||
it('should throw when not closed', async function () {
|
||||
const p = liquid.parseAndRender('{% raw %}')
|
||||
return expect(p).be.rejectedWith(/{% raw %} not closed/)
|
||||
return expect(p).rejects.toThrow(/{% raw %} not closed/)
|
||||
})
|
||||
it('should output filters as it is', async function () {
|
||||
const src = '{% raw %}{{ 5 | plus: 6 }}{% endraw %} is equal to 11.'
|
||||
const dst = '{{ 5 | plus: 6 }} is equal to 11.'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
it('should preserve blank characters', async function () {
|
||||
const src = '{% raw %}\n{{ foo}} \n{% endraw %}'
|
||||
const dst = '\n{{ foo}} \n'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
it('should support sync', function () {
|
||||
const html = liquid.parseAndRenderSync('{% raw %}{{foo}}{% endraw %}')
|
||||
return expect(html).to.equal('{{foo}}')
|
||||
return expect(html).toBe('{{foo}}')
|
||||
})
|
||||
})
|
||||
@@ -1,13 +1,10 @@
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { Drop } from '../../../src/drop/drop'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/render', function () {
|
||||
let liquid: Liquid
|
||||
before(function () {
|
||||
beforeEach(function () {
|
||||
liquid = new Liquid({
|
||||
root: '/',
|
||||
extname: '.html'
|
||||
@@ -20,7 +17,7 @@ describe('tags/render', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = await liquid.renderFile('/current.html')
|
||||
expect(html).to.equal('barfoobar')
|
||||
expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should support render', async function () {
|
||||
mock({
|
||||
@@ -29,7 +26,7 @@ describe('tags/render', function () {
|
||||
})
|
||||
const liquid = new Liquid({ partials: '/partials', root: '/' })
|
||||
const html = await liquid.renderFile('/current.html')
|
||||
expect(html).to.equal('barfoobar')
|
||||
expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should support template string', async function () {
|
||||
mock({
|
||||
@@ -37,7 +34,7 @@ describe('tags/render', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = await liquid.renderFile('/current.html', { name: 'foo.html' })
|
||||
expect(html).to.equal('barfoobar')
|
||||
expect(html).toBe('barfoobar')
|
||||
})
|
||||
|
||||
it('should throw when not specified', function () {
|
||||
@@ -45,8 +42,8 @@ describe('tags/render', function () {
|
||||
'/parent.html': '{%render%}'
|
||||
})
|
||||
return liquid.renderFile('/parent.html').catch(function (e) {
|
||||
expect(e.name).to.equal('ParseError')
|
||||
expect(e.message).to.match(/illegal argument ""/)
|
||||
expect(e.name).toBe('ParseError')
|
||||
expect(e.message).toMatch(/illegal argument ""/)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -55,8 +52,8 @@ describe('tags/render', function () {
|
||||
'/parent.html': '{%render not-exist%}'
|
||||
})
|
||||
return liquid.renderFile('/parent.html').catch(function (e) {
|
||||
expect(e.name).to.equal('RenderError')
|
||||
expect(e.message).to.match(/illegal filename "undefined"/)
|
||||
expect(e.name).toBe('RenderError')
|
||||
expect(e.message).toMatch(/illegal filename "undefined"/)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -66,7 +63,7 @@ describe('tags/render', function () {
|
||||
'/foo/relative.html': 'bar{% render "../bar/foo.html" %}bar'
|
||||
})
|
||||
const html = await liquid.renderFile('foo/relative.html')
|
||||
expect(html).to.equal('barfoobar')
|
||||
expect(html).toBe('barfoobar')
|
||||
})
|
||||
|
||||
it('should support render: hash list', async function () {
|
||||
@@ -75,7 +72,7 @@ describe('tags/render', function () {
|
||||
'/user.html': '{{role}} : {{alias}}'
|
||||
})
|
||||
const html = await liquid.renderFile('hash.html')
|
||||
expect(html).to.equal('admin : harttle')
|
||||
expect(html).toBe('admin : harttle')
|
||||
})
|
||||
|
||||
it('should not bleed into child template', async function () {
|
||||
@@ -84,7 +81,7 @@ describe('tags/render', function () {
|
||||
'/user.html': 'InChild: {{name}}'
|
||||
})
|
||||
const html = await liquid.renderFile('hash.html')
|
||||
expect(html).to.equal('InParent: harttle InChild: ')
|
||||
expect(html).toBe('InParent: harttle InChild: ')
|
||||
})
|
||||
|
||||
it('should allow argument reassignment', async function () {
|
||||
@@ -94,7 +91,7 @@ describe('tags/render', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
|
||||
const html = await staticLiquid.renderFile('parent.html')
|
||||
return expect(html).to.equal('green')
|
||||
return expect(html).toBe('green')
|
||||
})
|
||||
|
||||
it('should be able to access globals', async function () {
|
||||
@@ -104,7 +101,7 @@ describe('tags/render', function () {
|
||||
'/user.html': 'InChild: {{name}}'
|
||||
})
|
||||
const html = await liquid.renderFile('hash', { name: 'harttle' })
|
||||
expect(html).to.equal('InParent: harttle InChild: Harttle')
|
||||
expect(html).toBe('InParent: harttle InChild: Harttle')
|
||||
})
|
||||
|
||||
it('should support with', async function () {
|
||||
@@ -113,7 +110,7 @@ describe('tags/render', function () {
|
||||
'/color.html': 'color:{{color}}, shape:{{shape}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html')
|
||||
expect(html).to.equal('color:red, shape:rect')
|
||||
expect(html).toBe('color:red, shape:rect')
|
||||
})
|
||||
it('should treat as normal key/value if followed by ":"', async () => {
|
||||
mock({
|
||||
@@ -121,7 +118,7 @@ describe('tags/render', function () {
|
||||
'/color.html': 'color:{{color}}, with:{{with}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html')
|
||||
expect(html).to.equal('color:, with:foo')
|
||||
expect(html).toBe('color:, with:foo')
|
||||
})
|
||||
it('should treat as normal key if with value not specified', async () => {
|
||||
mock({
|
||||
@@ -129,7 +126,7 @@ describe('tags/render', function () {
|
||||
'/color.html': 'color:{{color}}, with:{{with}}, shape:{{shape}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html')
|
||||
expect(html).to.equal('color:, with:true, shape:rect')
|
||||
expect(html).toBe('color:, with:true, shape:rect')
|
||||
})
|
||||
it('should support with...as', async function () {
|
||||
mock({
|
||||
@@ -137,7 +134,7 @@ describe('tags/render', function () {
|
||||
'/color.html': 'color:{{c}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html', { color: 'red' })
|
||||
expect(html).to.equal('color:red')
|
||||
expect(html).toBe('color:red')
|
||||
})
|
||||
it('should support with...as and other parameters', async function () {
|
||||
mock({
|
||||
@@ -146,7 +143,7 @@ describe('tags/render', function () {
|
||||
})
|
||||
const scope = { color: 'red', shape: 'rect' }
|
||||
const html = await liquid.renderFile('index.html', scope)
|
||||
expect(html).to.equal('color:red, shape:rect')
|
||||
expect(html).toBe('color:red, shape:rect')
|
||||
})
|
||||
it('should support for...as', async function () {
|
||||
mock({
|
||||
@@ -154,7 +151,7 @@ describe('tags/render', function () {
|
||||
'/item.html': '{{forloop.index}}: {{color}}\n'
|
||||
})
|
||||
const html = await liquid.renderFile('index.html', { colors: ['red', 'green'] })
|
||||
expect(html).to.equal('1: red\n2: green\n')
|
||||
expect(html).toBe('1: red\n2: green\n')
|
||||
})
|
||||
it('should support for <iterable> as', async function () {
|
||||
class MockIterable {
|
||||
@@ -168,7 +165,7 @@ describe('tags/render', function () {
|
||||
'/item.html': '{{forloop.index}}: {{color}}\n'
|
||||
})
|
||||
const html = await liquid.renderFile('index.html', { colors: new MockIterable() })
|
||||
expect(html).to.equal('1: red\n2: green\n')
|
||||
expect(html).toBe('1: red\n2: green\n')
|
||||
})
|
||||
it('should support for <non-array> as', async function () {
|
||||
mock({
|
||||
@@ -176,7 +173,7 @@ describe('tags/render', function () {
|
||||
'/item.html': '{{forloop.index}}: {{color}}\n'
|
||||
})
|
||||
const html = await liquid.renderFile('index.html')
|
||||
expect(html).to.equal('1: green\n')
|
||||
expect(html).toBe('1: green\n')
|
||||
})
|
||||
it('should support for without as', async function () {
|
||||
mock({
|
||||
@@ -184,7 +181,7 @@ describe('tags/render', function () {
|
||||
'/item.html': '{{forloop.index}}: {{color}}\n'
|
||||
})
|
||||
const html = await liquid.renderFile('index.html', { colors: ['red', 'green'] })
|
||||
expect(html).to.equal('1: \n2: \n')
|
||||
expect(html).toBe('1: \n2: \n')
|
||||
})
|
||||
it('should support for...as with other parameters', async function () {
|
||||
mock({
|
||||
@@ -192,7 +189,7 @@ describe('tags/render', function () {
|
||||
'/item.html': '{{forloop.index}}{{sep}}{{color}}{{tail}}'
|
||||
})
|
||||
const html = await liquid.renderFile('index.html', { colors: ['red', 'green'] })
|
||||
expect(html).to.equal('1. red.\n2. green.\n')
|
||||
expect(html).toBe('1. red.\n2. green.\n')
|
||||
})
|
||||
it('should support for...as with other parameters (comma separated)', async function () {
|
||||
mock({
|
||||
@@ -200,7 +197,7 @@ describe('tags/render', function () {
|
||||
'/item.html': '{{forloop.index}}{{sep}}{{color}}{{tail}}'
|
||||
})
|
||||
const html = await liquid.renderFile('index.html', { colors: ['red', 'green'] })
|
||||
expect(html).to.equal('1. red.\n2. green.\n')
|
||||
expect(html).toBe('1. red.\n2. green.\n')
|
||||
})
|
||||
it('should support render: with as Drop', async function () {
|
||||
class ColorDrop extends Drop {
|
||||
@@ -213,7 +210,7 @@ describe('tags/render', function () {
|
||||
'/color.html': 'color:{{color}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html', { color: new ColorDrop() })
|
||||
expect(html).to.equal('color:red!')
|
||||
expect(html).toBe('color:red!')
|
||||
})
|
||||
it('should support render: with passed as Drop', async function () {
|
||||
class ColorDrop extends Drop {
|
||||
@@ -227,7 +224,7 @@ describe('tags/render', function () {
|
||||
'/color.html': '{{color | name}}'
|
||||
})
|
||||
const html = await liquid.renderFile('with.html', { color: new ColorDrop() })
|
||||
expect(html).to.equal('ColorDrop')
|
||||
expect(html).toBe('ColorDrop')
|
||||
})
|
||||
|
||||
it('should support nested renders', async function () {
|
||||
@@ -246,7 +243,7 @@ describe('tags/render', function () {
|
||||
}
|
||||
}
|
||||
const html = await liquid.renderFile('personInfo.html', ctx)
|
||||
expect(html).to.equal('This is a person <p>Joe Shmoe<br/>City: Dallas</p>')
|
||||
expect(html).toBe('This is a person <p>Joe Shmoe<br/>City: Dallas</p>')
|
||||
})
|
||||
it('should support relative reference', async function () {
|
||||
mock({
|
||||
@@ -255,7 +252,7 @@ describe('tags/render', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/foo' })
|
||||
const html = await staticLiquid.renderFile('coo/parent.html')
|
||||
expect(html).to.equal('Xchild with redY')
|
||||
expect(html).toBe('Xchild with redY')
|
||||
})
|
||||
it('should disable relative reference if specified', () => {
|
||||
mock({
|
||||
@@ -263,7 +260,7 @@ describe('tags/render', function () {
|
||||
'/foo/bar/child.html': 'child with {{color}}'
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/foo', relativeReference: false })
|
||||
return expect(staticLiquid.renderFile('coo/parent.html')).to.be.rejectedWith(/Failed to lookup/)
|
||||
return expect(staticLiquid.renderFile('coo/parent.html')).rejects.toThrow(/Failed to lookup/)
|
||||
})
|
||||
it('should throw not found if relative reference out of root', () => {
|
||||
mock({
|
||||
@@ -271,7 +268,7 @@ describe('tags/render', function () {
|
||||
'/bar/child.html': 'child with {{color}}'
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/foo', partials: '/foo' })
|
||||
return expect(staticLiquid.renderFile('parent.html')).to.be.rejectedWith(/Failed to lookup "..\/bar\/child.html"/)
|
||||
return expect(staticLiquid.renderFile('parent.html')).rejects.toThrow(/Failed to lookup "..\/bar\/child.html"/)
|
||||
})
|
||||
|
||||
describe('static partial', function () {
|
||||
@@ -285,7 +282,7 @@ describe('tags/render', function () {
|
||||
'/child.html': 'child with {{color}}'
|
||||
})
|
||||
const html = await staticLiquid.renderFile('parent.html')
|
||||
expect(html).to.equal('Xchild with redY')
|
||||
expect(html).toBe('Xchild with redY')
|
||||
})
|
||||
|
||||
it('should support parent paths', async function () {
|
||||
@@ -294,7 +291,7 @@ describe('tags/render', function () {
|
||||
'/foo/child.html': 'child'
|
||||
})
|
||||
const html = await staticLiquid.renderFile('parent.html')
|
||||
expect(html).to.equal('XchildY')
|
||||
expect(html).toBe('XchildY')
|
||||
})
|
||||
|
||||
it('should support subpaths', async function () {
|
||||
@@ -303,7 +300,7 @@ describe('tags/render', function () {
|
||||
'/foo/child.html': 'child'
|
||||
})
|
||||
const html = await staticLiquid.renderFile('parent.html')
|
||||
expect(html).to.equal('XchildY')
|
||||
expect(html).toBe('XchildY')
|
||||
})
|
||||
|
||||
it('should support comma separated arguments', async function () {
|
||||
@@ -312,7 +309,7 @@ describe('tags/render', function () {
|
||||
'/child.html': 'child with {{color}}'
|
||||
})
|
||||
const html = await staticLiquid.renderFile('parent.html')
|
||||
expect(html).to.equal('Xchild with redY')
|
||||
expect(html).toBe('Xchild with redY')
|
||||
})
|
||||
|
||||
it('should support template string', async function () {
|
||||
@@ -321,7 +318,7 @@ describe('tags/render', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = await staticLiquid.renderFile('/current.html', { name: 'foo.html' })
|
||||
expect(html).to.equal('barfoobar')
|
||||
expect(html).toBe('barfoobar')
|
||||
})
|
||||
|
||||
it('should support filters in template string', async function () {
|
||||
@@ -330,7 +327,7 @@ describe('tags/render', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = await staticLiquid.renderFile('/current.html', { name: 'foo' })
|
||||
expect(html).to.equal('barfoobar')
|
||||
expect(html).toBe('barfoobar')
|
||||
})
|
||||
})
|
||||
describe('sync support', function () {
|
||||
@@ -340,7 +337,7 @@ describe('tags/render', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = liquid.renderFileSync('/current.html')
|
||||
expect(html).to.equal('barfoobar')
|
||||
expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should support value string', function () {
|
||||
mock({
|
||||
@@ -348,7 +345,7 @@ describe('tags/render', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = liquid.renderFileSync('/current.html', { name: '/bar/foo.html' })
|
||||
expect(html).to.equal('barfoobar')
|
||||
expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should support template string', function () {
|
||||
mock({
|
||||
@@ -356,7 +353,7 @@ describe('tags/render', function () {
|
||||
'/bar/foo.html': 'foo'
|
||||
})
|
||||
const html = liquid.renderFileSync('/current.html', { name: '/foo.html' })
|
||||
expect(html).to.equal('barfoobar')
|
||||
expect(html).toBe('barfoobar')
|
||||
})
|
||||
it('should support with', function () {
|
||||
mock({
|
||||
@@ -364,7 +361,7 @@ describe('tags/render', function () {
|
||||
'/color.html': 'color:{{color}}, shape:{{shape}}'
|
||||
})
|
||||
const html = liquid.renderFileSync('with.html')
|
||||
expect(html).to.equal('color:red, shape:rect')
|
||||
expect(html).toBe('color:red, shape:rect')
|
||||
})
|
||||
it('should support filename with extension', function () {
|
||||
mock({
|
||||
@@ -373,7 +370,7 @@ describe('tags/render', function () {
|
||||
})
|
||||
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
|
||||
const html = staticLiquid.renderFileSync('parent.html')
|
||||
expect(html).to.equal('Xchild with redY')
|
||||
expect(html).toBe('Xchild with redY')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,9 +1,5 @@
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/tablerow', function () {
|
||||
const liquid = new Liquid()
|
||||
|
||||
@@ -11,7 +7,7 @@ describe('tags/tablerow', function () {
|
||||
const src = '{% tablerow i in (1..3)%}{{ i }}{% endtablerow %}'
|
||||
const dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
it('should support promises', async function () {
|
||||
@@ -21,7 +17,7 @@ describe('tags/tablerow', function () {
|
||||
}
|
||||
const dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
it('should support iterables', async function () {
|
||||
@@ -38,7 +34,7 @@ describe('tags/tablerow', function () {
|
||||
}
|
||||
const dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
it('should support cols', async function () {
|
||||
@@ -50,40 +46,40 @@ describe('tags/tablerow', function () {
|
||||
'<tr class="row1"><td class="col1">a</td><td class="col2">b</td></tr>' +
|
||||
'<tr class="row2"><td class="col1">c</td></tr>'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
it('should support cols set to 0', async function () {
|
||||
const src = '{% tablerow i in (1..3) cols:0 %}{{ i }}{% endtablerow %}'
|
||||
const dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
it('should support empty tablerow', async function () {
|
||||
const src = '{% tablerow i in (1..0) cols:2 %}{{ i }}{% endtablerow %}'
|
||||
const dst = ''
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
it('should support empty array', async function () {
|
||||
const src = '{% tablerow i in alpha.z cols:2 %}{{ i }}{% endtablerow %}'
|
||||
const dst = ''
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
it('should throw when tablerow not closed', function () {
|
||||
const src = '{% tablerow i in (1..0) cols:2 %}{{ i }}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/tag .* not closed/)
|
||||
.rejects.toThrow(/tag .* not closed/)
|
||||
})
|
||||
|
||||
it('should throw when x in y not found', function () {
|
||||
const src = '{% tablerow i (1..3) %}{{ i }}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith('illegal tag: {% tablerow i (1..3) %}, line:1, col:1')
|
||||
.rejects.toThrow('illegal tag: {% tablerow i (1..3) %}, line:1, col:1')
|
||||
})
|
||||
|
||||
it('should support tablerow with range', async function () {
|
||||
@@ -93,7 +89,7 @@ describe('tags/tablerow', function () {
|
||||
'<tr class="row2"><td class="col1">3</td><td class="col2">4</td></tr>' +
|
||||
'<tr class="row3"><td class="col1">5</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
it('should support tablerow with limit', async function () {
|
||||
@@ -102,45 +98,45 @@ describe('tags/tablerow', function () {
|
||||
'<tr class="row1"><td class="col1">1</td><td class="col2">2</td></tr>' +
|
||||
'<tr class="row2"><td class="col1">3</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
|
||||
it('should support index0, index, rindex0, rindex', async function () {
|
||||
const src = '{% tablerow i in (1..3)%}{{tablerowloop.index0}}{{tablerowloop.index}}{{tablerowloop.rindex0}}{{tablerowloop.rindex}}{% endtablerow %}'
|
||||
const dst = '<tr class="row1"><td class="col1">0123</td><td class="col2">1212</td><td class="col3">2301</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
it('should support first, last, length', async function () {
|
||||
const src = '{% tablerow i in (1..3)%}{{tablerowloop.first}} {{tablerowloop.last}} {{tablerowloop.length}}{% endtablerow %}'
|
||||
const dst = '<tr class="row1"><td class="col1">true false 3</td><td class="col2">false false 3</td><td class="col3">false true 3</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
it('should support col, row, col0, col_first, col_last', async function () {
|
||||
const src = '{% tablerow i in (1..3)%}{{tablerowloop.col}} {{tablerowloop.col0}} {{tablerowloop.col_first}} {{tablerowloop.col_last}}{% endtablerow %}'
|
||||
const dst = '<tr class="row1"><td class="col1">1 0 true false</td><td class="col2">2 1 false false</td><td class="col3">3 2 false true</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
describe('offset', function () {
|
||||
it('should support tablerow with offset', async function () {
|
||||
const src = '{% tablerow i in (1..5) cols:2 offset:3 %}{{ i }}{% endtablerow %}'
|
||||
const dst = '<tr class="row1"><td class="col1">4</td><td class="col2">5</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
it('index should also start at 1', async function () {
|
||||
const src = '{% tablerow i in (1..4) cols:2 offset:2 %}{{tablerowloop.index}}{% endtablerow %}'
|
||||
const dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
it('col should also start at 1', async function () {
|
||||
const src = '{% tablerow i in (1..4) cols:2 offset:3 %}{{tablerowloop.col}}{% endtablerow %}'
|
||||
const dst = '<tr class="row1"><td class="col1">1</td></tr>'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
})
|
||||
describe('sync support', function () {
|
||||
@@ -148,13 +144,13 @@ describe('tags/tablerow', function () {
|
||||
const src = '{% tablerow i in (1..3)%}{{ i }}{% endtablerow %}'
|
||||
const dst = '<tr class="row1"><td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
expect(html).to.equal(dst)
|
||||
expect(html).toBe(dst)
|
||||
})
|
||||
it('should support empty tablerow', function () {
|
||||
const src = '{% tablerow i in "" cols:2 %}{{ i }}{% endtablerow %}'
|
||||
const dst = ''
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
return expect(html).to.equal(dst)
|
||||
return expect(html).toBe(dst)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,43 +1,39 @@
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('tags/unless', function () {
|
||||
let liquid: Liquid
|
||||
before(() => { liquid = new Liquid() })
|
||||
beforeEach(() => { liquid = new Liquid() })
|
||||
|
||||
it('should render else when predicate yields true', async function () {
|
||||
// 0 is truthy
|
||||
const src = '{% unless 0 %}yes{%else%}no{%endunless%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('no')
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
it('should support elsif', async function () {
|
||||
const src = '{% unless true %}1{%elsif true%}2{%else%}3{%endunless%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('2')
|
||||
return expect(html).toBe('2')
|
||||
})
|
||||
it('should render unless when predicate yields false', async function () {
|
||||
const src = '{% unless false %}yes{%else%}no{%endunless%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('yes')
|
||||
return expect(html).toBe('yes')
|
||||
})
|
||||
it('should reject when tag not closed', function () {
|
||||
const src = '{% unless 1 > 2 %}yes'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/tag {% unless 1 > 2 %} not closed/)
|
||||
.rejects.toThrow(/tag {% unless 1 > 2 %} not closed/)
|
||||
})
|
||||
it('should render unless when predicate yields false and else undefined', async function () {
|
||||
const src = '{% unless 1 > 2 %}yes{%endunless%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('yes')
|
||||
return expect(html).toBe('yes')
|
||||
})
|
||||
it('should render "" when predicate yields false and else undefined', async function () {
|
||||
const src = '{% unless 1 < 2 %}yes{%endunless%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
|
||||
it('should output unless contents in order', async function () {
|
||||
@@ -46,7 +42,7 @@ describe('tags/unless', function () {
|
||||
{% unless false %}Inside {{ location }}{% endunless %}
|
||||
After {{ location }}`
|
||||
const html = await liquid.parseAndRender(src, { location: 'wonderland' })
|
||||
expect(html).to.equal(`
|
||||
expect(html).toBe(`
|
||||
Before wonderland
|
||||
Inside wonderland
|
||||
After wonderland`)
|
||||
@@ -56,12 +52,12 @@ describe('tags/unless', function () {
|
||||
it('should render else when predicate yields true', function () {
|
||||
const src = '{% unless 0 %}yes{%else%}no{%endunless%}'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
expect(html).to.equal('no')
|
||||
expect(html).toBe('no')
|
||||
})
|
||||
it('should render unless when predicate yields false', function () {
|
||||
const src = '{% unless false %}yes{%else%}no{%endunless%}'
|
||||
const html = liquid.parseAndRenderSync(src)
|
||||
expect(html).to.equal('yes')
|
||||
expect(html).toBe('yes')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,11 +1,7 @@
|
||||
import { expect, use } from 'chai'
|
||||
import { RenderError } from '../../../src/util/error'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import * as path from 'path'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
let engine = new Liquid()
|
||||
const strictEngine = new Liquid({
|
||||
@@ -18,9 +14,10 @@ describe('error', function () {
|
||||
|
||||
describe('TokenizationError', function () {
|
||||
it('should throw TokenizationError when tag illegal', async function () {
|
||||
const err = await expect(engine.parseAndRender('{% . a %}', {})).be.rejected
|
||||
expect(err.name).to.equal('TokenizationError')
|
||||
expect(err.message).to.contain('illegal tag syntax')
|
||||
await expect(engine.parseAndRender('{% . a %}', {})).rejects.toMatchObject({
|
||||
name: 'TokenizationError',
|
||||
message: expect.stringContaining('illegal tag syntax')
|
||||
})
|
||||
})
|
||||
it('should contain template content in err.message', async function () {
|
||||
const html = ['1st', '2nd', 'X{% . a %} Y', '4th']
|
||||
@@ -31,33 +28,41 @@ describe('error', function () {
|
||||
' 4| 4th',
|
||||
'TokenizationError'
|
||||
]
|
||||
const err = await expect(engine.parseAndRender(html.join('\n'))).be.rejected
|
||||
expect(err.message).to.equal('illegal tag syntax, line:3, col:2')
|
||||
expect(err.stack).to.contain(message.join('\n'))
|
||||
expect(err.name).to.equal('TokenizationError')
|
||||
await expect(engine.parseAndRender(html.join('\n'))).rejects.toMatchObject({
|
||||
message: 'illegal tag syntax, line:3, col:2',
|
||||
stack: expect.stringContaining(message.join('\n')),
|
||||
name: 'TokenizationError'
|
||||
})
|
||||
})
|
||||
it('should contain the whole template content in err.token.input', async function () {
|
||||
const html = 'bar\nfoo{% . a %}\nfoo'
|
||||
const err = await expect(engine.parseAndRender(html)).be.rejected
|
||||
expect(err.token.input).to.equal(html)
|
||||
await expect(engine.parseAndRender(html)).rejects.toMatchObject({
|
||||
token: expect.objectContaining({
|
||||
input: html
|
||||
})
|
||||
})
|
||||
})
|
||||
it('should contain stack in err.stack', async function () {
|
||||
const err = await expect(engine.parseAndRender('{% . a %}')).be.rejected
|
||||
expect(err.message).to.contain('illegal tag syntax')
|
||||
expect(err.stack).to.contain('at Liquid.parse')
|
||||
await expect(engine.parseAndRender('{% . a %}')).rejects.toMatchObject({
|
||||
message: expect.stringContaining('illegal tag syntax'),
|
||||
stack: expect.stringContaining('at Liquid.parse')
|
||||
})
|
||||
})
|
||||
describe('captureStackTrace compatibility', function () {
|
||||
it('should be empty when captureStackTrace undefined', async function () {
|
||||
const err = await expect(engine.parseAndRender('{% . a %}')).be.rejected
|
||||
expect(err.stack).to.contain('illegal tag syntax')
|
||||
expect(err.stack).to.not.contain('at Object.parse')
|
||||
await expect(engine.parseAndRender('{% . a %}')).rejects.toMatchObject({
|
||||
stack: expect.stringContaining('illegal tag syntax')
|
||||
})
|
||||
await expect(engine.parseAndRender('{% . a %}')).rejects.toMatchObject({
|
||||
stack: expect.not.stringContaining('at Object.parse')
|
||||
})
|
||||
})
|
||||
})
|
||||
it('should throw error with [line, col] if tag unmatched', async function () {
|
||||
const err = await expect(engine.parseAndRender('1\n2\nfoo{% assign a = 4 }\n4')).be.rejected
|
||||
console.log(err.stack)
|
||||
expect(err.name).to.equal('TokenizationError')
|
||||
expect(err.message).to.equal('tag "{% assign a =..." not closed, line:3, col:4')
|
||||
await expect(engine.parseAndRender('1\n2\nfoo{% assign a = 4 }\n4')).rejects.toMatchObject({
|
||||
name: 'TokenizationError',
|
||||
message: 'tag "{% assign a =..." not closed, line:3, col:4'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -82,30 +87,34 @@ describe('error', function () {
|
||||
})
|
||||
it('should throw RenderError when tag throws', async function () {
|
||||
const src = '{%throwingTag%}'
|
||||
const err = await expect(engine.parseAndRender(src)).be.rejected
|
||||
expect(err.name).to.equal('RenderError')
|
||||
expect(err.message).to.contain('intended render error')
|
||||
await expect(engine.parseAndRender(src)).rejects.toMatchObject({
|
||||
name: 'RenderError',
|
||||
message: expect.stringContaining('intended render error')
|
||||
})
|
||||
})
|
||||
it('should throw RenderError when tag rejects', async function () {
|
||||
const src = '{%rejectingTag%}'
|
||||
const err = await expect(engine.parseAndRender(src)).be.rejected
|
||||
expect(err.name).to.equal('RenderError')
|
||||
expect(err.message).to.contain('intended render reject')
|
||||
await expect(engine.parseAndRender(src)).rejects.toMatchObject({
|
||||
name: 'RenderError',
|
||||
message: expect.stringContaining('intended render reject')
|
||||
})
|
||||
})
|
||||
it('should throw RenderError when filter throws', async function () {
|
||||
const src = '{{1|throwingFilter}}'
|
||||
const err = await expect(engine.parseAndRender(src)).be.rejected
|
||||
expect(err.name).to.equal('RenderError')
|
||||
expect(err.message).to.contain('throwed by filter')
|
||||
await expect(engine.parseAndRender(src)).rejects.toMatchObject({
|
||||
name: 'RenderError',
|
||||
message: expect.stringContaining('throwed by filter')
|
||||
})
|
||||
})
|
||||
it('should not throw when variable undefined by default', async function () {
|
||||
const html = await engine.parseAndRender('X{{a}}Y')
|
||||
return expect(html).to.equal('XY')
|
||||
return expect(html).toBe('XY')
|
||||
})
|
||||
it('should throw RenderError when variable not defined', async function () {
|
||||
const err = await expect(strictEngine.parseAndRender('{{a}}')).be.rejected
|
||||
expect(err).to.have.property('name', 'RenderError')
|
||||
expect(err.message).to.contain('undefined variable: a')
|
||||
await expect(strictEngine.parseAndRender('{{a}}')).rejects.toMatchObject({
|
||||
name: 'RenderError',
|
||||
message: expect.stringContaining('undefined variable: a')
|
||||
})
|
||||
})
|
||||
it('should contain template context in err.stack', async function () {
|
||||
const html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
|
||||
@@ -118,10 +127,11 @@ describe('error', function () {
|
||||
' 7| 7th',
|
||||
'RenderError'
|
||||
]
|
||||
const err = await expect(engine.parseAndRender(html.join('\n'))).be.rejected
|
||||
expect(err.message).to.equal('intended render error, line:4, col:2')
|
||||
expect(err.stack).to.contain(message.join('\n'))
|
||||
expect(err.name).to.equal('RenderError')
|
||||
await expect(engine.parseAndRender(html.join('\n'))).rejects.toMatchObject({
|
||||
name: 'RenderError',
|
||||
message: 'intended render error, line:4, col:2',
|
||||
stack: expect.stringContaining(message.join('\n'))
|
||||
})
|
||||
})
|
||||
it('should contain original error info for {% layout %}', async function () {
|
||||
mock({
|
||||
@@ -145,10 +155,11 @@ describe('error', function () {
|
||||
' 7| 7th',
|
||||
'RenderError'
|
||||
]
|
||||
const err = await expect(engine.parseAndRender(html)).be.rejected
|
||||
expect(err.message).to.equal(`intended render error, file:${path.resolve('/throwing-tag.html')}, line:4, col:2`)
|
||||
expect(err.stack).to.contain(message.join('\n'))
|
||||
expect(err.name).to.equal('RenderError')
|
||||
await expect(engine.parseAndRender(html)).rejects.toMatchObject({
|
||||
name: 'RenderError',
|
||||
message: `intended render error, file:${path.resolve('/throwing-tag.html')}, line:4, col:2`,
|
||||
stack: expect.stringContaining(message.join('\n'))
|
||||
})
|
||||
})
|
||||
it('should contain original error info for {% include %}', async function () {
|
||||
const origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
|
||||
@@ -165,15 +176,17 @@ describe('error', function () {
|
||||
' 7| 7th',
|
||||
'RenderError'
|
||||
]
|
||||
const err = await expect(engine.parseAndRender(html)).be.rejected
|
||||
expect(err.message).to.equal(`intended render error, file:${path.resolve('/throwing-tag.html')}, line:4, col:2`)
|
||||
expect(err.stack).to.contain(message.join('\n'))
|
||||
expect(err.name).to.equal('RenderError')
|
||||
await expect(engine.parseAndRender(html)).rejects.toMatchObject({
|
||||
name: 'RenderError',
|
||||
message: `intended render error, file:${path.resolve('/throwing-tag.html')}, line:4, col:2`,
|
||||
stack: expect.stringContaining(message.join('\n'))
|
||||
})
|
||||
})
|
||||
it('should contain stack in err.stack', async function () {
|
||||
const err = await expect(engine.parseAndRender('{%rejectingTag%}')).be.rejected
|
||||
expect(err.message).to.contain('intended render reject')
|
||||
expect(err.stack).to.match(/at .*:\d+:\d+/)
|
||||
await expect(engine.parseAndRender('{%rejectingTag%}')).rejects.toMatchObject({
|
||||
message: expect.stringContaining('intended render reject'),
|
||||
stack: expect.stringMatching(/at .*:\d+:\d+/)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -188,30 +201,35 @@ describe('error', function () {
|
||||
})
|
||||
})
|
||||
it('should throw ParseError when filter not defined', async function () {
|
||||
const err = await expect(strictEngine.parseAndRender('{{1 | a}}')).be.rejected
|
||||
expect(err).to.have.property('name', 'ParseError')
|
||||
expect(err.message).to.contain('undefined filter: a')
|
||||
await expect(strictEngine.parseAndRender('{{1 | a}}')).rejects.toMatchObject({
|
||||
name: 'ParseError',
|
||||
message: expect.stringContaining('undefined filter: a')
|
||||
})
|
||||
})
|
||||
it('should throw ParseError when tag not closed', async function () {
|
||||
const err = await expect(engine.parseAndRender('{% if %}')).be.rejected
|
||||
expect(err.name).to.equal('ParseError')
|
||||
expect(err.message).to.contain('tag {% if %} not closed')
|
||||
await expect(engine.parseAndRender('{% if %}')).rejects.toMatchObject({
|
||||
name: 'ParseError',
|
||||
message: expect.stringContaining('tag {% if %} not closed')
|
||||
})
|
||||
})
|
||||
it('should throw ParseError when tag parse throws', async function () {
|
||||
const err = await expect(engine.parseAndRender('{%throwsOnParse%}')).be.rejected
|
||||
expect(err.name).to.equal('ParseError')
|
||||
expect(err.message).to.contain('intended parse error')
|
||||
await expect(engine.parseAndRender('{%throwsOnParse%}')).rejects.toMatchObject({
|
||||
name: 'ParseError',
|
||||
message: expect.stringContaining('intended parse error')
|
||||
})
|
||||
})
|
||||
it('should throw ParseError when tag not found', async function () {
|
||||
const src = '{%if true%}\naaa{%endif%}\n{% -a %}\n3'
|
||||
const err = await expect(engine.parseAndRender(src)).be.rejected
|
||||
expect(err.name).to.equal('ParseError')
|
||||
expect(err.message).to.contain('tag "-a" not found')
|
||||
await expect(engine.parseAndRender(src)).rejects.toMatchObject({
|
||||
name: 'ParseError',
|
||||
message: expect.stringContaining('tag "-a" not found')
|
||||
})
|
||||
})
|
||||
it('should throw ParseError when tag not exist', async function () {
|
||||
const err = await expect(engine.parseAndRender('{% a %}')).be.rejected
|
||||
expect(err.name).to.equal('ParseError')
|
||||
expect(err.message).to.contain('tag "a" not found')
|
||||
await expect(engine.parseAndRender('{% a %}')).rejects.toMatchObject({
|
||||
name: 'ParseError',
|
||||
message: expect.stringContaining('tag "a" not found')
|
||||
})
|
||||
})
|
||||
|
||||
it('should contain template context in err.stack', async function () {
|
||||
@@ -225,10 +243,11 @@ describe('error', function () {
|
||||
' 7| 7th',
|
||||
'ParseError: tag "a" not found'
|
||||
]
|
||||
const err = await expect(engine.parseAndRender(html.join('\n'))).be.rejected
|
||||
expect(err.message).to.equal('tag "a" not found, line:4, col:2')
|
||||
expect(err.stack).to.contain(message.join('\n'))
|
||||
expect(err.name).to.equal('ParseError')
|
||||
await expect(engine.parseAndRender(html.join('\n'))).rejects.toMatchObject({
|
||||
name: 'ParseError',
|
||||
message: 'tag "a" not found, line:4, col:2',
|
||||
stack: expect.stringContaining(message.join('\n'))
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle err.message when context not enough', async function () {
|
||||
@@ -240,15 +259,19 @@ describe('error', function () {
|
||||
' 4| 4th',
|
||||
'ParseError: tag "a" not found'
|
||||
]
|
||||
const err = await expect(engine.parseAndRender(html.join('\n'))).be.rejected
|
||||
expect(err.message).to.equal('tag "a" not found, line:2, col:2')
|
||||
expect(err.stack).to.contain(message.join('\n'))
|
||||
await expect(engine.parseAndRender(html.join('\n'))).rejects.toMatchObject({
|
||||
message: 'tag "a" not found, line:2, col:2',
|
||||
stack: expect.stringContaining(message.join('\n'))
|
||||
})
|
||||
})
|
||||
|
||||
it('should contain stack in err.stack', async function () {
|
||||
const err = await expect(engine.parseAndRender('{% -a %}')).be.rejected
|
||||
expect(err.stack).to.contain('ParseError: tag "-a" not found')
|
||||
expect(err.stack).to.match(/at .*:\d+:\d+\)/)
|
||||
await expect(engine.parseAndRender('{% -a %}')).rejects.toMatchObject({
|
||||
stack: expect.stringContaining('ParseError: tag "-a" not found')
|
||||
})
|
||||
await expect(engine.parseAndRender('{% -a %}')).rejects.toMatchObject({
|
||||
stack: expect.stringMatching(/at .*:\d+:\d+\)/)
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('sync support', function () {
|
||||
@@ -265,8 +288,8 @@ describe('error', function () {
|
||||
})
|
||||
it('should throw RenderError when tag throws', function () {
|
||||
const src = '{%throwingTag%}'
|
||||
expect(() => engine.parseAndRenderSync(src))
|
||||
.to.throw(RenderError, /intended render error/)
|
||||
expect(() => engine.parseAndRenderSync(src)).toThrow(RenderError)
|
||||
expect(() => engine.parseAndRenderSync(src)).toThrow(/intended render error/)
|
||||
})
|
||||
it('should contain original error info for {% include %}', function () {
|
||||
mock({
|
||||
@@ -286,9 +309,9 @@ describe('error', function () {
|
||||
engine.parseAndRenderSync(html)
|
||||
throw new Error('expected throw')
|
||||
} catch (err) {
|
||||
expect(err.message).to.equal(`intended render error, file:${path.resolve('/throwing-tag.html')}, line:4, col:2`)
|
||||
expect(err.stack).to.contain(message.join('\n'))
|
||||
expect(err.name).to.equal('RenderError')
|
||||
expect(err).toHaveProperty('name', 'RenderError')
|
||||
expect(err).toHaveProperty('message', `intended render error, file:${path.resolve('/throwing-tag.html')}, line:4, col:2`)
|
||||
expect(err).toHaveProperty('stack', expect.stringContaining(message.join('\n')))
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user