1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-23 11:37:32 +02:00
json-iterator/jsoniter_map_test.go

39 lines
895 B
Go
Raw Normal View History

2016-12-11 00:38:07 +08:00
package jsoniter
import (
"fmt"
"reflect"
"testing"
2016-12-11 00:38:07 +08:00
)
func Test_read_map(t *testing.T) {
iter := ParseString(`{"hello": "world"}`)
m := map[string]string{"1": "2"}
iter.Read(&m)
copy(iter.buf, []byte{0, 0, 0, 0, 0, 0})
2016-12-11 00:38:07 +08:00
if !reflect.DeepEqual(map[string]string{"1": "2", "hello": "world"}, m) {
fmt.Println(iter.Error)
t.Fatal(m)
}
}
2016-12-11 10:04:26 +08:00
func Test_read_map_of_interface(t *testing.T) {
iter := ParseString(`{"hello": "world"}`)
m := map[string]interface{}{"1": "2"}
iter.Read(&m)
if !reflect.DeepEqual(map[string]interface{}{"1": "2", "hello": "world"}, m) {
fmt.Println(iter.Error)
t.Fatal(m)
}
}
func Test_read_map_of_any(t *testing.T) {
iter := ParseString(`{"hello": "world"}`)
2016-12-11 15:53:35 +08:00
m := map[string]Any{"1": *MakeAny("2")}
2016-12-11 10:04:26 +08:00
iter.Read(&m)
2016-12-11 15:53:35 +08:00
if !reflect.DeepEqual(map[string]Any{"1": *MakeAny("2"), "hello": *MakeAny("world")}, m) {
2016-12-11 10:04:26 +08:00
fmt.Println(iter.Error)
t.Fatal(m)
}
}