mirror of
https://github.com/json-iterator/go.git
synced 2025-04-23 11:37:32 +02:00
add failing tests for nil non-empty interfaces
This commit is contained in:
parent
92772579dd
commit
2f7e5c8dd7
@ -370,3 +370,41 @@ func Test_omitempty_nil_interface(t *testing.T) {
|
|||||||
should.Equal(nil, err)
|
should.Equal(nil, err)
|
||||||
should.Equal(string(js), str)
|
should.Equal(string(js), str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_marshal_nil_marshaler_interface(t *testing.T) {
|
||||||
|
type TestData struct {
|
||||||
|
Field json.Marshaler `json:"field"`
|
||||||
|
}
|
||||||
|
should := require.New(t)
|
||||||
|
|
||||||
|
obj := TestData{
|
||||||
|
Field: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
js, err := json.Marshal(obj)
|
||||||
|
should.Equal(nil, err)
|
||||||
|
should.Equal(`{"field":null}`, string(js))
|
||||||
|
|
||||||
|
str, err := MarshalToString(obj)
|
||||||
|
should.Equal(nil, err)
|
||||||
|
should.Equal(string(js), str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_marshal_nil_nonempty_interface(t *testing.T) {
|
||||||
|
type TestData struct {
|
||||||
|
Field MyInterface `json:"field"`
|
||||||
|
}
|
||||||
|
should := require.New(t)
|
||||||
|
|
||||||
|
obj := TestData{
|
||||||
|
Field: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
js, err := json.Marshal(obj)
|
||||||
|
should.Equal(nil, err)
|
||||||
|
should.Equal(`{"field":null}`, string(js))
|
||||||
|
|
||||||
|
str, err := MarshalToString(obj)
|
||||||
|
should.Equal(nil, err)
|
||||||
|
should.Equal(string(js), str)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user