func TestJSONBuiltinDecoderFields(t *testing.T) { var m runtime.JSONBuiltin for _, fixt := range builtinFieldFixtures { r := strings.NewReader(fixt.json) dec := m.NewDecoder(r) dest := reflect.New(reflect.TypeOf(fixt.data)) if err := dec.Decode(dest.Interface()); err != nil { t.Errorf("dec.Decode(dest) failed with %v; want success; data = %q", err, fixt.json) } 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 TestJSONBuiltinDecoder(t *testing.T) { var ( m runtime.JSONBuiltin got examplepb.SimpleMessage data = `{"id": "foo"}` ) r := strings.NewReader(data) dec := m.NewDecoder(r) if err := dec.Decode(&got); err != nil { t.Errorf("m.Unmarshal(&got) failed with %v; want success", err) } want := examplepb.SimpleMessage{ Id: "foo", } if !reflect.DeepEqual(got, want) { t.Errorf("got = %v; want = %v", &got, &want) } }