| 61 | } |
| 62 | |
| 63 | func TestJSON_Unmarshal(t *testing.T) { |
| 64 | p := &testMessage{} |
| 65 | tests := []struct { |
| 66 | input string |
| 67 | expect interface{} |
| 68 | }{ |
| 69 | { |
| 70 | input: `{"a":"","b":"","c":""}`, |
| 71 | expect: &testMessage{}, |
| 72 | }, |
| 73 | { |
| 74 | input: `{"a":"a","b":"b","c":"c"}`, |
| 75 | expect: &p, |
| 76 | }, |
| 77 | } |
| 78 | for _, v := range tests { |
| 79 | want := []byte(v.input) |
| 80 | err := (Codec{}).Unmarshal(want, &v.expect) |
| 81 | if err != nil { |
| 82 | t.Errorf("marshal(%#v): %s", v.input, err) |
| 83 | } |
| 84 | got, err := Codec{}.Marshal(v.expect) |
| 85 | if err != nil { |
| 86 | t.Errorf("marshal(%#v): %s", v.input, err) |
| 87 | } |
| 88 | if !bytes.Equal(got, want) { |
| 89 | t.Errorf("marshal(%#v):\nhave %#q\nwant %#q", v.input, got, want) |
| 90 | } |
| 91 | } |
| 92 | } |