github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/dump/test/level_1_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 "github.com/v2pro/plz/test" 6 "github.com/v2pro/plz/countlog" 7 "github.com/v2pro/plz/test/must" 8 "github.com/v2pro/plz/dump" 9 ) 10 11 func Test_level1(t *testing.T) { 12 t.Run("string", test.Case(func(ctx *countlog.Context) { 13 must.JsonEqual(`{ 14 "__root__": { 15 "type": "string", 16 "data": { 17 "__ptr__": "{ptr1}" 18 } 19 }, 20 "{ptr1}": { 21 "data": { 22 "__ptr__": "{ptr2}" 23 }, 24 "len": 5 25 }, 26 "{ptr2}": "hello"}`, dump.Var{"hello"}.String()) 27 })) 28 t.Run("struct of pointer", test.Case(func(ctx *countlog.Context) { 29 type TestObject struct { 30 Field1 *int 31 Field2 *int 32 } 33 one := 1 34 two := 2 35 obj := TestObject{&one, &two} 36 must.JsonEqual(`{ 37 "__root__":{ 38 "type":"dump_test.TestObject", 39 "data":{"__ptr__":"{ptr1}"} 40 }, 41 "{ptr1}":{ 42 "Field1":{"__ptr__":"{ptr2}"}, 43 "Field2":{"__ptr__":"{ptr3}"} 44 }, 45 "{ptr2}":1, 46 "{ptr3}":2}`, dump.Var{Object: obj}.String()) 47 })) 48 }