Move the pointer tests into a test file - #92
Conversation
WalkthroughMoved inline tests out of sys/pointer.go into a dedicated sys/pointer_test.go. The Ptr[T any](v T) *T function remains unchanged. New tests cover multiple types and a nil interface case using testify assertions. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
sys/pointer_test.go (3)
9-9: Run tests in parallel.Add t.Parallel() to keep this test concurrent-friendly.
func TestPtr(t *testing.T) { + t.Parallel()
38-49: Add a few more nil edge cases (slice, map, pointer).These strengthen guarantees that Ptr works across common nil-able types.
// Test with nil interface var nilInterface interface{} nilPtr := Ptr(nilInterface) assert.NotNil(t, nilPtr) assert.Equal(t, nilInterface, *nilPtr) + + // Test with nil slice + var nilSlice []int + nilSlicePtr := Ptr(nilSlice) + assert.NotNil(t, nilSlicePtr) + assert.Equal(t, nilSlice, *nilSlicePtr) + + // Test with nil map + var nilMap map[string]int + nilMapPtr := Ptr(nilMap) + assert.NotNil(t, nilMapPtr) + assert.Equal(t, nilMap, *nilMapPtr) + + // Test with nil pointer + var nilIntPtr *int + nilIntPtrPtr := Ptr(nilIntPtr) + assert.NotNil(t, nilIntPtrPtr) + assert.Equal(t, nilIntPtr, *nilIntPtrPtr)
1-7: Consider external tests (package sys_test) to validate only the public API.Since Ptr is exported, external tests avoid accidental reliance on internals.
-package sys +package sys_test import ( "testing" "github.com/stretchr/testify/assert" + sys "github.com/agentuity/go-common/sys" )Then qualify calls:
- strPtr := Ptr(str) + strPtr := sys.Ptr(str) - numPtr := Ptr(num) + numPtr := sys.Ptr(num) - flagPtr := Ptr(flag) + flagPtr := sys.Ptr(flag) - sPtr := Ptr(s) + sPtr := sys.Ptr(s) - slicePtr := Ptr(slice) + slicePtr := sys.Ptr(slice) - nilPtr := Ptr(nilInterface) + nilPtr := sys.Ptr(nilInterface)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
sys/pointer.go(0 hunks)sys/pointer_test.go(1 hunks)
💤 Files with no reviewable changes (1)
- sys/pointer.go
🧰 Additional context used
🧬 Code graph analysis (1)
sys/pointer_test.go (1)
sys/pointer.go (1)
Ptr(4-6)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
sys/pointer_test.go (1)
9-49: LGTM on moving tests and coverage breadth.Good move separating tests from production code; cases cover primitives, struct, slice, and nil interface well.
Summary by CodeRabbit