1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-27 08:30:57 +02:00
json-iterator/any_tests/jsoniter_any_map_test.go

29 lines
772 B
Go
Raw Normal View History

2018-02-13 14:58:29 +02:00
package any_tests
2017-06-17 15:32:48 +02:00
import (
2018-02-24 16:04:41 +02:00
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
2017-06-19 17:43:53 +02:00
"testing"
2017-06-17 15:32:48 +02:00
)
func Test_wrap_map(t *testing.T) {
should := require.New(t)
2018-02-13 14:58:29 +02:00
any := jsoniter.Wrap(map[string]string{"Field1": "hello"})
2017-06-17 15:32:48 +02:00
should.Equal("hello", any.Get("Field1").ToString())
2018-02-13 14:58:29 +02:00
any = jsoniter.Wrap(map[string]string{"Field1": "hello"})
2017-06-17 15:32:48 +02:00
should.Equal(1, any.Size())
}
2018-02-14 02:28:17 +02: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), "")
}