forked from JSONPath-Plus/JSONPath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.at_and_dollar.js
55 lines (50 loc) · 1.82 KB
/
test.at_and_dollar.js
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
describe('JSONPath - At and Dollar sign', function () {
const t1 = {
simpleString: "simpleString",
"@": "@asPropertyName",
"a$a": "$inPropertyName",
"$": {
"@": "withboth"
},
a: {
b: {
c: "food"
}
}
};
it('test undefined, null', () => {
assert.strictEqual(jsonpath({json: {a: null}, path: '$.a', wrap: false}), null);
assert.strictEqual(jsonpath({json: undefined, path: 'foo'}), undefined);
assert.strictEqual(jsonpath({json: null, path: 'foo'}), undefined);
assert.strictEqual(jsonpath({json: {}, path: 'foo'})[0], undefined);
assert.strictEqual(jsonpath({json: {a: 'b'}, path: 'foo'})[0], undefined);
assert.strictEqual(jsonpath({json: {a: 'b'}, path: 'foo'})[100], undefined);
});
it('test $ and @', () => {
assert.strictEqual(jsonpath({json: t1, path: '`$'})[0], t1.$);
assert.strictEqual(jsonpath({json: t1, path: 'a$a'})[0], t1.a$a);
assert.strictEqual(jsonpath({json: t1, path: '`@'})[0], t1['@']);
assert.strictEqual(jsonpath({json: t1, path: '$.`$.`@'})[0], t1.$['@']);
assert.strictEqual(jsonpath({json: t1, path: '\\@'})[1], undefined);
});
it('@ as false', () => {
const json = {
a: {
b: false
}
};
const expected = [false];
const result = jsonpath({json, path: "$..*[?(@ === false)]", wrap: false});
assert.deepEqual(result, expected);
});
it('@ as 0', function () {
const json = {
a: {
b: 0
}
};
const expected = [0];
const result = jsonpath({json, path: "$.a[?(@property === 'b' && @ < 1)]", wrap: false});
assert.deepEqual(result, expected);
});
});