forked from buger/jsonparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_error_test.go
40 lines (33 loc) · 941 Bytes
/
parser_error_test.go
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
package jsonparser
import (
"fmt"
"testing"
)
var testPaths = [][]string{
[]string{"test"},
[]string{"these"},
[]string{"keys"},
[]string{"please"},
}
func testIter(data []byte) (err error) {
EachKey(data, func(idx int, value []byte, vt ValueType, iterErr error) {
if iterErr != nil {
err = fmt.Errorf("Error parsing json: %s", iterErr.Error())
}
}, testPaths...)
return err
}
func TestPanickingErrors(t *testing.T) {
if err := testIter([]byte(`{"test":`)); err == nil {
t.Error("Expected error...")
}
if err := testIter([]byte(`{"test":0}some":[{"these":[{"keys":"some"}]}]}some"}]}],"please":"some"}`)); err == nil {
t.Error("Expected error...")
}
if _, _, _, err := Get([]byte(`{"test":`), "test"); err == nil {
t.Error("Expected error...")
}
if _, _, _, err := Get([]byte(`{"some":0}some":[{"some":[{"some":"some"}]}]}some"}]}],"some":"some"}`), "x"); err == nil {
t.Error("Expected error...")
}
}