File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import (
3030// // if not nil => panic: assertion failed: My value should be a nil pointer
3131func NilPtr [T any ](name string , value * T ) * T {
3232 lo .Assertf (value == nil , "%s should be a nil pointer" , name )
33+
3334 return value
3435}
3536
@@ -42,9 +43,10 @@ func NilPtr[T any](name string, value *T) *T {
4243// // if nil => panic: assertion failed: My value should not be a nil pointer
4344func NotNilPtr [T any ](name string , value * T ) * T {
4445 lo .Assertf (value != nil , "%s should not be a nil pointer" , name )
46+
4547 return value
4648}
4749
48- // bla
50+ // bla.
4951func _ () {
5052}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ func TestNilPtr(t *testing.T) {
1010 t .Parallel ()
1111 t .Run ("should accept nil pointer & return nil" , func (t * testing.T ) {
1212 t .Parallel ()
13+
1314 var nilPtr * int
1415 assert .Nil (t , NilPtr ("Test pointer" , nilPtr ))
1516 })
@@ -48,15 +49,18 @@ func TestNotNilPtr(t *testing.T) {
4849
4950func BenchmarkNilPtr (b * testing.B ) {
5051 b .ResetTimer ()
52+
5153 for range b .N {
5254 NilPtr ("Benchmark pointer" , (* int )(nil ))
5355 }
5456}
5557
5658func BenchmarkNotNilPtr (b * testing.B ) {
5759 value := "benchmark"
60+
5861 b .ResetTimer ()
59- for i := 0 ; i < b .N ; i ++ {
62+
63+ for range b .N {
6064 NotNilPtr ("Benchmark pointer" , & value )
6165 }
6266}
You can’t perform that action at this time.
0 commit comments