func TestJSONPbEncoderFields(t *testing.T) { var m runtime.JSONPb for _, fixt := range fieldFixtures { var buf bytes.Buffer enc := m.NewEncoder(&buf) if err := enc.Encode(fixt.data); err != nil { t.Errorf("enc.Encode(%#v) failed with %v; want success", fixt.data, err) } if got, want := buf.String(), fixt.json; got != want { t.Errorf("enc.Encode(%#v) = %q; want %q", fixt.data, got, want) } } m.EnumsAsInts = true buf, err := m.Marshal(examplepb.NumericEnum_ONE) if err != nil { t.Errorf("m.Marshal(%#v) failed with %v; want success", examplepb.NumericEnum_ONE, err) } if got, want := string(buf), "1"; got != want { t.Errorf("m.Marshal(%#v) = %q; want %q", examplepb.NumericEnum_ONE, got, want) } }
func TestJSONPbMarshalFields(t *testing.T) { var m runtime.JSONPb for _, spec := range []struct { val interface{} want string }{} { buf, err := m.Marshal(spec.val) if err != nil { t.Errorf("m.Marshal(%#v) failed with %v; want success", spec.val, err) } if got, want := string(buf), spec.want; got != want { t.Errorf("m.Marshal(%#v) = %q; want %q", spec.val, got, want) } } m.EnumsAsInts = true buf, err := m.Marshal(examplepb.NumericEnum_ONE) if err != nil { t.Errorf("m.Marshal(%#v) failed with %v; want success", examplepb.NumericEnum_ONE, err) } if got, want := string(buf), "1"; got != want { t.Errorf("m.Marshal(%#v) = %q; want %q", examplepb.NumericEnum_ONE, got, want) } }