1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-26 11:42:56 +02:00

replace should.Equal(nil, err) with should.NoError(err)

This commit is contained in:
Jason Toffaletti 2017-09-16 16:30:04 -07:00
parent 48cc4d965a
commit b5d2607a6d
3 changed files with 20 additions and 20 deletions

View File

@ -92,22 +92,22 @@ func Test_bool_can_be_null(t *testing.T) {
obj := TestData{} obj := TestData{}
data1 := []byte(`{"field": true}`) data1 := []byte(`{"field": true}`)
err := Unmarshal(data1, &obj) err := Unmarshal(data1, &obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(true, obj.Field) should.Equal(true, obj.Field)
data2 := []byte(`{"field": null}`) data2 := []byte(`{"field": null}`)
err = Unmarshal(data2, &obj) err = Unmarshal(data2, &obj)
should.Equal(nil, err) should.NoError(err)
// Same behavior as stdlib, not touching the existing value. // Same behavior as stdlib, not touching the existing value.
should.Equal(true, obj.Field) should.Equal(true, obj.Field)
// Checking stdlib behavior as well // Checking stdlib behavior as well
obj2 := TestData{} obj2 := TestData{}
err = json.Unmarshal(data1, &obj2) err = json.Unmarshal(data1, &obj2)
should.Equal(nil, err) should.NoError(err)
should.Equal(true, obj2.Field) should.Equal(true, obj2.Field)
err = json.Unmarshal(data2, &obj2) err = json.Unmarshal(data2, &obj2)
should.Equal(nil, err) should.NoError(err)
should.Equal(true, obj2.Field) should.Equal(true, obj2.Field)
} }

View File

@ -40,11 +40,11 @@ func Test_custom_marshaler_on_enum(t *testing.T) {
w := Wrapper{Payload: MyEnumB} w := Wrapper{Payload: MyEnumB}
jb, err := Marshal(w) jb, err := Marshal(w)
should.Equal(nil, err) should.NoError(err)
should.Equal(`{"Payload":"foo-1"}`, string(jb)) should.Equal(`{"Payload":"foo-1"}`, string(jb))
var w2 Wrapper2 var w2 Wrapper2
err = Unmarshal(jb, &w2) err = Unmarshal(jb, &w2)
should.Equal(nil, err) should.NoError(err)
should.Equal(MyEnumB, w2.Payload) should.Equal(MyEnumB, w2.Payload)
} }

View File

@ -329,13 +329,13 @@ func Test_nil_out_null_interface(t *testing.T) {
data1 := []byte(`{"field": true}`) data1 := []byte(`{"field": true}`)
err := Unmarshal(data1, &obj) err := Unmarshal(data1, &obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(true, *(obj.Field.(*bool))) should.Equal(true, *(obj.Field.(*bool)))
data2 := []byte(`{"field": null}`) data2 := []byte(`{"field": null}`)
err = Unmarshal(data2, &obj) err = Unmarshal(data2, &obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(nil, obj.Field) should.Equal(nil, obj.Field)
// Checking stdlib behavior matches. // Checking stdlib behavior matches.
@ -344,11 +344,11 @@ func Test_nil_out_null_interface(t *testing.T) {
} }
err = json.Unmarshal(data1, &obj2) err = json.Unmarshal(data1, &obj2)
should.Equal(nil, err) should.NoError(err)
should.Equal(true, *(obj2.Field.(*bool))) should.Equal(true, *(obj2.Field.(*bool)))
err = json.Unmarshal(data2, &obj2) err = json.Unmarshal(data2, &obj2)
should.Equal(nil, err) should.NoError(err)
should.Equal(nil, obj2.Field) should.Equal(nil, obj2.Field)
} }
@ -363,11 +363,11 @@ func Test_omitempty_nil_interface(t *testing.T) {
} }
js, err := json.Marshal(obj) js, err := json.Marshal(obj)
should.Equal(nil, err) should.NoError(err)
should.Equal("{}", string(js)) should.Equal("{}", string(js))
str, err := MarshalToString(obj) str, err := MarshalToString(obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(string(js), str) should.Equal(string(js), str)
} }
@ -382,16 +382,16 @@ func Test_omitempty_nil_nonempty_interface(t *testing.T) {
} }
js, err := json.Marshal(obj) js, err := json.Marshal(obj)
should.Equal(nil, err) should.NoError(err)
should.Equal("{}", string(js)) should.Equal("{}", string(js))
str, err := MarshalToString(obj) str, err := MarshalToString(obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(string(js), str) should.Equal(string(js), str)
obj.Field = MyString("hello") obj.Field = MyString("hello")
err = UnmarshalFromString(`{"field":null}`, &obj) err = UnmarshalFromString(`{"field":null}`, &obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(nil, obj.Field) should.Equal(nil, obj.Field)
} }
@ -406,11 +406,11 @@ func Test_marshal_nil_marshaler_interface(t *testing.T) {
} }
js, err := json.Marshal(obj) js, err := json.Marshal(obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(`{"field":null}`, string(js)) should.Equal(`{"field":null}`, string(js))
str, err := MarshalToString(obj) str, err := MarshalToString(obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(string(js), str) should.Equal(string(js), str)
} }
@ -425,15 +425,15 @@ func Test_marshal_nil_nonempty_interface(t *testing.T) {
} }
js, err := json.Marshal(obj) js, err := json.Marshal(obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(`{"field":null}`, string(js)) should.Equal(`{"field":null}`, string(js))
str, err := MarshalToString(obj) str, err := MarshalToString(obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(string(js), str) should.Equal(string(js), str)
obj.Field = MyString("hello") obj.Field = MyString("hello")
err = Unmarshal(js, &obj) err = Unmarshal(js, &obj)
should.Equal(nil, err) should.NoError(err)
should.Equal(nil, obj.Field) should.Equal(nil, obj.Field)
} }