1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-24 08:22:14 +02:00
json-iterator/jsoniter_map_test.go
2017-01-05 21:23:08 +08:00

39 lines
895 B
Go

package jsoniter
import (
"fmt"
"reflect"
"testing"
)
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})
if !reflect.DeepEqual(map[string]string{"1": "2", "hello": "world"}, m) {
fmt.Println(iter.Error)
t.Fatal(m)
}
}
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"}`)
m := map[string]Any{"1": *MakeAny("2")}
iter.Read(&m)
if !reflect.DeepEqual(map[string]Any{"1": *MakeAny("2"), "hello": *MakeAny("world")}, m) {
fmt.Println(iter.Error)
t.Fatal(m)
}
}