forked from mirror/go-json
Fix test code for debug
This commit is contained in:
parent
75d7b8e673
commit
e0812246ef
|
@ -1786,15 +1786,16 @@ func equalError(a, b error) bool {
|
||||||
|
|
||||||
func TestUnmarshal(t *testing.T) {
|
func TestUnmarshal(t *testing.T) {
|
||||||
for i, tt := range unmarshalTests {
|
for i, tt := range unmarshalTests {
|
||||||
|
t.Run(fmt.Sprintf("%d_%q", i, tt.in), func(t *testing.T) {
|
||||||
in := []byte(tt.in)
|
in := []byte(tt.in)
|
||||||
if tt.ptr == nil {
|
if tt.ptr == nil {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
typ := reflect.TypeOf(tt.ptr)
|
typ := reflect.TypeOf(tt.ptr)
|
||||||
if typ.Kind() != reflect.Ptr {
|
if typ.Kind() != reflect.Ptr {
|
||||||
t.Errorf("#%d: unmarshalTest.ptr %T is not a pointer type", i, tt.ptr)
|
t.Errorf("#%d: unmarshalTest.ptr %T is not a pointer type", i, tt.ptr)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
typ = typ.Elem()
|
typ = typ.Elem()
|
||||||
|
|
||||||
|
@ -1809,7 +1810,7 @@ func TestUnmarshal(t *testing.T) {
|
||||||
// what they should. To test decoding into existing
|
// what they should. To test decoding into existing
|
||||||
// data, see TestPrefilled.
|
// data, see TestPrefilled.
|
||||||
t.Errorf("#%d: unmarshalTest.ptr %#v is not a pointer to a zero value", i, tt.ptr)
|
t.Errorf("#%d: unmarshalTest.ptr %#v is not a pointer to a zero value", i, tt.ptr)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dec := json.NewDecoder(bytes.NewReader(in))
|
dec := json.NewDecoder(bytes.NewReader(in))
|
||||||
|
@ -1821,9 +1822,9 @@ func TestUnmarshal(t *testing.T) {
|
||||||
}
|
}
|
||||||
if err := dec.Decode(v.Interface()); !equalError(err, tt.err) {
|
if err := dec.Decode(v.Interface()); !equalError(err, tt.err) {
|
||||||
t.Errorf("#%d: %v, want %v", i, err, tt.err)
|
t.Errorf("#%d: %v, want %v", i, err, tt.err)
|
||||||
continue
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(v.Elem().Interface(), tt.out) {
|
if !reflect.DeepEqual(v.Elem().Interface(), tt.out) {
|
||||||
t.Errorf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, v.Elem().Interface(), tt.out)
|
t.Errorf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, v.Elem().Interface(), tt.out)
|
||||||
|
@ -1831,7 +1832,7 @@ func TestUnmarshal(t *testing.T) {
|
||||||
println(string(data))
|
println(string(data))
|
||||||
data, _ = json.Marshal(tt.out)
|
data, _ = json.Marshal(tt.out)
|
||||||
println(string(data))
|
println(string(data))
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check round trip also decodes correctly.
|
// Check round trip also decodes correctly.
|
||||||
|
@ -1839,7 +1840,7 @@ func TestUnmarshal(t *testing.T) {
|
||||||
enc, err := json.Marshal(v.Interface())
|
enc, err := json.Marshal(v.Interface())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("#%d: error re-marshaling: %v", i, err)
|
t.Errorf("#%d: error re-marshaling: %v", i, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if tt.golden && !bytes.Equal(enc, in) {
|
if tt.golden && !bytes.Equal(enc, in) {
|
||||||
t.Errorf("#%d: remarshal mismatch:\nhave: %s\nwant: %s", i, enc, in)
|
t.Errorf("#%d: remarshal mismatch:\nhave: %s\nwant: %s", i, enc, in)
|
||||||
|
@ -1851,15 +1852,16 @@ func TestUnmarshal(t *testing.T) {
|
||||||
}
|
}
|
||||||
if err := dec.Decode(vv.Interface()); err != nil {
|
if err := dec.Decode(vv.Interface()); err != nil {
|
||||||
t.Errorf("#%d: error re-unmarshaling %#q: %v", i, enc, err)
|
t.Errorf("#%d: error re-unmarshaling %#q: %v", i, enc, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(v.Elem().Interface(), vv.Elem().Interface()) {
|
if !reflect.DeepEqual(v.Elem().Interface(), vv.Elem().Interface()) {
|
||||||
t.Errorf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, v.Elem().Interface(), vv.Elem().Interface())
|
t.Errorf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, v.Elem().Interface(), vv.Elem().Interface())
|
||||||
t.Errorf(" In: %q", strings.Map(noSpace, string(in)))
|
t.Errorf(" In: %q", strings.Map(noSpace, string(in)))
|
||||||
t.Errorf("Marshal: %q", strings.Map(noSpace, string(enc)))
|
t.Errorf("Marshal: %q", strings.Map(noSpace, string(enc)))
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue