github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/jsoni/any_tests/jsoniter_any_map_test.go (about) 1 package any_tests 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/bingoohuang/gg/pkg/jsoni" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func Test_wrap_map(t *testing.T) { 12 should := require.New(t) 13 any := jsoni.Wrap(map[string]string{"Field1": "hello"}) 14 should.Equal("hello", any.Get("Field1").ToString()) 15 any = jsoni.Wrap(map[string]string{"Field1": "hello"}) 16 should.Equal(1, any.Size()) 17 } 18 19 func Test_map_wrapper_any_get_all(t *testing.T) { 20 should := require.New(t) 21 any := jsoni.Wrap(map[string][]int{"Field1": {1, 2}}) 22 should.Equal(`{"Field1":1}`, any.Get('*', 0).ToString()) 23 should.Contains(any.Keys(), "Field1") 24 25 // map write to 26 stream := jsoni.NewStream(jsoni.ConfigDefault, nil, 0) 27 any.WriteTo(context.Background(), stream) 28 // TODO cannot pass 29 // should.Equal(string(stream.buf), "") 30 }