fix: reverse filter not pure, see #126

This commit is contained in:
Jun Yang
2019-05-19 13:58:11 +08:00
parent 224679a7d7
commit 505c408a85
2 changed files with 18 additions and 4 deletions
+17 -3
View File
@@ -1,6 +1,12 @@
import { test } from '../../../stub/render'
import Liquid from '../../../../src/liquid'
import {expect} from 'chai'
describe('filters/array', function () {
let liquid: Liquid
beforeEach(function () {
liquid = new Liquid()
})
describe('join', function () {
it('should support join', function () {
const src = '{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}' +
@@ -21,9 +27,17 @@ describe('filters/array', function () {
it('should support map', function () {
return test('{{posts | map: "category"}}', 'foo,bar')
})
it('should support reverse', function () {
return test('{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}',
'.moT rojaM ot lortnoc dnuorG')
describe('reverse', function () {
it('should support reverse', async function () {
const html = await liquid.parseAndRender('{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}')
expect(html).to.equal('.moT rojaM ot lortnoc dnuorG')
})
it('should be pure', async function () {
const scope = {arr: ['a', 'b', 'c']}
await liquid.parseAndRender('{{ arr | reverse | join: "" }}', scope)
const html = await liquid.parseAndRender('{{ arr | join: "" }}', scope)
expect(html).to.equal('abc')
})
})
describe('size', function () {
it('should return string length',