jsoniter_any_map_test.go 772 B

12345678910111213141516171819202122232425262728
  1. package any_tests
  2. import (
  3. "github.com/json-iterator/go"
  4. "github.com/stretchr/testify/require"
  5. "testing"
  6. )
  7. func Test_wrap_map(t *testing.T) {
  8. should := require.New(t)
  9. any := jsoniter.Wrap(map[string]string{"Field1": "hello"})
  10. should.Equal("hello", any.Get("Field1").ToString())
  11. any = jsoniter.Wrap(map[string]string{"Field1": "hello"})
  12. should.Equal(1, any.Size())
  13. }
  14. func Test_map_wrapper_any_get_all(t *testing.T) {
  15. should := require.New(t)
  16. any := jsoniter.Wrap(map[string][]int{"Field1": {1, 2}})
  17. should.Equal(`{"Field1":1}`, any.Get('*', 0).ToString())
  18. should.Contains(any.Keys(), "Field1")
  19. // map write to
  20. stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 0)
  21. any.WriteTo(stream)
  22. // TODO cannot pass
  23. //should.Equal(string(stream.buf), "")
  24. }