Skip to content

Commit 045dc31

Browse files
authored
Merge pull request #43 from stewart-yu/stewart-utils-pointers
add FloatPtr to pointer packages
2 parents 66066c8 + d392602 commit 045dc31

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

pointer/pointer.go

+10
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,13 @@ func BoolPtr(b bool) *bool {
7474
func StringPtr(s string) *string {
7575
return &s
7676
}
77+
78+
// Float32Ptr returns a pointer to the passed float32.
79+
func Float32Ptr(i float32) *float32 {
80+
return &i
81+
}
82+
83+
// Float64Ptr returns a pointer to the passed float64.
84+
func Float64Ptr(i float64) *float64 {
85+
return &i
86+
}

pointer/pointer_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package pointer
1818

1919
import (
20+
"fmt"
21+
"reflect"
2022
"testing"
2123
)
2224

@@ -59,8 +61,12 @@ func TestAllPtrFieldsNil(t *testing.T) {
5961
{(*struct{})(nil), true},
6062
}
6163
for i, tc := range testCases {
62-
if AllPtrFieldsNil(tc.obj) != tc.expected {
63-
t.Errorf("case[%d]: expected %t, got %t", i, tc.expected, !tc.expected)
64-
}
64+
name := fmt.Sprintf("case[%d]", i)
65+
t.Run(name, func(t *testing.T) {
66+
actualErr := AllPtrFieldsNil(tc.obj)
67+
if !reflect.DeepEqual(tc.expected, actualErr) {
68+
t.Errorf("%s: expected %t, got %t", name, tc.expected, !tc.expected)
69+
}
70+
})
6571
}
6672
}

0 commit comments

Comments
 (0)