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

Function testCycle

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

Source from the content-addressed store, hash-verified

326}
327
328func testCycle(t *testing.T, base interface{}, ff interface{}) {
329 setXValue(t, base)
330
331 buf, err := json.MarshalIndent(base, " ", " ")
332 require.NoError(t, err, "base[%T] failed to Marshal", base)
333
334 ffDst := emptyInterface(ff)
335 baseDst := emptyInterface(base)
336
337 err = json.Unmarshal(buf, ffDst)
338 errGo := json.Unmarshal(buf, baseDst)
339 if outputFileOnError && err != nil {
340 typeName := reflect.Indirect(reflect.ValueOf(base)).Type().String()
341 file, err := os.Create(fmt.Sprintf("fail-%s-unmarshal-decoder-input.json", typeName))
342 if err == nil {
343 file.Write(buf)
344 file.Close()
345 }
346 if errGo == nil {
347 file, err := os.Create(fmt.Sprintf("fail-%s-unmarshal-decoder-output-base.txt", typeName))
348 if err == nil {
349 fmt.Fprintf(file, "%#v", baseDst)
350 file.Close()
351 }
352 }
353 }
354 require.Nil(t, err, "json.Unmarshal of encoded ff[%T],\nErrors golang:%v,\nffjson:%v", ff, errGo, err)
355 require.Nil(t, errGo, "json.Unmarshal of encoded ff[%T],\nerrors golang:%v,\nffjson:%v", base, errGo, err)
356
357 require.EqualValues(t, baseDst, ffDst, "json.Unmarshal of base[%T] into ff[%T]", base, ff)
358}
359
360func testExpectedX(t *testing.T, expected interface{}, base interface{}, ff interface{}) {
361 buf, err := json.Marshal(base)

Callers 14

TestFuzzCycleFunction · 0.85
TestFuzzOmitCycleFunction · 0.85
testTypeFuzzNFunction · 0.85
TestMapStringStringFunction · 0.85
TestMapStringStringLongFunction · 0.85
testStrQuotedFunction · 0.85
testTypeFunction · 0.85
TestArrayFunction · 0.85
TestArrayPtrFunction · 0.85
TestSliceFunction · 0.85
TestSlicePtrFunction · 0.85

Calls 4

setXValueFunction · 0.85
emptyInterfaceFunction · 0.85
StringMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…