-
-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathtest.properties.js
More file actions
67 lines (61 loc) · 2.54 KB
/
Copy pathtest.properties.js
File metadata and controls
67 lines (61 loc) · 2.54 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
63
64
65
66
67
import {checkBuiltInVMAndNodeVM} from '../test-helpers/checkVM.js';
checkBuiltInVMAndNodeVM(function (vmType, setBuiltInState) {
describe(`JSONPath - Properties (${vmType})`, function () {
before(setBuiltInState);
const json = {
"test1": {
"test2": {
"test3.test4.test5": {
"test7": "value"
}
}
},
"datafield": [
{"tag": "035", "subfield": {"@code": "a", "#text": "1879"}},
{"@tag": "042", "subfield": {"@code": "a", "#text": "5555"}},
{"@tag": "045", "045": "secret"}
]
};
it('Periods within properties', () => {
const expected = {"test7": "value"};
const result = jsonpath({json, path: "$.test1.test2['test3.test4.test5']", wrap: false});
assert.deepEqual(result, expected);
});
it('At signs within properties', () => {
let result = jsonpath({json, path: "$.datafield[?(@.tag=='035')]", wrap: false});
assert.deepEqual(result, [json.datafield[0]]);
result = jsonpath({json, path: "$.datafield[?(@['@tag']=='042')]", wrap: false});
assert.deepEqual(result, [json.datafield[1]]);
result = jsonpath({json, path: "$.datafield[2][(@['@tag'])]", wrap: false});
assert.deepEqual(result, json.datafield[2]['045']);
});
it('At signs within properties (null data)', () => {
const result = jsonpath({json: {
datafield: [null]
}, path: "$.datafield[?(@ && @.tag=='xxx')]", wrap: false});
assert.deepEqual(result, undefined);
});
it('Checking properties of child object (through `@` as parent object)', function () {
const jsonObj = {
test1: {
a: 4,
b: 8
}
};
const result = jsonpath({
json: jsonObj, path: "$.[?(@.a == 4)]", wrap: false});
assert.deepEqual(result, [jsonObj.test1]);
});
it('Checking properties of child object (through `@` as property)', function () {
const jsonObj = {
test1: {
a: 4,
b: 8
}
};
const result = jsonpath({
json: jsonObj, path: "$.[?(@property == 'a' && @ == 4)]^", wrap: false});
assert.deepEqual(result, [jsonObj.test1]);
});
});
});