File tree Expand file tree Collapse file tree 4 files changed +20
-3
lines changed Expand file tree Collapse file tree 4 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ module github.com/flow-lab/utils
22
33go 1.20
44
5- require github.com/stretchr/testify v1.8.3
5+ require github.com/stretchr/testify v1.8.4
66
77require (
88 github.com/davecgh/go-spew v1.1.1 // indirect
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
22github.com/davecgh/go-spew v1.1.1 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
33github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
44github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
5- github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY =
6- github.com/stretchr/testify v1.8.3 /go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo =
5+ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk =
6+ github.com/stretchr/testify v1.8.4 /go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo =
77gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM =
88gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
99gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA =
Original file line number Diff line number Diff line change @@ -105,3 +105,9 @@ func Short(s string) string {
105105 }
106106 return s
107107}
108+
109+ // Ptr returns a pointer to the given value.
110+ // Useful for passing values to functions that expect pointers.
111+ func Ptr [T any ](value T ) * T {
112+ return & value
113+ }
Original file line number Diff line number Diff line change @@ -79,4 +79,15 @@ func TestUtils(t *testing.T) {
7979 assert .Equal (t , "1234" , Short ("1234" ))
8080 assert .Equal (t , "" , Short ("" ))
8181 })
82+
83+ t .Run ("Test2Ptr" , func (t * testing.T ) {
84+ var i int64 = 1234
85+ assert .Equal (t , & i , Ptr (i ))
86+ var f float32 = 1234
87+ assert .Equal (t , & f , Ptr (f ))
88+ var b bool = true
89+ assert .Equal (t , & b , Ptr (b ))
90+ var s string = "1234"
91+ assert .Equal (t , & s , Ptr (s ))
92+ })
8293}
You can’t perform that action at this time.
0 commit comments