1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

read to interface{}

This commit is contained in:
Tao Wen
2017-01-21 16:09:38 +08:00
parent 928bc4ce72
commit 1d29fa38ef
8 changed files with 71 additions and 40 deletions

View File

@ -8,24 +8,22 @@ import (
)
func Test_read_map(t *testing.T) {
should := require.New(t)
iter := ParseString(`{"hello": "world"}`)
m := map[string]string{"1": "2"}
iter.ReadVal(&m)
copy(iter.buf, []byte{0, 0, 0, 0, 0, 0})
if !reflect.DeepEqual(map[string]string{"1": "2", "hello": "world"}, m) {
fmt.Println(iter.Error)
t.Fatal(m)
}
should.Equal(map[string]string{"1": "2", "hello": "world"}, m)
}
func Test_read_map_of_interface(t *testing.T) {
should := require.New(t)
iter := ParseString(`{"hello": "world"}`)
m := map[string]interface{}{"1": "2"}
iter.ReadVal(&m)
if !reflect.DeepEqual(map[string]interface{}{"1": "2", "hello": "world"}, m) {
fmt.Println(iter.Error)
t.Fatal(m)
}
should.Equal(map[string]interface{}{"1": "2", "hello": "world"}, m)
iter = ParseString(`{"hello": "world"}`)
should.Equal(map[string]interface{}{"hello": "world"}, iter.Read())
}
func Test_read_map_of_any(t *testing.T) {