func TestJSONBuiltinUnmarshalFieldKnownErrors(t *testing.T) { var m runtime.JSONBuiltin for _, fixt := range builtinKnownErrors { dest := reflect.New(reflect.TypeOf(fixt.data)) if err := m.Unmarshal([]byte(fixt.json), dest.Interface()); err == nil { t.Errorf("m.Unmarshal(%q, dest) succeeded; want ane error", fixt.json) } } }
func TestJSONBuiltinUnmarshalField(t *testing.T) { var m runtime.JSONBuiltin for _, fixt := range builtinFieldFixtures { dest := reflect.New(reflect.TypeOf(fixt.data)) if err := m.Unmarshal([]byte(fixt.json), dest.Interface()); err != nil { t.Errorf("m.Unmarshal(%q, dest) failed with %v; want success", fixt.json, err) } if got, want := dest.Elem().Interface(), fixt.data; !reflect.DeepEqual(got, want) { t.Errorf("got = %#v; want = %#v; input = %q", got, want, fixt.json) } } }
func TestJSONBuiltinsnmarshal(t *testing.T) { var ( m runtime.JSONBuiltin got examplepb.SimpleMessage data = []byte(`{"id": "foo"}`) ) if err := m.Unmarshal(data, &got); err != nil { t.Errorf("m.Unmarshal(%q, &got) failed with %v; want success", data, err) } want := examplepb.SimpleMessage{ Id: "foo", } if !reflect.DeepEqual(got, want) { t.Errorf("got = %v; want = %v", &got, &want) } }