MCPcopy Create free account
hub / github.com/DoNewsCode/core / TestJSON_Unmarshal

Function TestJSON_Unmarshal

codec/json/json_test.go:63–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func 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}

Callers

nothing calls this directly

Calls 2

UnmarshalMethod · 0.65
MarshalMethod · 0.65

Tested by

no test coverage detected