@@ -158,6 +158,13 @@ var getTests = []GetTest{
158
158
isFound : true ,
159
159
data : `3` ,
160
160
},
161
+ GetTest {
162
+ desc : `empty key` ,
163
+ json : `{"":{"":{"":true}}}` ,
164
+ path : []string {"" , "" , "" },
165
+ isFound : true ,
166
+ data : `true` ,
167
+ },
161
168
162
169
// Escaped key tests
163
170
GetTest {
@@ -206,48 +213,54 @@ var getTests = []GetTest{
206
213
207
214
// Not found key tests
208
215
GetTest {
209
- desc : "non-existent key 1" ,
210
- json : `{"a":"b"} ` ,
211
- path : []string {"c " },
212
- isErr : true ,
216
+ desc : `empty input` ,
217
+ json : ` ` ,
218
+ path : []string {"a " },
219
+ isFound : false ,
213
220
},
214
221
GetTest {
215
- desc : "non-existent key 2 " ,
216
- json : `{"a":"b"}` ,
217
- path : []string {"b " },
218
- isErr : true ,
222
+ desc : "non-existent key 1 " ,
223
+ json : `{"a":"b"}` ,
224
+ path : []string {"c " },
225
+ isFound : false ,
219
226
},
220
227
GetTest {
221
- desc : "non-existent key 3 " ,
222
- json : `{"aa ":"b"}` ,
223
- path : []string {"a " },
224
- isErr : true ,
228
+ desc : "non-existent key 2 " ,
229
+ json : `{"a ":"b"}` ,
230
+ path : []string {"b " },
231
+ isFound : false ,
225
232
},
226
233
GetTest {
227
- desc : "apply scope of parent when search for nested key" ,
228
- json : `{"a": { "b": 1}, "c": 2 }` ,
229
- path : []string {"a" , "b" , "c " },
230
- isErr : true ,
234
+ desc : "non-existent key 3 " ,
235
+ json : `{"aa": "b"}` ,
236
+ path : []string {"a" },
237
+ isFound : false ,
231
238
},
232
239
GetTest {
233
- desc : ` apply scope to key level` ,
234
- json : `{"a": { "b": 1}, "c": 2 }` ,
235
- path : []string {"b " },
236
- isErr : true ,
240
+ desc : " apply scope of parent when search for nested key" ,
241
+ json : `{"a": { "b": 1}, "c": 2 }` ,
242
+ path : []string {"a" , "b" , "c " },
243
+ isFound : false ,
237
244
},
238
245
GetTest {
239
- desc : `handle escaped quote in key name in JSON` ,
240
- json : `{"key\"key": 1}` ,
241
- path : []string {"key" },
242
- isErr : true ,
246
+ desc : `apply scope to key level` ,
247
+ json : `{"a": { "b": 1}, "c": 2 }` ,
248
+ path : []string {"b" },
249
+ isFound : false ,
250
+ },
251
+ GetTest {
252
+ desc : `handle escaped quote in key name in JSON` ,
253
+ json : `{"key\"key": 1}` ,
254
+ path : []string {"key" },
255
+ isFound : false ,
243
256
},
244
257
245
258
// Error/invalid tests
246
259
GetTest {
247
- desc : `handle escaped quote in key name in JSON` ,
248
- json : `{"key\"key": 1}` ,
249
- path : []string {"key" },
250
- isErr : true ,
260
+ desc : `handle escaped quote in key name in JSON` ,
261
+ json : `{"key\"key": 1}` ,
262
+ path : []string {"key" },
263
+ isFound : false ,
251
264
},
252
265
GetTest {
253
266
desc : `missing closing brace, but can still find key` ,
@@ -300,10 +313,10 @@ var getTests = []GetTest{
300
313
},
301
314
302
315
GetTest { // This test returns not found instead of a parse error, as checking for the malformed JSON would reduce performance
303
- desc : "malformed key (followed by comma followed by colon)" ,
304
- json : `{"a",:1}` ,
305
- path : []string {"a" },
306
- isErr : true ,
316
+ desc : "malformed key (followed by comma followed by colon)" ,
317
+ json : `{"a",:1}` ,
318
+ path : []string {"a" },
319
+ isFound : false ,
307
320
},
308
321
GetTest { // This test returns a match instead of a parse error, as checking for the malformed JSON would reduce performance (this is not ideal)
309
322
desc : "malformed 'colon chain', lookup first string" ,
@@ -477,8 +490,8 @@ var getArrayTests = []GetTest{
477
490
// checkFoundAndNoError checks the dataType and error return from Get*() against the test case expectations.
478
491
// Returns true the test should proceed to checking the actual data returned from Get*(), or false if the test is finished.
479
492
func getTestCheckFoundAndNoError (t * testing.T , testKind string , test GetTest , jtype ValueType , value interface {}, err error ) bool {
480
- isFound := (jtype != NotExist ) && ( err != KeyPathNotFoundError )
481
- isErr := (err != nil )
493
+ isFound := (err != KeyPathNotFoundError )
494
+ isErr := (err != nil && err != KeyPathNotFoundError )
482
495
483
496
if test .isErr != isErr {
484
497
// If the call didn't match the error expectation, fail
0 commit comments