github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/op/check/api_test.go (about) 1 package check 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_ValueTypeAlwaysNotNil(t *testing.T) { 10 emptyString := "" 11 ref := &emptyString 12 assert.False(t, Nil(ref)) 13 ref = nil 14 assert.True(t, Nil(ref)) 15 } 16 17 func Test_NilIsNil(t *testing.T) { 18 assert.False(t, NotNil[interface{}](nil)) 19 assert.True(t, Nil[interface{}](nil)) 20 } 21 22 func Test_RealNil(t *testing.T) { 23 assert.True(t, Nil[*string]((nil))) 24 assert.True(t, Nil((*string)(nil))) 25 assert.True(t, Nil((*int)(nil))) 26 assert.True(t, Nil[*int](nil)) 27 assert.False(t, NotNil[*int](nil)) 28 } 29 30 func Test_NilStruct(t *testing.T) { 31 32 type someStruct struct{ somField string } 33 34 v := someStruct{somField: "someValue"} 35 36 r := &v 37 38 assert.False(t, Nil(&v)) 39 assert.True(t, NotNil(r)) 40 r = nil 41 assert.True(t, Nil(r)) 42 assert.True(t, Nil[*someStruct](nil)) 43 44 var i interface{} 45 assert.False(t, Nil(&i)) 46 } 47 48 func Test_ZeroStruct(t *testing.T) { 49 type someStruct struct{ somField []string } 50 51 var v someStruct 52 assert.True(t, Zero(v)) 53 54 }