diff --git a/nodejs/test/index.spec.js b/nodejs/test/index.spec.js index e486105..0367127 100644 --- a/nodejs/test/index.spec.js +++ b/nodejs/test/index.spec.js @@ -426,6 +426,55 @@ describe('filter test', () => { done(); } }); + + it('array range with step - $[::]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[::]"); + if (JSON.stringify(result) === JSON.stringify(["first", "second", "third", "forth", "fifth"])) { + done(); + } + }); + + it('array range with step - $[::2]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[::2]"); + if (JSON.stringify(result) === JSON.stringify(["first", "third", "fifth"])) { + done(); + } + }); + + it('array range with step - $[1: :]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[1: :]"); + if (JSON.stringify(result) === JSON.stringify(["second", "third", "forth", "fifth"])) { + done(); + } + }); + + it('array range with step - $[1:2:]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[1:2:]"); + if (JSON.stringify(result) === JSON.stringify(["second"])) { + done(); + } + }); + + it('array range with step - $[1::2]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[1::2]"); + if (JSON.stringify(result) === JSON.stringify(["second", "forth"])) { + done(); + } + }); + + it('array range with step - $[0:3:1]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[0:3:1]"); + if (JSON.stringify(result) === JSON.stringify(["first", "second", "third"])) { + done(); + } + }); + + it('array range with step - $[0:3:2]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[0:3:2]"); + if (JSON.stringify(result) === JSON.stringify(["first", "third"])) { + done(); + } + }); }); describe('SelectorMut test', () => { diff --git a/wasm/tests/test/index.spec.js b/wasm/tests/test/index.spec.js index b7a05c4..8e42c6f 100644 --- a/wasm/tests/test/index.spec.js +++ b/wasm/tests/test/index.spec.js @@ -426,6 +426,55 @@ describe('filter test', () => { done(); } }); + + it('array range with step - $[::]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[::]"); + if (JSON.stringify(result) === JSON.stringify(["first", "second", "third", "forth", "fifth"])) { + done(); + } + }); + + it('array range with step - $[::2]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[::2]"); + if (JSON.stringify(result) === JSON.stringify(["first", "third", "fifth"])) { + done(); + } + }); + + it('array range with step - $[1: :]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[1: :]"); + if (JSON.stringify(result) === JSON.stringify(["second", "third", "forth", "fifth"])) { + done(); + } + }); + + it('array range with step - $[1:2:]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[1:2:]"); + if (JSON.stringify(result) === JSON.stringify(["second"])) { + done(); + } + }); + + it('array range with step - $[1::2]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[1::2]"); + if (JSON.stringify(result) === JSON.stringify(["second", "forth"])) { + done(); + } + }); + + it('array range with step - $[0:3:1]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[0:3:1]"); + if (JSON.stringify(result) === JSON.stringify(["first", "second", "third"])) { + done(); + } + }); + + it('array range with step - $[0:3:2]', (done) => { + let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[0:3:2]"); + if (JSON.stringify(result) === JSON.stringify(["first", "third"])) { + done(); + } + }); }); describe('SelectorMut test', () => {