mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 05:50:43 -07:00
feat: jsonify, inspect, to_integer, normalize_whitespace filters
This commit is contained in:
@@ -30,4 +30,33 @@ describe('filters/object', function () {
|
||||
expect(liquid.parseAndRenderSync('{{obj | json: 4}}', scope)).toBe(result)
|
||||
})
|
||||
})
|
||||
describe('jsonify', function () {
|
||||
it('should stringify string', async () => expect(await liquid.parseAndRender('{{"foo" | jsonify}}')).toBe('"foo"'))
|
||||
})
|
||||
describe('inspect', function () {
|
||||
it('should inspect string', async () => expect(await liquid.parseAndRender('{{"foo" | inspect}}')).toBe('"foo"'))
|
||||
it('should inspect object', () => {
|
||||
const text = '{{foo | inspect}}'
|
||||
const foo = { bar: 'bar' }
|
||||
const expected = '{"bar":"bar"}'
|
||||
return expect(liquid.parseAndRenderSync(text, { foo })).toBe(expected)
|
||||
})
|
||||
it('should inspect cyclic object', () => {
|
||||
const text = '{{foo | inspect}}'
|
||||
const foo: any = { bar: 'bar' }
|
||||
foo.foo = foo
|
||||
const expected = '{"bar":"bar","foo":"[Circular]"}'
|
||||
return expect(liquid.parseAndRenderSync(text, { foo })).toBe(expected)
|
||||
})
|
||||
it('should support space argument', () => {
|
||||
const text = '{{foo | inspect: 4}}'
|
||||
const foo: any = { bar: 'bar' }
|
||||
foo.foo = foo
|
||||
const expected = '{\n "bar": "bar",\n "foo": "[Circular]"\n}'
|
||||
return expect(liquid.parseAndRenderSync(text, { foo })).toBe(expected)
|
||||
})
|
||||
})
|
||||
describe('to_integer', function () {
|
||||
it('should stringify string', () => expect(liquid.parseAndRenderSync('{{ "123" | to_integer | json }}')).toBe('123'))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { test } from '../../stub/render'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
|
||||
describe('filters/string', function () {
|
||||
const liquid = new Liquid()
|
||||
describe('append', function () {
|
||||
it('should return "-3abc" for -3, "abc"',
|
||||
() => test('{{ -3 | append: "abc" }}', '-3abc'))
|
||||
@@ -228,4 +230,12 @@ describe('filters/string', function () {
|
||||
'Take my protein pills and put my helmet on')
|
||||
})
|
||||
})
|
||||
describe('normalize_whitespace', () => {
|
||||
it('should replace " \n " with " "', () => {
|
||||
expect(liquid.parseAndRenderSync('{{ "a \n b" | normalize_whitespace }}')).toEqual('a b')
|
||||
})
|
||||
it('should replace multiple occurrences', () => {
|
||||
expect(liquid.parseAndRenderSync('{{ "a \n b c" | normalize_whitespace }}')).toEqual('a b c')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user