github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/val_decoder_native_ptr_test.go (about) 1 package jzon 2 3 import ( 4 "io" 5 "runtime/debug" 6 "testing" 7 ) 8 9 func TestValDecoder_Native_Ptr(t *testing.T) { 10 f := func(t *testing.T, data string, ex error, p1, p2 interface{}) { 11 t.Log(">>>>> initValues >>>>>") 12 printValue(t, "p1", p1) 13 printValue(t, "p2", p2) 14 t.Log(">>>>>>>>>>>>>>>>>>>>>>") 15 checkDecodeWithStandard(t, DefaultDecoderConfig, data, ex, p1, p2) 16 t.Log("<<<<< initValues <<<<<") 17 printValue(t, "p1", p1) 18 printValue(t, "p2", p2) 19 t.Log("<<<<<<<<<<<<<<<<<<<<<<") 20 } 21 t.Run("nil pointer", func(t *testing.T) { 22 f(t, "null", ErrNilPointerReceiver, (*int)(nil), (*int)(nil)) 23 }) 24 t.Run("eof", func(t *testing.T) { 25 pi1 := (*int)(nil) 26 pi2 := (*int)(nil) 27 f(t, "", io.EOF, &pi1, &pi2) 28 }) 29 t.Run("invalid null", func(t *testing.T) { 30 pi1 := (*int)(nil) 31 pi2 := (*int)(nil) 32 f(t, "nul", io.EOF, &pi1, &pi2) 33 }) 34 t.Run("null 1", func(t *testing.T) { 35 pi1 := (*int)(nil) 36 pi2 := (*int)(nil) 37 f(t, "null", nil, &pi1, &pi2) 38 }) 39 t.Run("null 2", func(t *testing.T) { 40 i1 := 1 41 i2 := 1 42 pi1 := &i1 43 pi2 := &i2 44 f(t, "null", nil, &pi1, &pi2) 45 }) 46 t.Run("not null error 1", func(t *testing.T) { 47 pi1 := (*int)(nil) 48 pi2 := (*int)(nil) 49 f(t, `true`, InvalidDigitError{}, &pi1, &pi2) 50 }) 51 t.Run("not null error 2", func(t *testing.T) { 52 i1 := 1 53 i2 := 1 54 pi1 := &i1 55 pi2 := &i2 56 f(t, `true`, InvalidDigitError{}, &pi1, &pi2) 57 }) 58 t.Run("not null 1", func(t *testing.T) { 59 pi1 := (*int)(nil) 60 pi2 := (*int)(nil) 61 f(t, `23`, nil, &pi1, &pi2) 62 }) 63 t.Run("not null 2", func(t *testing.T) { 64 i1 := 1 65 i2 := 1 66 pi1 := &i1 67 pi2 := &i2 68 f(t, `23`, nil, &pi1, &pi2) 69 }) 70 debug.FreeOSMemory() 71 }