-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package utils | ||
|
||
func StringPointer(s string) *string { | ||
return &s | ||
} | ||
|
||
func IntPointer(i int) *int { | ||
return &i | ||
} | ||
|
||
func BoolPointer(b bool) *bool { | ||
return &b | ||
} | ||
|
||
func Float64Pointer(f float64) *float64 { | ||
return &f | ||
} | ||
|
||
func Float32Pointer(f float32) *float32 { | ||
return &f | ||
} | ||
|
||
func Int64Pointer(i int64) *int64 { | ||
return &i | ||
} | ||
|
||
func Int32Pointer(i int32) *int32 { | ||
return &i | ||
} | ||
|
||
func Int16Pointer(i int16) *int16 { | ||
return &i | ||
} | ||
|
||
func Int8Pointer(i int8) *int8 { | ||
return &i | ||
} | ||
|
||
func UintPointer(u uint) *uint { | ||
return &u | ||
} | ||
|
||
func Uint64Pointer(u uint64) *uint64 { | ||
return &u | ||
} | ||
|
||
func Uint32Pointer(u uint32) *uint32 { | ||
return &u | ||
} | ||
|
||
func Uint16Pointer(u uint16) *uint16 { | ||
return &u | ||
} | ||
|
||
func Uint8Pointer(u uint8) *uint8 { | ||
return &u | ||
} | ||
|
||
func BytePointer(b byte) *byte { | ||
return &b | ||
} | ||
|
||
func RunePointer(r rune) *rune { | ||
return &r | ||
} | ||
|
||
func Complex64Pointer(c complex64) *complex64 { | ||
return &c | ||
} | ||
|
||
func Complex128Pointer(c complex128) *complex128 { | ||
return &c | ||
} | ||
|
||
func Pointer[T any](v T) *T { | ||
return &v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package utils_test | ||
|
||
import ( | ||
"github.com/bugfixes/go-bugfixes/utils" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestStringPointer(t *testing.T) { | ||
s := "test" | ||
sp := utils.StringPointer(s) | ||
assert.Equal(t, &s, sp) | ||
} | ||
|
||
func TestIntPointer(t *testing.T) { | ||
i := 10 | ||
ip := utils.IntPointer(i) | ||
assert.Equal(t, &i, ip) | ||
} | ||
|
||
func TestBoolPointer(t *testing.T) { | ||
b := true | ||
bp := utils.BoolPointer(true) | ||
assert.Equal(t, &b, bp) | ||
} | ||
|
||
func TestFloat64Pointer(t *testing.T) { | ||
f := 10.0 | ||
fp := utils.Float64Pointer(f) | ||
assert.Equal(t, &f, fp) | ||
} | ||
|
||
func TestFloat32Pointer(t *testing.T) { | ||
f := float32(10.0) | ||
fp := utils.Float32Pointer(f) | ||
assert.Equal(t, &f, fp) | ||
} | ||
|
||
func TestInt64Pointer(t *testing.T) { | ||
i := int64(10) | ||
ip := utils.Int64Pointer(i) | ||
assert.Equal(t, &i, ip) | ||
} | ||
|
||
func TestInt32Pointer(t *testing.T) { | ||
i := int32(10) | ||
ip := utils.Int32Pointer(i) | ||
assert.Equal(t, &i, ip) | ||
} | ||
|
||
func TestInt16Pointer(t *testing.T) { | ||
i := int16(10) | ||
ip := utils.Int16Pointer(i) | ||
assert.Equal(t, &i, ip) | ||
} | ||
|
||
func TestInt8Pointer(t *testing.T) { | ||
i := int8(10) | ||
ip := utils.Int8Pointer(i) | ||
assert.Equal(t, &i, ip) | ||
} | ||
|
||
func TestUintPointer(t *testing.T) { | ||
u := uint(10) | ||
up := utils.UintPointer(u) | ||
assert.Equal(t, &u, up) | ||
} | ||
|
||
func TestUint64Pointer(t *testing.T) { | ||
u := uint64(10) | ||
up := utils.Uint64Pointer(u) | ||
assert.Equal(t, &u, up) | ||
} | ||
|
||
func TestUint32Pointer(t *testing.T) { | ||
u := uint32(10) | ||
up := utils.Uint32Pointer(u) | ||
assert.Equal(t, &u, up) | ||
} | ||
|
||
func TestUint16Pointer(t *testing.T) { | ||
u := uint16(10) | ||
up := utils.Uint16Pointer(u) | ||
assert.Equal(t, &u, up) | ||
} | ||
|
||
func TestUint8Pointer(t *testing.T) { | ||
u := uint8(10) | ||
up := utils.Uint8Pointer(u) | ||
assert.Equal(t, &u, up) | ||
} | ||
|
||
func TestBytePointer(t *testing.T) { | ||
b := byte(10) | ||
bp := utils.BytePointer(b) | ||
assert.Equal(t, &b, bp) | ||
} | ||
|
||
func TestRunePointer(t *testing.T) { | ||
r := rune(10) | ||
rp := utils.RunePointer(r) | ||
assert.Equal(t, &r, rp) | ||
} | ||
|
||
func TestComplex64Pointer(t *testing.T) { | ||
c := complex64(10) | ||
cp := utils.Complex64Pointer(c) | ||
assert.Equal(t, &c, cp) | ||
} | ||
|
||
func TestComplex128Pointer(t *testing.T) { | ||
c := complex128(10) | ||
cp := utils.Complex128Pointer(c) | ||
assert.Equal(t, &c, cp) | ||
} | ||
|
||
func TestPointer(t *testing.T) { | ||
i := 10 | ||
ip := utils.Pointer(i) | ||
assert.Equal(t, &i, ip) | ||
} |