Skip to content

Commit 5af0fc0

Browse files
committed
- Testing: Improve coverage
1 parent 83526fe commit 5af0fc0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/test.slice.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,38 @@ describe('JSONPath - slice', function () {
88
const result = jsonpath({json, path: '$.children[1:3]', wrap: false});
99
assert.deepEqual(result, expected);
1010
});
11+
12+
it('should return objects with slice step', function () {
13+
const jsonWithChildren = {
14+
"name": "root",
15+
"children": [
16+
{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}
17+
]
18+
};
19+
const expected = [
20+
{a: 2}, {a: 4}, {a: 6}
21+
];
22+
const result = jsonpath({
23+
json: jsonWithChildren,
24+
path: '$.children[1:6:2]'
25+
});
26+
assert.deepEqual(result, expected);
27+
});
28+
29+
it('should return objects with negative end slice', function () {
30+
const jsonWithChildren = {
31+
"name": "root",
32+
"children": [
33+
{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}
34+
]
35+
};
36+
const expected = [
37+
{a: 2}, {a: 3}
38+
];
39+
const result = jsonpath({
40+
json: jsonWithChildren,
41+
path: '$.children[1:-3]'
42+
});
43+
assert.deepEqual(result, expected);
44+
});
1145
});

0 commit comments

Comments
 (0)