tests: add backend tests

This commit is contained in:
2026-01-19 12:46:07 -05:00
parent 5e8ac5e4b6
commit 627fcbafe1
9 changed files with 664 additions and 7 deletions

View File

@@ -0,0 +1,53 @@
package ptr
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDerefOrZero(t *testing.T) {
// Test with nil pointer
var nilPtr *int
result := DerefOrZero(nilPtr)
assert.Equal(t, 0, result)
// Test with non-nil pointer
value := 42
ptr := &value
result = DerefOrZero(ptr)
assert.Equal(t, 42, result)
// Test with string
var nilString *string
resultStr := DerefOrZero(nilString)
assert.Equal(t, "", resultStr)
// Test with non-nil string
strValue := "hello"
strPtr := &strValue
resultStr = DerefOrZero(strPtr)
assert.Equal(t, "hello", resultStr)
}
func TestOf(t *testing.T) {
// Test with int
value := 42
ptr := Of(value)
assert.NotNil(t, ptr)
assert.Equal(t, 42, *ptr)
// Test with string - using explicit typing
var strPtr *string
strValue := "hello"
strPtr = Of(strValue)
assert.NotNil(t, strPtr)
assert.Equal(t, "hello", *strPtr)
// Test with bool - using explicit typing
var boolPtr *bool
boolValue := true
boolPtr = Of(boolValue)
assert.NotNil(t, boolPtr)
assert.Equal(t, true, *boolPtr)
}