feat: implement liquid and echo tags, see #428

This commit is contained in:
James Prior
2021-12-19 21:09:26 +08:00
committed by Jun Yang
parent 5b2ea63b14
commit fde9924ee6
9 changed files with 243 additions and 1 deletions
+25
View File
@@ -11,6 +11,7 @@ import { OutputToken } from '../../../src/tokens/output-token'
import { HTMLToken } from '../../../src/tokens/html-token'
import { createTrie } from '../../../src/util/operator-trie'
import { defaultOperators } from '../../../src/types'
import { LiquidTagToken } from '../../../src/tokens/liquid-tag-token'
describe('Tokenizer', function () {
const trie = createTrie(defaultOperators)
@@ -500,4 +501,28 @@ describe('Tokenizer', function () {
expect(rhs.getText()).to.deep.equal('"\\""')
})
})
describe('#readLiquidTagTokens', () => {
it('should read newline terminated tokens', () => {
const tokenizer = new Tokenizer('echo \'hello\'', trie)
const tokens = tokenizer.readLiquidTagTokens()
expect(tokens.length).to.equal(1)
const tag = tokens[0]
expect(tag).instanceOf(LiquidTagToken)
expect(tag.name).to.equal('echo')
expect(tag.args).to.equal('\'hello\'')
})
it('should gracefully handle empty lines', () => {
const tokenizer = new Tokenizer(`
echo 'hello'
decrement foo
`, trie)
const tokens = tokenizer.readLiquidTagTokens()
expect(tokens.length).to.equal(2)
})
it('should throw if line does not start with an identifier', () => {
const tokenizer = new Tokenizer('!', trie)
expect(() => tokenizer.readLiquidTagTokens()).to.throw(/illegal liquid tag syntax/)
})
})
})