forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liquid.js
49 lines (45 loc) · 1.38 KB
/
liquid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { liquid } = require('../../lib/render-content')
const template = `
{% if page.version ver_gt "2.13" %}up to date{% endif %}
{% if page.version ver_lt "2.13" %}out of date{% endif %}
`
describe('liquid template parser', () => {
describe('custom operators', () => {
describe('ver_gt', () => {
test('works as expected', async () => {
const context = {
page: {
version: '2.14'
}
}
const output = await liquid.parseAndRender(template, context)
expect(output.trim()).toBe('up to date')
})
test('returns false when given value is not numeric, like `dotcom`', async () => {
const context = {
page: {
version: 'dotcom'
}
}
const output = await liquid.parseAndRender(template, context)
expect(output.trim()).toBe('')
})
test('returns false when given value is falsy', async () => {
const context = {}
const output = await liquid.parseAndRender(template, context)
expect(output.trim()).toBe('')
})
})
describe('ver_lt', () => {
test('works as expected', async () => {
const context = {
page: {
version: '2.12'
}
}
const output = await liquid.parseAndRender(template, context)
expect(output.trim()).toBe('out of date')
})
})
})
})