@@ -3,80 +3,78 @@ package test
33import "testing"
44
55func Test_Misc (t * testing.T ) {
6+ batchTest (t , miscTests )
7+ }
68
7- tests := []testData {
8- {
9- query : "" , // empty
10- data : `{"a": 42, "": 21}` ,
11- expected : nil ,
12- consensus : nil ,
13- expectedError : "invalid JSONPath query '' unexpected token '' at index 0" ,
14- },
15- {
16- query : `$.data.sum()` ,
17- data : `{"data": [1,2,3,4]}` ,
18- expected : nil ,
19- consensus : consensusNone ,
20- expectedError : "key: invalid token target. expected [map] got [slice]" ,
21- },
22- {
23- query : `$(key,more)` ,
24- data : `{"key": 1, "some": 2, "more": 3}` ,
25- expected : nil ,
26- consensus : nil ,
27- expectedError : "invalid JSONPath query '$(key,more)' unexpected token '(' at index 1" ,
28- },
29- {
30- query : `$..` ,
31- data : `[{"a": {"b": "c"}}, [0, 1]]` ,
32- expected : []interface {}{[]interface {}{map [string ]interface {}{"a" : map [string ]interface {}{"b" : "c" }}, []interface {}{float64 (0 ), float64 (1 )}}, map [string ]interface {}{"a" : map [string ]interface {}{"b" : "c" }}, map [string ]interface {}{"b" : "c" }, "c" , []interface {}{float64 (0 ), float64 (1 )}, float64 (0 ), float64 (1 )},
33- consensus : consensusNone ,
34- expectedError : "" ,
35- },
36- {
37- query : `$.key..` ,
38- data : `{"some key": "value", "key": {"complex": "string", "primitives": [0, 1]}}` ,
39- expected : []interface {}{map [string ]interface {}{"complex" : "string" , "primitives" : []interface {}{float64 (0 ), float64 (1 )}}, []interface {}{float64 (0 ), float64 (1 )}, float64 (0 ), float64 (1 ), "string" },
40- consensus : consensusNone ,
41- expectedError : "" ,
42- },
43- {
44- query : `$` ,
45- data : `{ "key": "value", "another key": { "complex": [ "a", 1 ] } }` ,
46- expected : map [string ]interface {}{"key" : "value" , "another key" : map [string ]interface {}{"complex" : []interface {}{"a" , float64 (1 )}}},
47- consensus : map [string ]interface {}{"key" : "value" , "another key" : map [string ]interface {}{"complex" : []interface {}{"a" , float64 (1 )}}},
48- expectedError : "" ,
49- },
50- {
51- query : `$` ,
52- data : `42` ,
53- expected : int64 (42 ),
54- consensus : int64 (42 ),
55- expectedError : "" ,
56- },
57- {
58- query : `$` ,
59- data : `false` ,
60- expected : false ,
61- consensus : false ,
62- expectedError : "" ,
63- },
64- {
65- query : `$` ,
66- data : `true` ,
67- expected : true ,
68- consensus : true ,
69- expectedError : "" ,
70- },
71- {
72- query : `$[(@.length-1)]` ,
73- data : `["first", "second", "third", "forth", "fifth"]` ,
74- expected : "fifth" ,
75- consensus : nil ,
76- expectedError : "" ,
77- },
78- }
79-
80- batchTest (t , tests )
81- // printConsensusMatrix(tests)
9+ var miscTests []testData = []testData {
10+ {
11+ query : "" , // empty
12+ data : `{"a": 42, "": 21}` ,
13+ expected : nil ,
14+ consensus : nil ,
15+ expectedError : "invalid JSONPath query '' unexpected token '' at index 0" ,
16+ },
17+ {
18+ query : `$.data.sum()` ,
19+ data : `{"data": [1,2,3,4]}` ,
20+ expected : nil ,
21+ consensus : consensusNone ,
22+ expectedError : "key: invalid token target. expected [map] got [slice]" ,
23+ },
24+ {
25+ query : `$(key,more)` ,
26+ data : `{"key": 1, "some": 2, "more": 3}` ,
27+ expected : nil ,
28+ consensus : nil ,
29+ expectedError : "invalid JSONPath query '$(key,more)' unexpected token '(' at index 1" ,
30+ },
31+ {
32+ query : `$..` ,
33+ data : `[{"a": {"b": "c"}}, [0, 1]]` ,
34+ expected : []interface {}{[]interface {}{map [string ]interface {}{"a" : map [string ]interface {}{"b" : "c" }}, []interface {}{float64 (0 ), float64 (1 )}}, map [string ]interface {}{"a" : map [string ]interface {}{"b" : "c" }}, map [string ]interface {}{"b" : "c" }, "c" , []interface {}{float64 (0 ), float64 (1 )}, float64 (0 ), float64 (1 )},
35+ consensus : consensusNone ,
36+ expectedError : "" ,
37+ },
38+ {
39+ query : `$.key..` ,
40+ data : `{"some key": "value", "key": {"complex": "string", "primitives": [0, 1]}}` ,
41+ expected : []interface {}{map [string ]interface {}{"complex" : "string" , "primitives" : []interface {}{float64 (0 ), float64 (1 )}}, []interface {}{float64 (0 ), float64 (1 )}, float64 (0 ), float64 (1 ), "string" },
42+ consensus : consensusNone ,
43+ expectedError : "" ,
44+ },
45+ {
46+ query : `$` ,
47+ data : `{ "key": "value", "another key": { "complex": [ "a", 1 ] } }` ,
48+ expected : map [string ]interface {}{"key" : "value" , "another key" : map [string ]interface {}{"complex" : []interface {}{"a" , float64 (1 )}}},
49+ consensus : map [string ]interface {}{"key" : "value" , "another key" : map [string ]interface {}{"complex" : []interface {}{"a" , float64 (1 )}}},
50+ expectedError : "" ,
51+ },
52+ {
53+ query : `$` ,
54+ data : `42` ,
55+ expected : int64 (42 ),
56+ consensus : int64 (42 ),
57+ expectedError : "" ,
58+ },
59+ {
60+ query : `$` ,
61+ data : `false` ,
62+ expected : false ,
63+ consensus : false ,
64+ expectedError : "" ,
65+ },
66+ {
67+ query : `$` ,
68+ data : `true` ,
69+ expected : true ,
70+ consensus : true ,
71+ expectedError : "" ,
72+ },
73+ {
74+ query : `$[(@.length-1)]` ,
75+ data : `["first", "second", "third", "forth", "fifth"]` ,
76+ expected : "fifth" ,
77+ consensus : nil ,
78+ expectedError : "" ,
79+ },
8280}
0 commit comments