Skip to content

Commit b155046

Browse files
committed
- Testing: Remove unneeded closures
1 parent 7d5eb1b commit b155046

18 files changed

+367
-405
lines changed

test/test.all.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
'use strict';
22

3-
(function () {
4-
const json = {
5-
"name": "root",
6-
"children": [
7-
{"name": "child1", "children": [{"name": "child1_1"}, {"name": "child1_2"}]},
8-
{"name": "child2", "children": [{"name": "child2_1"}]},
9-
{"name": "child3", "children": [{"name": "child3_1"}, {"name": "child3_2"}]}
10-
]
11-
};
12-
133
describe('JSONPath - All', function () {
4+
const json = {
5+
"name": "root",
6+
"children": [
7+
{"name": "child1", "children": [{"name": "child1_1"}, {"name": "child1_2"}]},
8+
{"name": "child2", "children": [{"name": "child2_1"}]},
9+
{"name": "child3", "children": [{"name": "child3_1"}, {"name": "child3_2"}]}
10+
]
11+
};
12+
1413
it('simple parent selection, return both path and value', () => {
1514
const result = jsonpath({json, path: '$.children[0]^', resultType: 'all'});
1615
assert.deepEqual([{path: "$['children']", value: json.children, parent: json, parentProperty: 'children', pointer: '/children'}], result);
@@ -40,4 +39,3 @@ describe('JSONPath - All', function () {
4039
assert.deepEqual([], result);
4140
});
4241
});
43-
}());

test/test.arr.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
'use strict';
22

3-
(function () {
4-
const json = {
5-
"store": {
6-
"book": {
7-
"category": "reference",
8-
"author": "Nigel Rees",
9-
"title": "Sayings of the Century",
10-
"price": [8.95, 8.94, 8.93]
11-
},
12-
"books": [{
13-
"category": "reference",
14-
"author": "Nigel Rees",
15-
"title": "Sayings of the Century",
16-
"price": [8.95, 8.94, 8.93]
17-
}]
18-
}
19-
};
20-
213
describe('JSONPath - Array', function () {
4+
const json = {
5+
"store": {
6+
"book": {
7+
"category": "reference",
8+
"author": "Nigel Rees",
9+
"title": "Sayings of the Century",
10+
"price": [8.95, 8.94, 8.93]
11+
},
12+
"books": [{
13+
"category": "reference",
14+
"author": "Nigel Rees",
15+
"title": "Sayings of the Century",
16+
"price": [8.95, 8.94, 8.93]
17+
}]
18+
}
19+
};
20+
2221
it('get single', () => {
2322
const expected = json.store.book;
2423
const result = jsonpath({json, path: 'store.book', flatten: true, wrap: false});
@@ -31,4 +30,3 @@ describe('JSONPath - Array', function () {
3130
assert.deepEqual(expected, result);
3231
});
3332
});
34-
}());

test/test.at_and_dollar.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
'use strict';
22

3-
(function () {
4-
const t1 = {
5-
simpleString: "simpleString",
6-
"@": "@asPropertyName",
7-
"a$a": "$inPropertyName",
8-
"$": {
9-
"@": "withboth"
10-
},
11-
a: {
12-
b: {
13-
c: "food"
3+
describe('JSONPath - At and Dollar sign', function () {
4+
const t1 = {
5+
simpleString: "simpleString",
6+
"@": "@asPropertyName",
7+
"a$a": "$inPropertyName",
8+
"$": {
9+
"@": "withboth"
10+
},
11+
a: {
12+
b: {
13+
c: "food"
14+
}
1415
}
15-
}
16-
};
16+
};
1717

18-
describe('JSONPath - At and Dollar sign', function () {
1918
it('test undefined, null', () => {
2019
assert.strictEqual(null, jsonpath({json: {a: null}, path: '$.a', wrap: false}));
2120
assert.strictEqual(undefined, jsonpath({json: undefined, path: 'foo'}));
@@ -33,4 +32,3 @@ describe('JSONPath - At and Dollar sign', function () {
3332
assert.strictEqual(undefined, jsonpath({json: t1, path: '\\@'})[1]);
3433
});
3534
});
36-
}());

test/test.callback.js

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
'use strict';
22

3-
(function () {
4-
const json = {
5-
"store": {
6-
"book": [{
7-
"category": "reference",
8-
"author": "Nigel Rees",
9-
"title": "Sayings of the Century",
10-
"price": 8.95
11-
},
12-
{
13-
"category": "fiction",
14-
"author": "Evelyn Waugh",
15-
"title": "Sword of Honour",
16-
"price": 12.99
17-
},
18-
{
19-
"category": "fiction",
20-
"author": "Herman Melville",
21-
"title": "Moby Dick",
22-
"isbn": "0-553-21311-3",
23-
"price": 8.99
24-
},
25-
{
26-
"category": "fiction",
27-
"author": "J. R. R. Tolkien",
28-
"title": "The Lord of the Rings",
29-
"isbn": "0-395-19395-8",
30-
"price": 22.99
31-
}],
32-
"bicycle": {
33-
"color": "red",
34-
"price": 19.95
3+
describe('JSONPath - Callback', function () {
4+
const json = {
5+
"store": {
6+
"book": [{
7+
"category": "reference",
8+
"author": "Nigel Rees",
9+
"title": "Sayings of the Century",
10+
"price": 8.95
11+
},
12+
{
13+
"category": "fiction",
14+
"author": "Evelyn Waugh",
15+
"title": "Sword of Honour",
16+
"price": 12.99
17+
},
18+
{
19+
"category": "fiction",
20+
"author": "Herman Melville",
21+
"title": "Moby Dick",
22+
"isbn": "0-553-21311-3",
23+
"price": 8.99
24+
},
25+
{
26+
"category": "fiction",
27+
"author": "J. R. R. Tolkien",
28+
"title": "The Lord of the Rings",
29+
"isbn": "0-395-19395-8",
30+
"price": 22.99
31+
}],
32+
"bicycle": {
33+
"color": "red",
34+
"price": 19.95
35+
}
3536
}
36-
}
37-
};
37+
};
3838

39-
describe('JSONPath - Callback', function () {
4039
it('Callback', () => {
4140
const expected = ['value', json.store.bicycle, {path: "$['store']['bicycle']", value: json.store.bicycle, parent: json.store, parentProperty: 'bicycle'}];
4241
let result;
@@ -57,4 +56,3 @@ describe('JSONPath - Callback', function () {
5756
assert.deepEqual(expected, result);
5857
});
5958
});
60-
}());

test/test.custom-properties.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
'use strict';
22

3-
(function () {
4-
const t1 = {
5-
b: {true: 'abc', false: 'def'},
6-
c: {true: 'qrs', false: 'tuv'}
7-
};
8-
93
describe('JSONPath - Custom properties', function () {
4+
const t1 = {
5+
b: {true: 'abc', false: 'def'},
6+
c: {true: 'qrs', false: 'tuv'}
7+
};
8+
109
it('@path for index', () => {
1110
const result = jsonpath({json: t1, path: '$.*[(@path === "$[\'b\']")]', wrap: false});
1211
assert.deepEqual(['abc', 'tuv'], result);
1312
});
1413
});
15-
}());

test/test.escaping.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
'use strict';
22

3-
(function () {
4-
const json = {
5-
'*': 'star',
6-
'rest': 'rest',
7-
'foo': 'bar'
8-
};
9-
10-
const jsonMissingSpecial = {
11-
'rest': 'rest',
12-
'foo': 'bar'
13-
};
14-
153
describe('JSONPath - Escaping', function () {
4+
const json = {
5+
'*': 'star',
6+
'rest': 'rest',
7+
'foo': 'bar'
8+
};
9+
10+
const jsonMissingSpecial = {
11+
'rest': 'rest',
12+
'foo': 'bar'
13+
};
14+
1615
it('escape *', () => {
1716
let expected = ['star'];
1817
let result = jsonpath({json, path: "$['`*']"});
@@ -43,4 +42,3 @@ describe('JSONPath - Escaping', function () {
4342
assert.deepEqual(expected, result);
4443
});
4544
});
46-
}());

test/test.eval.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
'use strict';
22

3-
(function () {
4-
const json = {
5-
"store": {
6-
"book": {
7-
"category": "reference",
8-
"author": "Nigel Rees",
9-
"title": "Sayings of the Century",
10-
"price": [8.95, 8.94]
11-
},
12-
"books": [{
13-
"category": "fiction",
14-
"author": "Evelyn Waugh",
15-
"title": "Sword of Honour",
16-
"price": [10.99, 12.29]
17-
}, {
18-
"category": "fiction",
19-
"author": "Herman Melville",
20-
"title": "Moby Dick",
21-
"isbn": "0-553-21311-3",
22-
"price": [8.99, 6.95]
23-
}]
24-
}
25-
};
26-
273
describe('JSONPath - Eval', function () {
4+
const json = {
5+
"store": {
6+
"book": {
7+
"category": "reference",
8+
"author": "Nigel Rees",
9+
"title": "Sayings of the Century",
10+
"price": [8.95, 8.94]
11+
},
12+
"books": [{
13+
"category": "fiction",
14+
"author": "Evelyn Waugh",
15+
"title": "Sword of Honour",
16+
"price": [10.99, 12.29]
17+
}, {
18+
"category": "fiction",
19+
"author": "Herman Melville",
20+
"title": "Moby Dick",
21+
"isbn": "0-553-21311-3",
22+
"price": [8.99, 6.95]
23+
}]
24+
}
25+
};
26+
2827
it('multi statement eval', () => {
2928
const expected = json.store.books[0];
3029
const selector = '$..[?(' +
@@ -93,4 +92,3 @@ describe('JSONPath - Eval', function () {
9392
});
9493
});
9594
});
96-
}());

test/test.examples.js

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
11
'use strict';
22

3-
(function () {
4-
// tests based on examples at http://goessner.net/articles/jsonpath/
5-
6-
const json = {
7-
"store": {
8-
"book": [{
9-
"category": "reference",
10-
"author": "Nigel Rees",
11-
"title": "Sayings of the Century",
12-
"price": 8.95
13-
},
14-
{
15-
"category": "fiction",
16-
"author": "Evelyn Waugh",
17-
"title": "Sword of Honour",
18-
"price": 12.99
19-
},
20-
{
21-
"category": "fiction",
22-
"author": "Herman Melville",
23-
"title": "Moby Dick",
24-
"isbn": "0-553-21311-3",
25-
"price": 8.99
26-
},
27-
{
28-
"category": "fiction",
29-
"author": "J. R. R. Tolkien",
30-
"title": "The Lord of the Rings",
31-
"isbn": "0-395-19395-8",
32-
"price": 22.99
33-
}],
34-
"bicycle": {
35-
"color": "red",
36-
"price": 19.95
3+
describe('JSONPath - Examples', function () {
4+
// tests based on examples at http://goessner.net/articles/jsonpath/
5+
const json = {
6+
"store": {
7+
"book": [{
8+
"category": "reference",
9+
"author": "Nigel Rees",
10+
"title": "Sayings of the Century",
11+
"price": 8.95
12+
},
13+
{
14+
"category": "fiction",
15+
"author": "Evelyn Waugh",
16+
"title": "Sword of Honour",
17+
"price": 12.99
18+
},
19+
{
20+
"category": "fiction",
21+
"author": "Herman Melville",
22+
"title": "Moby Dick",
23+
"isbn": "0-553-21311-3",
24+
"price": 8.99
25+
},
26+
{
27+
"category": "fiction",
28+
"author": "J. R. R. Tolkien",
29+
"title": "The Lord of the Rings",
30+
"isbn": "0-395-19395-8",
31+
"price": 22.99
32+
}],
33+
"bicycle": {
34+
"color": "red",
35+
"price": 19.95
36+
}
3737
}
38-
}
39-
};
38+
};
4039

41-
describe('JSONPath - Examples', function () {
4240
it('wildcards (with and without $.)', () => {
4341
const books = json.store.book;
4442
const expected = [books[0].author, books[1].author, books[2].author, books[3].author];
@@ -226,4 +224,3 @@ describe('JSONPath - Examples', function () {
226224
assert.deepEqual(expected, result);
227225
});
228226
});
229-
}());

0 commit comments

Comments
 (0)