(t *testing.T)
| 6 | ) |
| 7 | |
| 8 | func 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 | |
| 46 | func BenchmarkUnmarshalJSONMap(b *testing.B) { |
| 47 | cases := []struct { |
nothing calls this directly
no test coverage detected