1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-24 23:16:47 +02:00

#70 decode null to nil for map/slice

This commit is contained in:
Tao Wen
2017-06-26 10:20:49 +08:00
parent d100b0d41f
commit f771d32291
3 changed files with 31 additions and 10 deletions

View File

@ -32,7 +32,7 @@ func Test_encode_null(t *testing.T) {
should.Equal("null", str)
}
func Test_decode_null_object(t *testing.T) {
func Test_decode_null_object_field(t *testing.T) {
should := require.New(t)
iter := ParseString(ConfigDefault, `[null,"a"]`)
iter.ReadArray()
@ -51,16 +51,27 @@ func Test_decode_null_object(t *testing.T) {
should.Len(objs, 1)
}
func Test_decode_null_array(t *testing.T) {
func Test_decode_null_array_element(t *testing.T) {
should := require.New(t)
iter := ParseString(ConfigDefault, `[null,"a"]`)
iter.ReadArray()
if iter.ReadArray() != false {
t.FailNow()
}
iter.ReadArray()
if iter.ReadString() != "a" {
t.FailNow()
}
should.True(iter.ReadArray())
should.True(iter.ReadNil())
should.True(iter.ReadArray())
should.Equal("a", iter.ReadString())
}
func Test_decode_null_array(t *testing.T) {
should := require.New(t)
arr := []string{}
should.Nil(UnmarshalFromString("null", &arr))
should.Nil(arr)
}
func Test_decode_null_map(t *testing.T) {
should := require.New(t)
arr := map[string]string{}
should.Nil(UnmarshalFromString("null", &arr))
should.Nil(arr)
}
func Test_decode_null_string(t *testing.T) {