forked from JSONPath-Plus/JSONPath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.properties.js
More file actions
51 lines (43 loc) · 1.64 KB
/
Copy pathtest.properties.js
File metadata and controls
51 lines (43 loc) · 1.64 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
/*global require, module*/
/*eslint-disable quotes*/
(function () {'use strict';
var jsonpath = require('../'),
testCase = require('nodeunit').testCase;
var 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"}
]
};
module.exports = testCase({
// ============================================================================
'Periods within properties': function (test) {
// ============================================================================
test.expect(1);
var expected = {"test7": "value"};
var result = jsonpath({json: json, path: "$.test1.test2['test3.test4.test5']", wrap: false});
test.deepEqual(expected, result);
test.done();
},
// ============================================================================
'At signs within properties': function (test) {
// ============================================================================
test.expect(3);
var result = jsonpath({json: json, path: "$.datafield[?(@.tag=='035')]", wrap: false});
test.deepEqual(json.datafield[0], result);
result = jsonpath({json: json, path: "$.datafield[?(@['@tag']=='042')]", wrap: false});
test.deepEqual(json.datafield[1], result);
result = jsonpath({json: json, path: "$.datafield[2][(@['@tag'])]", wrap: false});
test.deepEqual(json.datafield[2]['045'], result);
test.done();
}
});
}());