forked from JSONPath-Plus/JSONPath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.pointer.js
More file actions
62 lines (58 loc) · 2.11 KB
/
test.pointer.js
File metadata and controls
62 lines (58 loc) · 2.11 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
describe('JSONPath - Pointers', function () {
const json = {
"store": {
"book": [{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "reference",
"author": "Nigel Rees",
"application/vnd.wordperfect": "sotc.wpd",
"title": "Sayings of the Century"
},
{
"category": "reference",
"author": "Nigel Rees",
"application~vnd.wordperfect": "sotc.wpd",
"title": "Sayings of the Century"
}],
"bicycle": {
"color": "red",
"price": 19.95
}
}
};
it('array', () => {
const expected = [
'/store/book/0/price',
'/store/book/1/price',
'/store/bicycle/price'
];
const result = jsonpath({json, path: 'store..price', resultType: 'pointer', flatten: true});
assert.deepEqual(result, expected);
});
it('single', () => {
const expected = ['/store'];
const result = jsonpath({json, path: 'store', resultType: 'pointer', flatten: true});
assert.deepEqual(result, expected);
});
it('escape / as ~1', () => {
const expected = ['/store/book/2/application~1vnd.wordperfect'];
const result = jsonpath({json, path: "$['store']['book'][*]['application/vnd.wordperfect']", resultType: 'pointer', flatten: true});
assert.deepEqual(result, expected);
});
it('escape ~ as ~0', () => {
const expected = ['/store/book/3/application~0vnd.wordperfect'];
const result = jsonpath({json, path: "$['store']['book'][*]['application~vnd.wordperfect']", resultType: 'pointer', flatten: true});
assert.deepEqual(result, expected);
});
});