(t *testing.T)
| 20 | } |
| 21 | |
| 22 | func TestJSON_Marshal(t *testing.T) { |
| 23 | tests := []struct { |
| 24 | input interface{} |
| 25 | expect string |
| 26 | options []Option |
| 27 | }{ |
| 28 | { |
| 29 | input: &testMessage{}, |
| 30 | expect: `{"a":"","b":"","c":""}`, |
| 31 | options: nil, |
| 32 | }, |
| 33 | { |
| 34 | input: &testMessage{Field1: "a", Field2: "b", Field3: "c"}, |
| 35 | expect: `{"a":"a","b":"b","c":"c"}`, |
| 36 | options: nil, |
| 37 | }, |
| 38 | { |
| 39 | input: &testMessage{Field1: "a", Field2: "b", Field3: "c"}, |
| 40 | expect: `{ |
| 41 | "a": "a", |
| 42 | "b": "b", |
| 43 | "c": "c" |
| 44 | }`, |
| 45 | options: []Option{WithIndent(" ")}, |
| 46 | }, |
| 47 | } |
| 48 | for _, v := range tests { |
| 49 | data, err := (NewCodec(v.options...)).Marshal(v.input) |
| 50 | if err != nil { |
| 51 | t.Errorf("marshal(%#v): %s", v.input, err) |
| 52 | } |
| 53 | if got, want := string(data), v.expect; got != want { |
| 54 | if strings.Contains(want, "\n") { |
| 55 | t.Errorf("marshal(%#v):\nHAVE:\n%s\nWANT:\n%s", v.input, got, want) |
| 56 | } else { |
| 57 | t.Errorf("marshal(%#v):\nhave %#q\nwant %#q", v.input, got, want) |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | func TestJSON_Unmarshal(t *testing.T) { |
| 64 | p := &testMessage{} |
nothing calls this directly
no test coverage detected