Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions sys/pointer.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
package sys

import (
"testing"

"github.com/stretchr/testify/assert"
)

// Ptr returns a pointer to the given value.
func Ptr[T any](v T) *T {
return &v
}

func TestPtr(t *testing.T) {
// Test with string
str := "hello"
strPtr := Ptr(str)
assert.NotNil(t, strPtr)
assert.Equal(t, str, *strPtr)

// Test with int
num := 42
numPtr := Ptr(num)
assert.NotNil(t, numPtr)
assert.Equal(t, num, *numPtr)

// Test with bool
flag := true
flagPtr := Ptr(flag)
assert.NotNil(t, flagPtr)
assert.Equal(t, flag, *flagPtr)

// Test with struct
type testStruct struct {
Name string
Age int
}
s := testStruct{Name: "test", Age: 25}
sPtr := Ptr(s)
assert.NotNil(t, sPtr)
assert.Equal(t, s, *sPtr)

// Test with slice
slice := []int{1, 2, 3}
slicePtr := Ptr(slice)
assert.NotNil(t, slicePtr)
assert.Equal(t, slice, *slicePtr)

// Test with nil interface
var nilInterface interface{}
nilPtr := Ptr(nilInterface)
assert.NotNil(t, nilPtr)
assert.Equal(t, nilInterface, *nilPtr)
}
49 changes: 49 additions & 0 deletions sys/pointer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package sys

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestPtr(t *testing.T) {
// Test with string
str := "hello"
strPtr := Ptr(str)
assert.NotNil(t, strPtr)
assert.Equal(t, str, *strPtr)

// Test with int
num := 42
numPtr := Ptr(num)
assert.NotNil(t, numPtr)
assert.Equal(t, num, *numPtr)

// Test with bool
flag := true
flagPtr := Ptr(flag)
assert.NotNil(t, flagPtr)
assert.Equal(t, flag, *flagPtr)

// Test with struct
type testStruct struct {
Name string
Age int
}
s := testStruct{Name: "test", Age: 25}
sPtr := Ptr(s)
assert.NotNil(t, sPtr)
assert.Equal(t, s, *sPtr)

// Test with slice
slice := []int{1, 2, 3}
slicePtr := Ptr(slice)
assert.NotNil(t, slicePtr)
assert.Equal(t, slice, *slicePtr)

// Test with nil interface
var nilInterface interface{}
nilPtr := Ptr(nilInterface)
assert.NotNil(t, nilPtr)
assert.Equal(t, nilInterface, *nilPtr)
}
Loading