File: jsoniter_any_map_test.go

package info (click to toggle)
golang-github-json-iterator-go 1.1.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie, trixie-proposed-updates
  • size: 916 kB
  • sloc: sh: 19; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 772 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package any_tests

import (
	"github.com/json-iterator/go"
	"github.com/stretchr/testify/require"
	"testing"
)

func Test_wrap_map(t *testing.T) {
	should := require.New(t)
	any := jsoniter.Wrap(map[string]string{"Field1": "hello"})
	should.Equal("hello", any.Get("Field1").ToString())
	any = jsoniter.Wrap(map[string]string{"Field1": "hello"})
	should.Equal(1, any.Size())
}

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), "")
}