2016-12-11 00:38:07 +08:00
|
|
|
package jsoniter
|
|
|
|
|
|
|
|
import (
|
2017-01-05 21:23:08 +08:00
|
|
|
"testing"
|
2017-01-09 20:51:09 +08:00
|
|
|
"github.com/json-iterator/go/require"
|
2016-12-11 00:38:07 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_read_map(t *testing.T) {
|
2017-01-21 16:09:38 +08:00
|
|
|
should := require.New(t)
|
2016-12-11 00:38:07 +08:00
|
|
|
iter := ParseString(`{"hello": "world"}`)
|
|
|
|
m := map[string]string{"1": "2"}
|
2017-01-09 17:47:21 +08:00
|
|
|
iter.ReadVal(&m)
|
2017-01-05 21:23:08 +08:00
|
|
|
copy(iter.buf, []byte{0, 0, 0, 0, 0, 0})
|
2017-01-21 16:09:38 +08:00
|
|
|
should.Equal(map[string]string{"1": "2", "hello": "world"}, m)
|
2016-12-11 00:38:07 +08:00
|
|
|
}
|
2016-12-11 10:04:26 +08:00
|
|
|
|
|
|
|
func Test_read_map_of_interface(t *testing.T) {
|
2017-01-21 16:09:38 +08:00
|
|
|
should := require.New(t)
|
2016-12-11 10:04:26 +08:00
|
|
|
iter := ParseString(`{"hello": "world"}`)
|
|
|
|
m := map[string]interface{}{"1": "2"}
|
2017-01-09 17:47:21 +08:00
|
|
|
iter.ReadVal(&m)
|
2017-01-21 16:09:38 +08:00
|
|
|
should.Equal(map[string]interface{}{"1": "2", "hello": "world"}, m)
|
|
|
|
iter = ParseString(`{"hello": "world"}`)
|
|
|
|
should.Equal(map[string]interface{}{"hello": "world"}, iter.Read())
|
2016-12-11 10:04:26 +08:00
|
|
|
}
|
|
|
|
|
2017-01-09 20:51:09 +08:00
|
|
|
func Test_write_val_map(t *testing.T) {
|
|
|
|
should := require.New(t)
|
|
|
|
val := map[string]string{"1": "2"}
|
|
|
|
str, err := MarshalToString(val)
|
|
|
|
should.Nil(err)
|
|
|
|
should.Equal(`{"1":"2"}`, str)
|
|
|
|
}
|