1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-30 08:36:43 +02:00
json-iterator/jsoniter_map_test.go
2016-12-11 18:19:26 +08:00

39 lines
890 B
Go

package jsoniter
import (
"testing"
"reflect"
"fmt"
)
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)
}
}