mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
fix: break/continue omitting output before them, #123
BREAKING CHANGE: remove default export, now should be used like import
{Liquid} from 'liquidjs'
This commit is contained in:
+2
-2
@@ -1,10 +1,10 @@
|
||||
import Liquid from '../..'
|
||||
import { Liquid, Drop } from '../..'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
class SettingsDrop extends Liquid.Types.Drop {
|
||||
class SettingsDrop extends Drop {
|
||||
private foo: string = 'FOO'
|
||||
public bar () {
|
||||
return 'BAR'
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../..'
|
||||
import { Liquid } from '../..'
|
||||
|
||||
describe('.evalValue()', function () {
|
||||
var engine: Liquid
|
||||
beforeEach(() => { engine = new Liquid() })
|
||||
|
||||
it('should throw when scope undefined', async function () {
|
||||
return expect(engine.evalValue('{{"foo"}}', null as any)).to.be.rejectedWith(/scope undefined/)
|
||||
return expect(() => engine.evalValue('{{"foo"}}', null as any)).to.throw(/scope undefined/)
|
||||
})
|
||||
})
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import { expect } from 'chai'
|
||||
import * as request from 'supertest'
|
||||
import * as express from 'express'
|
||||
import { resolve } from 'path'
|
||||
import Liquid from '../..'
|
||||
import { Liquid } from '../..'
|
||||
|
||||
describe('express()', function () {
|
||||
const root = resolve(__dirname, '../stub/root')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../..'
|
||||
import { Liquid } from '../..'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../..'
|
||||
import { Liquid } from '../..'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { resolve } from 'path'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../..'
|
||||
import { Liquid } from '../..'
|
||||
|
||||
const liquid = new Liquid()
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../dist/liquid.js'
|
||||
import { Liquid } from '../../dist/liquid.js'
|
||||
import * as sinon from 'sinon'
|
||||
import { expect, use } from 'chai'
|
||||
import { JSDOM } from 'jsdom'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { test } from '../../../stub/render'
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('filters/array', function () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { test, ctx } from '../../../stub/render'
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
|
||||
describe('filters/date', function () {
|
||||
let liquid: Liquid
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import { test, liquid } from '../../../stub/render'
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
|
||||
describe('filters/math', function () {
|
||||
const l = new Liquid()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { test } from '../../../stub/render'
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('filters/string', function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Scope } from '../../../../src/context/scope'
|
||||
@@ -106,12 +106,22 @@ describe('tags/for', function () {
|
||||
return expect(html).to.equal(dst)
|
||||
})
|
||||
|
||||
it('should support for with continue', async function () {
|
||||
const src = '{% for i in (1..5) %}' +
|
||||
'{{i}}{% continue %}after' +
|
||||
'{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('12345')
|
||||
describe('continue', function () {
|
||||
it('should support for with continue', async function () {
|
||||
const src = '{% for i in (1..5) %}' +
|
||||
'{% if i == 4 %}continue{% continue %}{% endif %}{{i}}' +
|
||||
'{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('123continue5')
|
||||
})
|
||||
it('should output contents before continue', async function () {
|
||||
const src = '{% for i in (1..5) %}' +
|
||||
'{% if i == 4 %}continue{% continue %}{% endif %}' +
|
||||
'{{ i }}' +
|
||||
'{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('123continue5')
|
||||
})
|
||||
})
|
||||
describe('break', function () {
|
||||
it('should support break', async function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('tags/if', function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid, Drop } from '../../../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
import { mock, restore } from '../../../stub/mockfs'
|
||||
|
||||
@@ -83,8 +83,8 @@ describe('tags/include', function () {
|
||||
const html = await liquid.renderFile('with.html')
|
||||
return expect(html).to.equal('color:red, shape:rect')
|
||||
})
|
||||
it('should support include: with as Liquid Drop', async function () {
|
||||
class ColorDrop extends Liquid.Types.Drop {
|
||||
it('should support include: with as Drop', async function () {
|
||||
class ColorDrop extends Drop {
|
||||
public valueOf (): string {
|
||||
return 'red!'
|
||||
}
|
||||
@@ -96,8 +96,8 @@ describe('tags/include', function () {
|
||||
const html = await liquid.renderFile('with.html', { color: new ColorDrop() })
|
||||
expect(html).to.equal('color:red!')
|
||||
})
|
||||
it('should support include: with passed as Liquid Drop', async function () {
|
||||
class ColorDrop extends Liquid.Types.Drop {
|
||||
it('should support include: with passed as Drop', async function () {
|
||||
class ColorDrop extends Drop {
|
||||
public valueOf (): string {
|
||||
return 'red!'
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
import { mock, restore } from '../../../stub/mockfs'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('tags/raw', function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('tags/tablerow', function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { Liquid } from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('drop/blank-drop', function () {
|
||||
let liquid: Liquid
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid, Drop } from '../../../src/liquid'
|
||||
|
||||
describe('drop/drop', function () {
|
||||
let liquid: Liquid
|
||||
before(() => (liquid = new Liquid()))
|
||||
|
||||
class CustomDrop extends Liquid.Types.Drop {
|
||||
class CustomDrop extends Drop {
|
||||
private name: string = 'NAME'
|
||||
public getName () {
|
||||
return 'GET NAME'
|
||||
@@ -16,7 +16,7 @@ describe('drop/drop', function () {
|
||||
return key.toUpperCase()
|
||||
}
|
||||
}
|
||||
class PromiseDrop extends Liquid.Types.Drop {
|
||||
class PromiseDrop extends Drop {
|
||||
private name = Promise.resolve('NAME')
|
||||
public async getName () {
|
||||
return 'GET NAME'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('drop/empty-drop', function () {
|
||||
let liquid: Liquid
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('drop/null-drop', function () {
|
||||
let liquid: Liquid
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
|
||||
describe('LiquidOptions#cache', function () {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('LiquidOptions#*_delimiter_*', function () {
|
||||
it('should respect tag_delimiter_*', async function () {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('LiquidOptions#fs', function () {
|
||||
let engine: Liquid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid, isFalsy } from '../../../src/liquid'
|
||||
import * as chai from 'chai'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
@@ -19,7 +19,7 @@ describe('Liquid', function () {
|
||||
it('should call plugin with Liquid', async function () {
|
||||
const engine = new Liquid()
|
||||
engine.plugin(function (Liquid) {
|
||||
this.registerFilter('t', x => Liquid.isFalsy(x))
|
||||
this.registerFilter('t', x => isFalsy(x))
|
||||
})
|
||||
const html = await engine.parseAndRender('{{false|t}}')
|
||||
expect(html).to.equal('true')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('LiquidOptions#strict*', function () {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('LiquidOptions#trimming', function () {
|
||||
const ctx = { name: 'harttle' }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import * as path from 'path'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
|
||||
@@ -190,7 +190,8 @@ describe('error', function () {
|
||||
engine.registerTag('throwsOnParse', {
|
||||
parse: function () {
|
||||
throw new Error('intended parse error')
|
||||
}
|
||||
},
|
||||
render: () => ''
|
||||
})
|
||||
})
|
||||
it('should throw ParseError when filter not defined', async function () {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import Liquid from '../../src/liquid'
|
||||
import { Liquid } from '../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
|
||||
export const liquid = new Liquid()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import * as chai from 'chai'
|
||||
import Context from '../../../src/context/context'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import { Scope } from '../../../src/context/scope'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('scope', function () {
|
||||
describe('Context', function () {
|
||||
let ctx: any, scope: Scope
|
||||
beforeEach(function () {
|
||||
scope = {
|
||||
@@ -22,108 +22,107 @@ describe('scope', function () {
|
||||
|
||||
describe('#propertyAccessSeq()', function () {
|
||||
it('should handle dot syntax', async function () {
|
||||
expect(await ctx.parseProp('foo.bar'))
|
||||
expect(ctx.parseProp('foo.bar'))
|
||||
.to.deep.equal(['foo', 'bar'])
|
||||
})
|
||||
it('should handle [<String>] syntax', async function () {
|
||||
expect(await ctx.parseProp('foo["bar"]'))
|
||||
expect(ctx.parseProp('foo["bar"]'))
|
||||
.to.deep.equal(['foo', 'bar'])
|
||||
})
|
||||
it('should handle [<Identifier>] syntax', async function () {
|
||||
expect(await ctx.parseProp('foo[foo]'))
|
||||
expect(ctx.parseProp('foo[foo]'))
|
||||
.to.deep.equal(['foo', 'zoo'])
|
||||
})
|
||||
it('should handle nested access 1', async function () {
|
||||
expect(await ctx.parseProp('foo[bar.zoo]'))
|
||||
expect(ctx.parseProp('foo[bar.zoo]'))
|
||||
.to.deep.equal(['foo', 'coo'])
|
||||
})
|
||||
it('should handle nested access 2', async function () {
|
||||
expect(await ctx.parseProp('foo[bar["zoo"]]'))
|
||||
expect(ctx.parseProp('foo[bar["zoo"]]'))
|
||||
.to.deep.equal(['foo', 'coo'])
|
||||
})
|
||||
it('should handle nested access 3', async function () {
|
||||
expect(await ctx.parseProp('bar["foo"].zoo'))
|
||||
expect(ctx.parseProp('bar["foo"].zoo'))
|
||||
.to.deep.equal(['bar', 'foo', 'zoo'])
|
||||
})
|
||||
it('should handle nested access 4', async function () {
|
||||
expect(await ctx.parseProp('foo[0].bar'))
|
||||
expect(ctx.parseProp('foo[0].bar'))
|
||||
.to.deep.equal(['foo', '0', 'bar'])
|
||||
})
|
||||
it('should handle nested access 5', async function () {
|
||||
expect(await ctx.parseProp('foo[one].bar'))
|
||||
expect(ctx.parseProp('foo[one].bar'))
|
||||
.to.deep.equal(['foo', '1', 'bar'])
|
||||
})
|
||||
it('should handle nested access 6', async function () {
|
||||
expect(await ctx.parseProp('foo[two].bar'))
|
||||
expect(ctx.parseProp('foo[two].bar'))
|
||||
.to.deep.equal(['foo', 'undefined', 'bar'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('#get()', function () {
|
||||
it('should get direct property', async function () {
|
||||
expect(await await ctx.get('foo')).equal('zoo')
|
||||
expect(ctx.get('foo')).equal('zoo')
|
||||
})
|
||||
|
||||
it('undefined property should yield undefined', async function () {
|
||||
expect(ctx.get('notdefined')).to.be.rejected
|
||||
expect(await ctx.get('notdefined')).to.equal(undefined)
|
||||
expect(await ctx.get(false as any)).to.equal(undefined)
|
||||
expect(ctx.get('notdefined')).to.equal(undefined)
|
||||
expect(ctx.get(false as any)).to.equal(undefined)
|
||||
})
|
||||
|
||||
it('should throw for invalid path', async function () {
|
||||
expect(ctx.get('')).to.be.rejectedWith('invalid path:""')
|
||||
expect(() => ctx.get('')).to.throw('invalid path:""')
|
||||
})
|
||||
|
||||
it('should throw when [] unbalanced', async function () {
|
||||
expect(ctx.get('foo[bar')).to.be.rejectedWith(/unbalanced \[\]/)
|
||||
expect(() => ctx.get('foo[bar')).to.throw(/unbalanced \[\]/)
|
||||
})
|
||||
|
||||
it('should throw when "" unbalanced', async function () {
|
||||
expect(ctx.get('foo["bar]')).to.be.rejectedWith(/unbalanced "/)
|
||||
expect(() => ctx.get('foo["bar]')).to.throw(/unbalanced "/)
|
||||
})
|
||||
|
||||
it("should throw when '' unbalanced", async function () {
|
||||
expect(ctx.get("foo['bar]")).to.be.rejectedWith(/unbalanced '/)
|
||||
expect(() => ctx.get("foo['bar]")).to.throw(/unbalanced '/)
|
||||
})
|
||||
it('should respect to toLiquid', async function () {
|
||||
const scope = new Context({ foo: {
|
||||
toLiquid: () => ({ bar: 'BAR' }),
|
||||
bar: 'bar'
|
||||
} })
|
||||
expect(await scope.get('foo.bar')).to.equal('BAR')
|
||||
expect(scope.get('foo.bar')).to.equal('BAR')
|
||||
})
|
||||
|
||||
it('should access child property via dot syntax', async function () {
|
||||
expect(await ctx.get('bar.zoo')).to.equal('coo')
|
||||
expect(await ctx.get('bar.arr')).to.deep.equal(['a', 'b'])
|
||||
expect(ctx.get('bar.zoo')).to.equal('coo')
|
||||
expect(ctx.get('bar.arr')).to.deep.equal(['a', 'b'])
|
||||
})
|
||||
|
||||
it('should access child property via [<String>] syntax', async function () {
|
||||
expect(await ctx.get('bar["zoo"]')).to.equal('coo')
|
||||
expect(ctx.get('bar["zoo"]')).to.equal('coo')
|
||||
})
|
||||
|
||||
it('should access child property via [<Number>] syntax', async function () {
|
||||
expect(await ctx.get('bar.arr[0]')).to.equal('a')
|
||||
expect(ctx.get('bar.arr[0]')).to.equal('a')
|
||||
})
|
||||
|
||||
it('should access child property via [<Identifier>] syntax', async function () {
|
||||
expect(await ctx.get('bar[foo]')).to.equal('coo')
|
||||
expect(ctx.get('bar[foo]')).to.equal('coo')
|
||||
})
|
||||
|
||||
it('should return undefined when not exist', async function () {
|
||||
expect(await ctx.get('foo.foo.foo')).to.be.undefined
|
||||
expect(ctx.get('foo.foo.foo')).to.be.undefined
|
||||
})
|
||||
it('should return string length as size', async function () {
|
||||
expect(await ctx.get('foo.size')).to.equal(3)
|
||||
expect(ctx.get('foo.size')).to.equal(3)
|
||||
})
|
||||
it('should return array length as size', async function () {
|
||||
expect(await ctx.get('bar.arr.size')).to.equal(2)
|
||||
expect(ctx.get('bar.arr.size')).to.equal(2)
|
||||
})
|
||||
it('should return size property if exists', async function () {
|
||||
expect(await ctx.get('zoo.size')).to.equal(4)
|
||||
expect(ctx.get('zoo.size')).to.equal(4)
|
||||
})
|
||||
it('should return undefined if do not have size and length', async function () {
|
||||
expect(await ctx.get('one.size')).to.equal(undefined)
|
||||
expect(ctx.get('one.size')).to.equal(undefined)
|
||||
})
|
||||
})
|
||||
describe('strictVariables', async function () {
|
||||
@@ -134,28 +133,28 @@ describe('scope', function () {
|
||||
} as any)
|
||||
})
|
||||
it('should throw when variable not defined', function () {
|
||||
return expect(ctx.get('notdefined')).to.be.rejectedWith(/undefined variable: notdefined/)
|
||||
return expect(() => ctx.get('notdefined')).to.throw(/undefined variable: notdefined/)
|
||||
})
|
||||
it('should throw when deep variable not exist', async function () {
|
||||
ctx.push({ foo: 'FOO' })
|
||||
return expect(ctx.get('foo.bar.not.defined')).to.be.rejectedWith(/undefined variable: bar/)
|
||||
return expect(() => ctx.get('foo.bar.not.defined')).to.throw(/undefined variable: bar/)
|
||||
})
|
||||
it('should throw when itself not defined', async function () {
|
||||
ctx.push({ foo: 'FOO' })
|
||||
return expect(ctx.get('foo.BAR')).to.be.rejectedWith(/undefined variable: BAR/)
|
||||
return expect(() => ctx.get('foo.BAR')).to.throw(/undefined variable: BAR/)
|
||||
})
|
||||
it('should find variable in parent scope', async function () {
|
||||
ctx.push({ 'foo': 'foo' })
|
||||
ctx.push({
|
||||
'bar': 'bar'
|
||||
})
|
||||
expect(await ctx.get('foo')).to.equal('foo')
|
||||
expect(ctx.get('foo')).to.equal('foo')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.getAll()', function () {
|
||||
it('should get all properties when arguments empty', async function () {
|
||||
expect(await ctx.getAll()).deep.equal(scope)
|
||||
expect(ctx.getAll()).deep.equal(scope)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -165,14 +164,14 @@ describe('scope', function () {
|
||||
ctx.push({
|
||||
foo: 'foo'
|
||||
})
|
||||
expect(await ctx.get('foo')).to.equal('foo')
|
||||
expect(await ctx.get('bar')).to.equal('bar')
|
||||
expect(ctx.get('foo')).to.equal('foo')
|
||||
expect(ctx.get('bar')).to.equal('bar')
|
||||
})
|
||||
it('should hide deep properties by push', async function () {
|
||||
ctx.push({ bar: { bar: 'bar' } })
|
||||
ctx.push({ bar: { foo: 'foo' } })
|
||||
expect(await ctx.get('bar.foo')).to.equal('foo')
|
||||
expect(await ctx.get('bar.bar')).to.equal(undefined)
|
||||
expect(ctx.get('bar.foo')).to.equal('foo')
|
||||
expect(ctx.get('bar.bar')).to.equal(undefined)
|
||||
})
|
||||
})
|
||||
describe('.pop()', function () {
|
||||
@@ -181,7 +180,7 @@ describe('scope', function () {
|
||||
foo: 'foo'
|
||||
})
|
||||
ctx.pop()
|
||||
expect(await ctx.get('foo')).to.equal('zoo')
|
||||
expect(ctx.get('foo')).to.equal('zoo')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { expect } from 'chai'
|
||||
import Tokenizer from '../../../src/parser/tokenizer'
|
||||
import TagToken from '../../../src/parser/tag-token'
|
||||
import OutputToken from '../../../src/parser/output-token'
|
||||
import HTMLToken from '../../../src/parser/html-token'
|
||||
import { Tokenizer } from '../../../src/parser/tokenizer'
|
||||
import { TagToken } from '../../../src/parser/tag-token'
|
||||
import { OutputToken } from '../../../src/parser/output-token'
|
||||
import { HTMLToken } from '../../../src/parser/html-token'
|
||||
|
||||
describe('tokenizer', function () {
|
||||
const tokenizer = new Tokenizer()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { expect } from 'chai'
|
||||
import Context from '../../../src/context/context'
|
||||
import Token from '../../../src/parser/token'
|
||||
import Tag from '../../../src/template/tag/tag'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import { Token } from '../../../src/parser/token'
|
||||
import { Tag } from '../../../src/template/tag/tag'
|
||||
import { Filter } from '../../../src/template/filter/filter'
|
||||
import Render from '../../../src/render/render'
|
||||
import HTML from '../../../src/template/html'
|
||||
import { Render } from '../../../src/render/render'
|
||||
import { HTML } from '../../../src/template/html'
|
||||
|
||||
describe('render', function () {
|
||||
let render: Render
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Context from '../../../src/context/context'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import { expect } from 'chai'
|
||||
import { evalExp, evalValue, isTruthy } from '../../../src/render/syntax'
|
||||
|
||||
@@ -62,7 +62,7 @@ describe('render/syntax', function () {
|
||||
|
||||
describe('.evalExp()', function () {
|
||||
it('should throw when scope undefined', async function () {
|
||||
return expect((evalExp as any)('')).to.be.rejectedWith(/scope undefined/)
|
||||
return expect(() => (evalExp as any)('')).to.throw(/scope undefined/)
|
||||
})
|
||||
|
||||
it('should eval simple expression', async function () {
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as chai from 'chai'
|
||||
import * as sinon from 'sinon'
|
||||
import * as sinonChai from 'sinon-chai'
|
||||
import { Filter } from '../../../../src/template/filter/filter'
|
||||
import Context from '../../../../src/context/context'
|
||||
import { Context } from '../../../../src/context/context'
|
||||
|
||||
chai.use(sinonChai)
|
||||
const expect = chai.expect
|
||||
@@ -14,7 +14,7 @@ describe('filter', function () {
|
||||
ctx = new Context()
|
||||
})
|
||||
it('should create default filter if not registered', async function () {
|
||||
const result = new Filter('foo', [], false)
|
||||
const result = new Filter('foo', [], false) as any
|
||||
expect(result.name).to.equal('foo')
|
||||
})
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import * as chai from 'chai'
|
||||
import Context from '../../../src/context/context'
|
||||
import Output from '../../../src/template/output'
|
||||
import OutputToken from '../../../src/parser/output-token'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import { Output } from '../../../src/template/output'
|
||||
import { OutputToken } from '../../../src/parser/output-token'
|
||||
import { Filter } from '../../../src/template/filter/filter'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Output', function () {
|
||||
const emitter = { write: (html: string) => (emitter.html += html), html: '' }
|
||||
beforeEach(function () {
|
||||
Filter.clear()
|
||||
emitter.html = ''
|
||||
})
|
||||
|
||||
it('should stringify objects', async function () {
|
||||
@@ -16,25 +18,25 @@ describe('Output', function () {
|
||||
foo: { obj: { arr: ['a', 2] } }
|
||||
})
|
||||
const output = new Output({ value: 'foo' } as OutputToken, false)
|
||||
const html = await output.render(scope)
|
||||
return expect(html).to.equal('[object Object]')
|
||||
await output.render(scope, emitter)
|
||||
return expect(emitter.html).to.equal('[object Object]')
|
||||
})
|
||||
it('should skip function property', async function () {
|
||||
const scope = new Context({ obj: { foo: 'foo', bar: (x: any) => x } })
|
||||
const output = new Output({ value: 'obj' } as OutputToken, false)
|
||||
const html = await output.render(scope)
|
||||
return expect(html).to.equal('[object Object]')
|
||||
await output.render(scope, emitter)
|
||||
return expect(emitter.html).to.equal('[object Object]')
|
||||
})
|
||||
it('should respect to .toString()', async () => {
|
||||
const scope = new Context({ obj: { toString: () => 'FOO' } })
|
||||
const output = new Output({ value: 'obj' } as OutputToken, false)
|
||||
const str = await output.render(scope)
|
||||
return expect(str).to.equal('FOO')
|
||||
await output.render(scope, emitter)
|
||||
return expect(emitter.html).to.equal('FOO')
|
||||
})
|
||||
it('should respect to .toString()', async () => {
|
||||
const scope = new Context({ obj: { toString: () => 'FOO' } })
|
||||
const output = new Output({ value: 'obj' } as OutputToken, false)
|
||||
const str = await output.render(scope)
|
||||
return expect(str).to.equal('FOO')
|
||||
await output.render(scope, emitter)
|
||||
return expect(emitter.html).to.equal('FOO')
|
||||
})
|
||||
})
|
||||
|
||||
+14
-10
@@ -1,10 +1,10 @@
|
||||
import * as chai from 'chai'
|
||||
import Tag from '../../../src/template/tag/tag'
|
||||
import Context from '../../../src/context/context'
|
||||
import { Tag } from '../../../src/template/tag/tag'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import * as sinon from 'sinon'
|
||||
import * as sinonChai from 'sinon-chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import TagToken from '../../../src/parser/tag-token'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { TagToken } from '../../../src/parser/tag-token'
|
||||
|
||||
chai.use(sinonChai)
|
||||
const expect = chai.expect
|
||||
@@ -12,6 +12,7 @@ const liquid = new Liquid()
|
||||
|
||||
describe('tag', function () {
|
||||
let ctx: Context
|
||||
const emitter = { write: (html: string) => (emitter.html += html), html: '' }
|
||||
before(function () {
|
||||
ctx = new Context({
|
||||
foo: 'bar',
|
||||
@@ -22,6 +23,9 @@ describe('tag', function () {
|
||||
})
|
||||
Tag.clear()
|
||||
})
|
||||
beforeEach(function () {
|
||||
emitter.html = ''
|
||||
})
|
||||
|
||||
it('should throw when not registered', function () {
|
||||
expect(function () {
|
||||
@@ -51,7 +55,7 @@ describe('tag', function () {
|
||||
value: 'foo',
|
||||
name: 'foo'
|
||||
} as TagToken
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.called
|
||||
})
|
||||
|
||||
@@ -70,29 +74,29 @@ describe('tag', function () {
|
||||
} as TagToken
|
||||
})
|
||||
it('should call tag.render with scope', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch(ctx)
|
||||
})
|
||||
it('should resolve identifier hash', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch({}, {
|
||||
aa: 'bar'
|
||||
})
|
||||
})
|
||||
it('should accept space between key/value', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch({}, {
|
||||
bb: 2
|
||||
})
|
||||
})
|
||||
it('should resolve number value hash', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch(ctx, {
|
||||
cc: 2.3
|
||||
})
|
||||
})
|
||||
it('should resolve property access hash', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch(ctx, {
|
||||
dd: 'uoo'
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as chai from 'chai'
|
||||
import * as sinonChai from 'sinon-chai'
|
||||
import * as sinon from 'sinon'
|
||||
import Context from '../../../src/context/context'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import { Filter } from '../../../src/template/filter/filter'
|
||||
import Value from '../../../src/template/value'
|
||||
import { Value } from '../../../src/template/value'
|
||||
|
||||
chai.use(sinonChai)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as chai from 'chai'
|
||||
import assert from '../../../src/util/assert'
|
||||
import { assert } from '../../../src/util/assert'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
|
||||
Reference in New Issue
Block a user