@@ -6,6 +6,12 @@ import (
6
6
7
7
// TestPointer tests the Pointer helper function with various types
8
8
func TestPointer (t * testing.T ) {
9
+ // Test nil pointer for int (should be nil if explicitly set)
10
+ nilIntPtr := Pointer [* int ](nil )
11
+ if nilIntPtr == nil || * nilIntPtr != nil {
12
+ t .Errorf ("Expected nil pointer, got %v" , nilIntPtr )
13
+ }
14
+
9
15
// Test with an integer
10
16
intValue := 11
11
17
intPtr := Pointer (intValue )
@@ -45,3 +51,66 @@ func TestPointer(t *testing.T) {
45
51
t .Errorf ("Expected %+v, got %+v" , structValue , * structPtr )
46
52
}
47
53
}
54
+
55
+ // TestDoublePointer tests the DoublePointer helper function with various types
56
+ func TestDoublePointer (t * testing.T ) {
57
+ // Test with an integer
58
+ intValue := 42
59
+ intDoublePtr := DoublePointer (intValue )
60
+ if * * intDoublePtr != intValue {
61
+ t .Errorf ("Expected %d, got %d" , intValue , * * intDoublePtr )
62
+ }
63
+
64
+ // Test with a string
65
+ strValue := "double"
66
+ strDoublePtr := DoublePointer (strValue )
67
+ if * * strDoublePtr != strValue {
68
+ t .Errorf ("Expected %s, got %s" , strValue , * * strDoublePtr )
69
+ }
70
+
71
+ // Test with a boolean
72
+ boolValue := false
73
+ boolDoublePtr := DoublePointer (boolValue )
74
+ if * * boolDoublePtr != boolValue {
75
+ t .Errorf ("Expected %t, got %t" , boolValue , * * boolDoublePtr )
76
+ }
77
+
78
+ // Test with a struct
79
+ type myStruct struct {
80
+ Field int
81
+ }
82
+ structValue := myStruct {Field : 7 }
83
+ structDoublePtr := DoublePointer (structValue )
84
+ if (* * structDoublePtr ).Field != structValue .Field {
85
+ t .Errorf ("Expected %+v, got %+v" , structValue , * * structDoublePtr )
86
+ }
87
+ }
88
+
89
+ func TestDoublePointerNull (t * testing.T ) {
90
+ // Test with an integer
91
+ intDoublePtr := DoublePointerNull [int ]()
92
+ if intDoublePtr == nil || * intDoublePtr != nil {
93
+ t .Errorf ("Expected nil pointer, got %v" , intDoublePtr )
94
+ }
95
+
96
+ // Test with a string
97
+ stringDoublePtr := DoublePointerNull [string ]()
98
+ if stringDoublePtr == nil || * stringDoublePtr != nil {
99
+ t .Errorf ("Expected nil pointer, got %v" , stringDoublePtr )
100
+ }
101
+
102
+ // Test with a boolean
103
+ boolDoublePtr := DoublePointerNull [bool ]()
104
+ if boolDoublePtr == nil || * boolDoublePtr != nil {
105
+ t .Errorf ("Expected nil pointer, got %v" , boolDoublePtr )
106
+ }
107
+
108
+ // Test with a struct
109
+ type myStruct struct {
110
+ Field int
111
+ }
112
+ structDoublePtr := DoublePointerNull [myStruct ]()
113
+ if structDoublePtr == nil || * structDoublePtr != nil {
114
+ t .Errorf ("Expected nil pointer, got %v" , structDoublePtr )
115
+ }
116
+ }
0 commit comments