github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/utils/ptr/generic_test.go (about) 1 package ptr 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestCopy(t *testing.T) { 11 var x = 1234 12 y := Copy(&x) 13 assert.NotEqual(t, fmt.Sprintf("%p", &x), fmt.Sprintf("%p", y)) 14 assert.Equal(t, x, *y) 15 } 16 17 func TestDeref(t *testing.T) { 18 var x *int64 19 assert.Equal(t, int64(0), Deref(x)) 20 21 x = Ptr(int64(1234)) 22 assert.Equal(t, int64(1234), Deref(x)) 23 } 24 25 func TestPtr(t *testing.T) { 26 var x = 1234 27 y := Ptr(x) 28 assert.Equal(t, x, Deref(y)) 29 } 30 31 func TestNotZero(t *testing.T) { 32 ret1 := NotZero(0) 33 assert.Nil(t, ret1) 34 35 ret2 := NotZero(1234) 36 assert.NotNil(t, ret2) 37 }