Skip to content

Move the pointer tests into a test file - #92

Merged
jhaynie merged 1 commit into
mainfrom
move-pointer
Sep 7, 2025
Merged

jhaynie merged 1 commit into
mainfrom
move-pointer

Conversation

@jhaynie

@jhaynie jhaynie commented Sep 7, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests for Ptr across strings, ints, bools, structs, slices, and nil interfaces to ensure non-nil pointers and correct dereferenced values.
  • Chores
    • Moved inline tests out of the source file into a dedicated test file for cleaner code organization.

@coderabbitai

coderabbitai Bot commented Sep 7, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Moved 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

Cohort / File(s) Summary
Test relocation and expansion
sys/pointer.go, sys/pointer_test.go
Removed inline test and related imports from pointer.go. Added pointer_test.go with comprehensive unit tests for Ptr, covering primitives, struct, slice, and nil interface cases using testing and testify/assert.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

In burrowed code I twitch with cheer,
Tests hop outside, all crystal-clear.
A pointer’s nudge, a gentle tap—
From string to slice, we close the gap.
Nil as a friend, we still concur—
Assert and nibble: purr-fect, sir! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch move-pointer

Comment @coderabbitai help to get the list of available commands and usage tips.

@jhaynie
jhaynie merged commit bc93f2e into main Sep 7, 2025
4 of 5 checks passed
@jhaynie
jhaynie deleted the move-pointer branch September 7, 2025 00:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 194132b and e26777b.

📒 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant