-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathresolvejsonerror_test.go
More file actions
33 lines (29 loc) · 946 Bytes
/
resolvejsonerror_test.go
File metadata and controls
33 lines (29 loc) · 946 Bytes
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
package checkjson
import (
"encoding/json"
"fmt"
"testing"
)
func TestResolveJSONError(t *testing.T) {
fmt.Println("=============== TestResolveJSONError")
// this is just to view formating w/ "key" and position info
src := `{"this":{"is":["a", "test"],"of":"ResolveJSONError", "with":"a","quote":missing}}`
var m interface{}
err := json.Unmarshal([]byte(src), m)
if err == nil {
t.Fatal("JSON error not caught")
}
fmt.Println(ResolveJSONError([]byte(src), err))
src = `{"this":{"is":["a", "test"],"of":"ResolveJSONError", "with":"a","quote:missing}}`
err = json.Unmarshal([]byte(src), m)
if err == nil {
t.Fatal("JSON error not caught")
}
fmt.Println(ResolveJSONError([]byte(src), err))
src = `{"this":{"is":["a", "test"],"of":"ResolveJSONError", "with":"a", quote:missing}}`
err = json.Unmarshal([]byte(src), m)
if err == nil {
t.Fatal("JSON error not caught")
}
fmt.Println(ResolveJSONError([]byte(src), err))
}