1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-20 11:28:49 +02:00
json-iterator/any_tests/jsoniter_any_map_test.go

29 lines
772 B
Go
Raw Normal View History

2018-02-13 20:58:29 +08:00
package any_tests
2017-06-17 21:32:48 +08:00
import (
2018-02-24 22:04:41 +08:00
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
2017-06-19 23:43:53 +08:00
"testing"
2017-06-17 21:32:48 +08:00
)
func Test_wrap_map(t *testing.T) {
should := require.New(t)
2018-02-13 20:58:29 +08:00
any := jsoniter.Wrap(map[string]string{"Field1": "hello"})
2017-06-17 21:32:48 +08:00
should.Equal("hello", any.Get("Field1").ToString())
2018-02-13 20:58:29 +08:00
any = jsoniter.Wrap(map[string]string{"Field1": "hello"})
2017-06-17 21:32:48 +08:00
should.Equal(1, any.Size())
}
2018-02-14 08:28:17 +08:00
func Test_map_wrapper_any_get_all(t *testing.T) {
should := require.New(t)
any := jsoniter.Wrap(map[string][]int{"Field1": {1, 2}})
should.Equal(`{"Field1":1}`, any.Get('*', 0).ToString())
should.Contains(any.Keys(), "Field1")
// map write to
stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 0)
any.WriteTo(stream)
// TODO cannot pass
//should.Equal(string(stream.buf), "")
}