MCPcopy
hub / github.com/pquerna/ffjson / testSameMarshal

Function testSameMarshal

tests/ff_test.go:277–326  ·  view source on GitHub ↗
(t *testing.T, base interface{}, ff interface{})

Source from the content-addressed store, hash-verified

275}
276
277func testSameMarshal(t *testing.T, base interface{}, ff interface{}) {
278 bufbase, err := json.MarshalIndent(base, " ", " ")
279 require.NoError(t, err, "base[%T] failed to Marshal", base)
280
281 bufff, err := json.MarshalIndent(ff, " ", " ")
282 if err != nil {
283 msg := fmt.Sprintf("golang output:\n%s\n", string(bufbase))
284 mf, ok := ff.(json.Marshaler)
285 var raw []byte
286 if ok {
287 var err2 error
288 raw, err2 = mf.MarshalJSON()
289 msg += fmt.Sprintf("Raw output:\n%s\nErros:%v", string(raw), err2)
290 }
291 if outputFileOnError {
292 typeName := reflect.Indirect(reflect.ValueOf(base)).Type().String()
293 file, err := os.Create(fmt.Sprintf("fail-%s-marshal-go.json", typeName))
294 if err == nil {
295 file.Write(bufbase)
296 file.Close()
297 }
298 if len(raw) != 0 {
299 file, err = os.Create(fmt.Sprintf("fail-%s-marshal-ffjson-raw.json", typeName))
300 if err == nil {
301 file.Write(raw)
302 file.Close()
303 }
304 }
305 }
306 require.NoError(t, err, "ff[%T] failed to Marshal:%s", ff, msg)
307 }
308
309 if outputFileOnError {
310 if string(bufbase) != string(bufff) {
311 typeName := reflect.Indirect(reflect.ValueOf(base)).Type().String()
312 file, err := os.Create(fmt.Sprintf("fail-%s-marshal-base.json", typeName))
313 if err == nil {
314 file.Write(bufbase)
315 file.Close()
316 }
317 file, err = os.Create(fmt.Sprintf("fail-%s-marshal-ffjson.json", typeName))
318 if err == nil {
319 file.Write(bufff)
320 file.Close()
321 }
322 }
323 }
324
325 require.Equal(t, string(bufbase), string(bufff), "json.Marshal of base[%T] != ff[%T]", base, ff)
326}
327
328func testCycle(t *testing.T, base interface{}, ff interface{}) {
329 setXValue(t, base)

Callers 10

TestFuzzCycleFunction · 0.85
TestFuzzOmitCycleFunction · 0.85
TestFuzzStringCycleFunction · 0.85
testTypeFuzzNFunction · 0.85
testTypeFunction · 0.85
TestForceStringTaggedFunction · 0.85
TestSortSameFunction · 0.85
TestEmbeddedFunction · 0.85
TestInlineStructsFunction · 0.85

Calls 3

StringMethod · 0.65
MarshalJSONMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…