mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
feat: Access array item by negative index, closes #486
This commit is contained in:
@@ -227,4 +227,9 @@ describe('Issues', function () {
|
||||
const html = await engine.parseAndRender(`{{ foo | concat | json }}`)
|
||||
expect(html).to.equal('[]')
|
||||
})
|
||||
it('#486 Access array items from the right with negative indexes', async () => {
|
||||
const engine = new Liquid()
|
||||
const html = await engine.parseAndRender(`{% assign a = "x,y,z" | split: ',' -%}{{ a[-1] }} {{ a[-3] }} {{ a[-8] }}`)
|
||||
expect(html).to.equal('z x ')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -22,7 +22,8 @@ describe('Context', function () {
|
||||
zoo: 'coo',
|
||||
'Mr.Smith': 'John',
|
||||
arr: ['a', 'b']
|
||||
}
|
||||
},
|
||||
arr: ['a', 'b', 'c', 'd']
|
||||
}
|
||||
ctx = new Context(scope)
|
||||
})
|
||||
@@ -69,6 +70,12 @@ describe('Context', function () {
|
||||
it('should read .last of array', async function () {
|
||||
expect(ctx.get(['bar', 'arr', 'last'])).to.equal('b')
|
||||
})
|
||||
it('should read element of array', async function () {
|
||||
expect(ctx.get(['arr', 1])).to.equal('b')
|
||||
})
|
||||
it('should read element of array from end', async function () {
|
||||
expect(ctx.get(['arr', -2])).to.equal('c')
|
||||
})
|
||||
it('should call function', async function () {
|
||||
expect(ctx.get(['func'])).to.equal('FUNC')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user