fix: throw an error if : omitted unintentionally, #212, #208

This commit is contained in:
harttle
2020-03-31 14:05:38 +08:00
parent c30766ffe1
commit 8daf281fca
14 changed files with 86 additions and 25 deletions
+8 -1
View File
@@ -1,6 +1,8 @@
import { test } from '../../../stub/render'
import { Liquid } from '../../../../src/liquid'
import { expect } from 'chai'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('filters/array', function () {
let liquid: Liquid
@@ -25,6 +27,11 @@ describe('filters/array', function () {
'{{ beatles | join }}'
return test(src, 'John Paul George Ringo')
})
it('should throw when comma missing', async () => {
const src = '{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}' +
'{{ beatles | join " and " }}'
return expect(liquid.parseAndRender(src)).to.be.rejectedWith('unexpected token at "\\" and \\"", line:1, col:65')
})
})
it('should support split/last', function () {
const src = '{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}' +
+5
View File
@@ -207,6 +207,11 @@ describe('Tokenize', function () {
expect(token).to.have.property('name', 'plus')
expect(token).to.have.property('args').to.deep.equal([])
})
it('should read null if name not found', function () {
const tokenizer = new Tokenizer('|')
const token = tokenizer.readFilter()
expect(token).to.be.null
})
it('should read a filter with k/v argument', function () {
const tokenizer = new Tokenizer(' | plus: a:1')
const token = tokenizer.readFilter()