MCPcopy Create free account
hub / github.com/chain/txvm / TestMarshalJSONMap

Function TestMarshalJSONMap

encoding/json/json_test.go:8–44  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestMarshalJSONMap(t *testing.T) {
9 cases := []struct {
10 testName string
11 input Map
12 want []byte
13 }{
14 {
15 testName: "test nil map",
16 input: nil,
17 want: []byte("{}"),
18 },
19 {
20 testName: "test empty map",
21 input: Map{},
22 want: []byte("{}"),
23 },
24 {
25 testName: "populated map",
26 input: Map("i am a map"),
27 want: []byte("i am a map"),
28 },
29 }
30
31 for _, tc := range cases {
32 t.Run(tc.testName, func(t *testing.T) {
33 out, err := tc.input.MarshalJSON()
34
35 if err != nil {
36 t.Errorf("unexpected err %v", err)
37 }
38
39 if !bytes.Equal(out, tc.want) {
40 t.Errorf("marshalJSON(%v)=%s, want:%s", tc.input, out, tc.want)
41 }
42 })
43 }
44}
45
46func BenchmarkUnmarshalJSONMap(b *testing.B) {
47 cases := []struct {

Callers

nothing calls this directly

Calls 3

MapTypeAlias · 0.85
EqualMethod · 0.80
MarshalJSONMethod · 0.45

Tested by

no test coverage detected