MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / TestJSONBuiltinEncoderFields

Function TestJSONBuiltinEncoderFields

runtime/marshal_json_test.go:151–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

149}
150
151func TestJSONBuiltinEncoderFields(t *testing.T) {
152 var m runtime.JSONBuiltin
153 for _, fixt := range builtinFieldFixtures {
154 var buf bytes.Buffer
155 enc := m.NewEncoder(&buf)
156
157 if fixt.indent != "" {
158 if e, ok := enc.(*json.Encoder); ok {
159 e.SetIndent("", fixt.indent)
160 } else {
161 // By default, JSONBuiltin.NewEncoder returns *json.Encoder as runtime.Encoder.
162 // Otherwise it's better to fail the tests than skip fixtures with non empty indent
163 t.Errorf("enc is not *json.Encoder, unable to set indentation settings. " +
164 "This failure prevents testing the correctness of indentation in JSON output.")
165 }
166 }
167
168 if err := enc.Encode(fixt.data); err != nil {
169 t.Errorf("enc.Encode(%#v) failed with %v; want success", fixt.data, err)
170 }
171
172 if got, want := buf.String(), fixt.json+"\n"; got != want {
173 t.Errorf("got = %q; want %q; data = %#v", got, want, fixt.data)
174 }
175 }
176}
177
178func TestJSONBuiltinDecoder(t *testing.T) {
179 var (

Callers

nothing calls this directly

Calls 3

NewEncoderMethod · 0.95
EncodeMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected