-
Notifications
You must be signed in to change notification settings - Fork 446
Expand file tree
/
Copy pathparser_test.go
More file actions
816 lines (765 loc) · 19.8 KB
/
parser_test.go
File metadata and controls
816 lines (765 loc) · 19.8 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
package jsonparser
import (
"bytes"
_ "fmt"
"reflect"
"testing"
)
// Set it to non-empty value if want to run only specific test
var activeTest = ""
func toArray(data []byte) (result [][]byte) {
ArrayEach(data, func(value []byte, dataType ValueType, offset int, err error) {
result = append(result, value)
})
return
}
func toStringArray(data []byte) (result []string) {
ArrayEach(data, func(value []byte, dataType ValueType, offset int, err error) {
result = append(result, string(value))
})
return
}
type GetTest struct {
desc string
json string
path []string
isErr bool
isFound bool
data interface{}
}
var getTests = []GetTest{
// Found key tests
GetTest{
desc: "handling multiple nested keys with same name",
json: `{"a":[{"b":1},{"b":2},3],"c":{"c":[1,2]}} }`,
path: []string{"c", "c"},
isFound: true,
data: `[1,2]`,
},
GetTest{
desc: "read basic key",
json: `{"a":"b"}`,
path: []string{"a"},
isFound: true,
data: `b`,
},
GetTest{
desc: "read basic key with space",
json: `{"a": "b"}`,
path: []string{"a"},
isFound: true,
data: `b`,
},
GetTest{
desc: "read composite key",
json: `{"a": { "b":{"c":"d" }}}`,
path: []string{"a", "b", "c"},
isFound: true,
data: `d`,
},
GetTest{
desc: `read numberic value as string`,
json: `{"a": "b", "c": 1}`,
path: []string{"c"},
isFound: true,
data: `1`,
},
GetTest{
desc: `handle multiple nested keys with same name`,
json: `{"a":[{"b":1},{"b":2},3],"c":{"c":[1,2]}} }`,
path: []string{"c", "c"},
isFound: true,
data: `[1,2]`,
},
GetTest{
desc: `read string values with quotes`,
json: `{"a": "string\"with\"quotes"}`,
path: []string{"a"},
isFound: true,
data: `string\"with\"quotes`,
},
GetTest{
desc: `read object`,
json: `{"a": { "b":{"c":"d" }}}`,
path: []string{"a", "b"},
isFound: true,
data: `{"c":"d" }`,
},
GetTest{
desc: `empty path`,
json: `{"c":"d" }`,
path: []string{},
isFound: true,
data: `{"c":"d" }`,
},
GetTest{
desc: `formatted JSON value`,
json: "{\n \"a\": \"b\"\n}",
path: []string{"a"},
isFound: true,
data: `b`,
},
GetTest{
desc: `formatted JSON value 2`,
json: "{\n \"a\":\n {\n\"b\":\n {\"c\":\"d\",\n\"e\": \"f\"}\n}\n}",
path: []string{"a", "b"},
isFound: true,
data: "{\"c\":\"d\",\n\"e\": \"f\"}",
},
GetTest{
desc: `whitespace`,
json: " \n\r\t{ \n\r\t\"whitespace\" \n\r\t: \n\r\t333 \n\r\t} \n\r\t",
path: []string{"whitespace"},
isFound: true,
data: "333",
},
GetTest{
desc: `escaped backslash quote`,
json: `{"a": "\\\""}`,
path: []string{"a"},
isFound: true,
data: `\\\"`,
},
GetTest{
desc: `unescaped backslash quote`,
json: `{"a": "\\"}`,
path: []string{"a"},
isFound: true,
data: `\\`,
},
GetTest{
desc: `unicode in JSON`,
json: `{"a": "15°C"}`,
path: []string{"a"},
isFound: true,
data: `15°C`,
},
GetTest{
desc: `no padding + nested`,
json: `{"a":{"a":"1"},"b":2}`,
path: []string{"b"},
isFound: true,
data: `2`,
},
GetTest{
desc: `no padding + nested + array`,
json: `{"a":{"b":[1,2]},"c":3}`,
path: []string{"c"},
isFound: true,
data: `3`,
},
// Escaped key tests
GetTest{
desc: `key with simple escape`,
json: `{"a\\b":1}`,
path: []string{"a\\b"},
isFound: true,
data: `1`,
},
GetTest{
desc: `key with Unicode escape`,
json: `{"a\u00B0b":1}`,
path: []string{"a\u00B0b"},
isFound: true,
data: `1`,
},
GetTest{
desc: `key with complex escape`,
json: `{"a\uD83D\uDE03b":1}`,
path: []string{"a\U0001F603b"},
isFound: true,
data: `1`,
},
GetTest{ // This test returns a match instead of a parse error, as checking for the malformed JSON would reduce performance
desc: `malformed with trailing whitespace`,
json: `{"a":1 `,
path: []string{"a"},
isFound: true,
data: `1`,
},
GetTest{ // This test returns a match instead of a parse error, as checking for the malformed JSON would reduce performance
desc: `malformed with wrong closing bracket`,
json: `{"a":1]`,
path: []string{"a"},
isFound: true,
data: `1`,
},
// Not found key tests
GetTest{
desc: "non-existent key 1",
json: `{"a":"b"}`,
path: []string{"c"},
isErr: true,
},
GetTest{
desc: "non-existent key 2",
json: `{"a":"b"}`,
path: []string{"b"},
isErr: true,
},
GetTest{
desc: "non-existent key 3",
json: `{"aa":"b"}`,
path: []string{"a"},
isErr: true,
},
GetTest{
desc: "apply scope of parent when search for nested key",
json: `{"a": { "b": 1}, "c": 2 }`,
path: []string{"a", "b", "c"},
isErr: true,
},
GetTest{
desc: `apply scope to key level`,
json: `{"a": { "b": 1}, "c": 2 }`,
path: []string{"b"},
isErr: true,
},
GetTest{
desc: `handle escaped quote in key name in JSON`,
json: `{"key\"key": 1}`,
path: []string{"key"},
isErr: true,
},
// Error/invalid tests
GetTest{
desc: `handle escaped quote in key name in JSON`,
json: `{"key\"key": 1}`,
path: []string{"key"},
isErr: true,
},
GetTest{
desc: `missing closing brace, but can still find key`,
json: `{"a":"b"`,
path: []string{"a"},
isFound: true,
data: `b`,
},
GetTest{
desc: `missing value closing quote`,
json: `{"a":"b`,
path: []string{"a"},
isErr: true,
},
GetTest{
desc: `missing value closing curly brace`,
json: `{"a": { "b": "c"`,
path: []string{"a"},
isErr: true,
},
GetTest{
desc: `missing value closing square bracket`,
json: `{"a": [1, 2, 3 }`,
path: []string{"a"},
isErr: true,
},
GetTest{
desc: `missing value 1`,
json: `{"a":`,
path: []string{"a"},
isErr: true,
},
GetTest{
desc: `missing value 2`,
json: `{"a": `,
path: []string{"a"},
isErr: true,
},
GetTest{
desc: `missing value 3`,
json: `{"a":}`,
path: []string{"a"},
isErr: true,
},
GetTest{ // This test returns not found instead of a parse error, as checking for the malformed JSON would reduce performance
desc: "malformed key (followed by comma followed by colon)",
json: `{"a",:1}`,
path: []string{"a"},
isErr: true,
},
GetTest{ // This test returns a match instead of a parse error, as checking for the malformed JSON would reduce performance (this is not ideal)
desc: "malformed 'colon chain', lookup first string",
json: `{"a":"b":"c"}`,
path: []string{"a"},
isFound: true,
data: "b",
},
GetTest{ // This test returns a match instead of a parse error, as checking for the malformed JSON would reduce performance (this is not ideal)
desc: "malformed 'colon chain', lookup second string",
json: `{"a":"b":"c"}`,
path: []string{"b"},
isFound: true,
data: "c",
},
}
var getIntTests = []GetTest{
GetTest{
desc: `read numeric value as number`,
json: `{"a": "b", "c": 1}`,
path: []string{"c"},
isFound: true,
data: int64(1),
},
GetTest{
desc: `read numeric value as number in formatted JSON`,
json: "{\"a\": \"b\", \"c\": 1 \n}",
path: []string{"c"},
isFound: true,
data: int64(1),
},
}
var getFloatTests = []GetTest{
GetTest{
desc: `read numeric value as number`,
json: `{"a": "b", "c": 1.123}`,
path: []string{"c"},
isFound: true,
data: float64(1.123),
},
GetTest{
desc: `read numeric value as number in formatted JSON`,
json: "{\"a\": \"b\", \"c\": 23.41323 \n}",
path: []string{"c"},
isFound: true,
data: float64(23.41323),
},
}
var getStringTests = []GetTest{
GetTest{
desc: `Translate Unicode symbols`,
json: `{"c": "test"}`,
path: []string{"c"},
isFound: true,
data: `test`,
},
GetTest{
desc: `Translate Unicode symbols`,
json: `{"c": "15\u00b0C"}`,
path: []string{"c"},
isFound: true,
data: `15°C`,
},
GetTest{
desc: `Translate supplementary Unicode symbols`,
json: `{"c": "\uD83D\uDE03"}`, // Smiley face (UTF16 surrogate pair)
path: []string{"c"},
isFound: true,
data: "\U0001F603", // Smiley face
},
GetTest{
desc: `Translate escape symbols`,
json: `{"c": "\\\""}`,
path: []string{"c"},
isFound: true,
data: `\"`,
},
}
var getBoolTests = []GetTest{
GetTest{
desc: `read boolean true as boolean`,
json: `{"a": "b", "c": true}`,
path: []string{"c"},
isFound: true,
data: true,
},
GetTest{
desc: `boolean true in formatted JSON`,
json: "{\"a\": \"b\", \"c\": true \n}",
path: []string{"c"},
isFound: true,
data: true,
},
GetTest{
desc: `read boolean false as boolean`,
json: `{"a": "b", "c": false}`,
path: []string{"c"},
isFound: true,
data: false,
},
GetTest{
desc: `boolean true in formatted JSON`,
json: "{\"a\": \"b\", \"c\": false \n}",
path: []string{"c"},
isFound: true,
data: false,
},
GetTest{
desc: `read fake boolean true`,
json: `{"a": txyz}`,
path: []string{"a"},
isErr: true,
},
GetTest{
desc: `read fake boolean false`,
json: `{"a": fwxyz}`,
path: []string{"a"},
isErr: true,
},
GetTest{
desc: `read boolean true with whitespace and another key`,
json: "{\r\t\n \"a\"\r\t\n :\r\t\n true\r\t\n ,\r\t\n \"b\": 1}",
path: []string{"a"},
isFound: true,
data: true,
},
}
var getArrayTests = []GetTest{
GetTest{
desc: `read array of simple values`,
json: `{"a": { "b":[1,2,3,4]}}`,
path: []string{"a", "b"},
isFound: true,
data: []string{`1`, `2`, `3`, `4`},
},
GetTest{
desc: `read array via empty path`,
json: `[1,2,3,4]`,
path: []string{},
isFound: true,
data: []string{`1`, `2`, `3`, `4`},
},
GetTest{
desc: `read array of objects`,
json: `{"a": { "b":[{"x":1},{"x":2},{"x":3},{"x":4}]}}`,
path: []string{"a", "b"},
isFound: true,
data: []string{`{"x":1}`, `{"x":2}`, `{"x":3}`, `{"x":4}`},
},
GetTest{
desc: `read nested array`,
json: `{"a": [[[1]],[[2]]]}`,
path: []string{"a"},
isFound: true,
data: []string{`[[1]]`, `[[2]]`},
},
}
// checkFoundAndNoError checks the dataType and error return from Get*() against the test case expectations.
// Returns true the test should proceed to checking the actual data returned from Get*(), or false if the test is finished.
func getTestCheckFoundAndNoError(t *testing.T, testKind string, test GetTest, jtype ValueType, value interface{}, err error) bool {
isFound := (jtype != NotExist) && (err != KeyPathNotFoundError)
isErr := (err != nil)
if test.isErr != isErr {
// If the call didn't match the error expectation, fail
t.Errorf("%s test '%s' isErr mismatch: expected %t, obtained %t (err %v). Value: %v", testKind, test.desc, test.isErr, isErr, err, value)
return false
} else if isErr {
// Else, if there was an error, don't fail and don't check isFound or the value
return false
} else if test.isFound != isFound {
// Else, if the call didn't match the is-found expectation, fail
t.Errorf("%s test '%s' isFound mismatch: expected %t, obtained %t", testKind, test.desc, test.isFound, isFound)
return false
} else if !isFound {
// Else, if no value was found, don't fail and don't check the value
return false
} else {
// Else, there was no error and a value was found, so check the value
return true
}
}
func runGetTests(t *testing.T, testKind string, tests []GetTest, runner func(GetTest) (interface{}, ValueType, error), resultChecker func(GetTest, interface{}) (bool, interface{})) {
for _, test := range tests {
if activeTest != "" && test.desc != activeTest {
continue
}
// fmt.Println("Running:", test.desc)
value, dataType, err := runner(test)
if getTestCheckFoundAndNoError(t, testKind, test, dataType, value, err) {
if test.data == nil {
t.Errorf("MALFORMED TEST: %v", test)
continue
}
if ok, expected := resultChecker(test, value); !ok {
if expectedBytes, ok := expected.([]byte); ok {
expected = string(expectedBytes)
}
if valueBytes, ok := value.([]byte); ok {
value = string(valueBytes)
}
t.Errorf("%s test '%s' expected to return value %v, but did returned %v instead", testKind, test.desc, expected, value)
}
}
}
}
func TestGet(t *testing.T) {
runGetTests(t, "Get()", getTests,
func(test GetTest) (value interface{}, dataType ValueType, err error) {
value, dataType, _, err = Get([]byte(test.json), test.path...)
return
},
func(test GetTest, value interface{}) (bool, interface{}) {
expected := []byte(test.data.(string))
return bytes.Equal(expected, value.([]byte)), expected
},
)
}
func TestGetString(t *testing.T) {
runGetTests(t, "GetString()", getStringTests,
func(test GetTest) (value interface{}, dataType ValueType, err error) {
value, err = GetString([]byte(test.json), test.path...)
return value, String, err
},
func(test GetTest, value interface{}) (bool, interface{}) {
expected := test.data.(string)
return expected == value.(string), expected
},
)
}
func TestGetInt(t *testing.T) {
runGetTests(t, "GetInt()", getIntTests,
func(test GetTest) (value interface{}, dataType ValueType, err error) {
value, err = GetInt([]byte(test.json), test.path...)
return value, Number, err
},
func(test GetTest, value interface{}) (bool, interface{}) {
expected := test.data.(int64)
return expected == value.(int64), expected
},
)
}
func TestGetFloat(t *testing.T) {
runGetTests(t, "GetFloat()", getFloatTests,
func(test GetTest) (value interface{}, dataType ValueType, err error) {
value, err = GetFloat([]byte(test.json), test.path...)
return value, Number, err
},
func(test GetTest, value interface{}) (bool, interface{}) {
expected := test.data.(float64)
return expected == value.(float64), expected
},
)
}
func TestGetBoolean(t *testing.T) {
runGetTests(t, "GetBoolean()", getBoolTests,
func(test GetTest) (value interface{}, dataType ValueType, err error) {
value, err = GetBoolean([]byte(test.json), test.path...)
return value, Boolean, err
},
func(test GetTest, value interface{}) (bool, interface{}) {
expected := test.data.(bool)
return expected == value.(bool), expected
},
)
}
func TestGetSlice(t *testing.T) {
runGetTests(t, "Get()-for-arrays", getArrayTests,
func(test GetTest) (value interface{}, dataType ValueType, err error) {
value, dataType, _, err = Get([]byte(test.json), test.path...)
return
},
func(test GetTest, value interface{}) (bool, interface{}) {
expected := test.data.([]string)
return reflect.DeepEqual(expected, toStringArray(value.([]byte))), expected
},
)
}
func TestArrayEach(t *testing.T) {
mock := []byte(`{"a": { "b":[{"x": 1} ,{"x":2},{ "x":3}, {"x":4} ]}}`)
count := 0
ArrayEach(mock, func(value []byte, dataType ValueType, offset int, err error) {
count++
switch count {
case 1:
if string(value) != `{"x": 1}` {
t.Errorf("Wrong first item: %s", string(value))
}
case 2:
if string(value) != `{"x":2}` {
t.Errorf("Wrong second item: %s", string(value))
}
case 3:
if string(value) != `{ "x":3}` {
t.Errorf("Wrong third item: %s", string(value))
}
case 4:
if string(value) != `{"x":4}` {
t.Errorf("Wrong forth item: %s", string(value))
}
default:
t.Errorf("Should process only 4 items")
}
}, "a", "b")
}
var testJson = []byte(`{"name": "Name", "order": "Order", "sum": 100, "len": 12, "isPaid": true, "nested": {"a":"test", "b":2, "nested3":{"a":"test3","b":4}, "c": "unknown"}, "nested2": {"a":"test2", "b":3}, "arr": [{"a":"zxc", "b": 1}, {"a":"123", "b":2}], "arrInt": [1,2,3,4], "intPtr": 10}`)
func TestEachKey(t *testing.T) {
paths := [][]string{
[]string{"name"},
[]string{"nested", "a"},
[]string{"nested", "nested3", "b"},
}
keysFound := 0
EachKey(testJson, func(idx int, value []byte, vt ValueType, err error){
keysFound++
switch idx {
case 0:
if string(value) != "Name" {
t.Errorf("Should find 1 key")
}
case 1:
if string(value) != "test" {
t.Errorf("Should find 2 key")
}
case 2:
if string(value) != "4" {
t.Errorf("Should find 3 key")
}
default:
t.Errorf("Should found only 3 keys")
}
}, paths...)
if keysFound != 3 {
t.Errorf("Should find 3 keys: %d", keysFound)
}
}
type ParseTest struct {
in string
intype ValueType
out interface{}
isErr bool
}
var parseBoolTests = []ParseTest{
ParseTest{
in: "true",
intype: Boolean,
out: true,
},
ParseTest{
in: "false",
intype: Boolean,
out: false,
},
ParseTest{
in: "foo",
intype: Boolean,
isErr: true,
},
ParseTest{
in: "trux",
intype: Boolean,
isErr: true,
},
ParseTest{
in: "truex",
intype: Boolean,
isErr: true,
},
ParseTest{
in: "",
intype: Boolean,
isErr: true,
},
}
var parseFloatTest = []ParseTest{
ParseTest{
in: "0",
intype: Number,
out: float64(0),
},
ParseTest{
in: "0.0",
intype: Number,
out: float64(0.0),
},
ParseTest{
in: "1",
intype: Number,
out: float64(1),
},
ParseTest{
in: "1.234",
intype: Number,
out: float64(1.234),
},
ParseTest{
in: "1.234e5",
intype: Number,
out: float64(1.234e5),
},
ParseTest{
in: "-1.234e5",
intype: Number,
out: float64(-1.234e5),
},
ParseTest{
in: "+1.234e5", // Note: + sign not allowed under RFC7159, but our parser accepts it since it uses strconv.ParseFloat
intype: Number,
out: float64(1.234e5),
},
ParseTest{
in: "1.2.3",
intype: Number,
isErr: true,
},
ParseTest{
in: "1..1",
intype: Number,
isErr: true,
},
ParseTest{
in: "1a",
intype: Number,
isErr: true,
},
ParseTest{
in: "",
intype: Number,
isErr: true,
},
}
// parseTestCheckNoError checks the error return from Parse*() against the test case expectations.
// Returns true the test should proceed to checking the actual data returned from Parse*(), or false if the test is finished.
func parseTestCheckNoError(t *testing.T, testKind string, test ParseTest, value interface{}, err error) bool {
if isErr := (err != nil); test.isErr != isErr {
// If the call didn't match the error expectation, fail
t.Errorf("%s test '%s' isErr mismatch: expected %t, obtained %t (err %v). Obtained value: %v", testKind, test.in, test.isErr, isErr, err, value)
return false
} else if isErr {
// Else, if there was an error, don't fail and don't check isFound or the value
return false
} else {
// Else, there was no error and a value was found, so check the value
return true
}
}
func runParseTests(t *testing.T, testKind string, tests []ParseTest, runner func(ParseTest) (interface{}, error), resultChecker func(ParseTest, interface{}) (bool, interface{})) {
for _, test := range tests {
value, err := runner(test)
if parseTestCheckNoError(t, testKind, test, value, err) {
if test.out == nil {
t.Errorf("MALFORMED TEST: %v", test)
continue
}
if ok, expected := resultChecker(test, value); !ok {
if expectedBytes, ok := expected.([]byte); ok {
expected = string(expectedBytes)
}
if valueBytes, ok := value.([]byte); ok {
value = string(valueBytes)
}
t.Errorf("%s test '%s' expected to return value %v, but did returned %v instead", testKind, test.in, expected, value)
}
}
}
}
func TestParseBoolean(t *testing.T) {
runParseTests(t, "ParseBoolean()", parseBoolTests,
func(test ParseTest) (value interface{}, err error) {
return ParseBoolean([]byte(test.in))
},
func(test ParseTest, obtained interface{}) (bool, interface{}) {
expected := test.out.(bool)
return obtained.(bool) == expected, expected
},
)
}
func TestParseFloat(t *testing.T) {
runParseTests(t, "ParseFloat()", parseFloatTest,
func(test ParseTest) (value interface{}, err error) {
return ParseFloat([]byte(test.in))
},
func(test ParseTest, obtained interface{}) (bool, interface{}) {
expected := test.out.(float64)
return obtained.(float64) == expected, expected
},
)
}