Skip to content

test: playground code for PR comment testing#218

Open
eugenioenko wants to merge 2 commits into
mainfrom
test/pr-comments-playground
Open

test: playground code for PR comment testing#218
eugenioenko wants to merge 2 commits into
mainfrom
test/pr-comments-playground

Conversation

@eugenioenko

Copy link
Copy Markdown
Owner

Summary

Sample code with deliberate review opportunities for testing PR comment features.

Do not merge — this is a test PR for exercising comment UIs.

eugenioenko and others added 2 commits June 19, 2026 20:42
Sample functions with deliberate review opportunities: missing error
handling in Divide, inefficient Fibonacci, loop-based Multiply.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7 files with various issues: regex recompilation, memory leaks,
overflow bugs, shadowed builtins, missing edge case handling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@eugenioenko

Copy link
Copy Markdown
Owner Author

Overall this looks like a good start, but there are several issues that need addressing before merge. See my inline comments below.

@eugenioenko

Copy link
Copy Markdown
Owner Author

I'd also suggest adding table-driven tests for the math functions. The current test coverage is thin.

@eugenioenko

Copy link
Copy Markdown
Owner Author

One more thing: the example package name is too generic. Consider renaming to something more descriptive like playground or sandbox.

}

func Divide(a, b int) int {
return a / b

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Bug: this will panic on division by zero. Add a guard: if b == 0 { return 0 } or return an error.

func Fibonacci(n int) int {
if n <= 1 {
return n
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Performance: this naive recursive Fibonacci is O(2^n). Use memoization or an iterative approach. This will be unusably slow for n > 30.

}

func Multiply(a, b int) int {
result := 0

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nit: why use a loop here instead of just return a * b? This also breaks for negative b.


// TODO: this compiles the regex every call, should be a package-level var
func IsEmail(s string) bool {
re := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Performance: regexp.MustCompile is called every invocation. Move this to a package-level var emailRe = regexp.MustCompile(...).

Comment thread internal/example/math.go
}

// this shadows builtin max, probably bad
func max2(a, b int) int {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This shadows the builtin max (Go 1.21+). Either use the builtin directly or pick a different name. Also this function appears unused.

if r >= 'A' && r <= 'Z' {
if i > 0 {
result.WriteByte('_')
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The REVIEW comment nails it: HTTPServer becomes h_t_t_p_server. Consider tracking runs of uppercase characters.

}

func FahrenheitToCelsius(f float64) float64 {
return (f - 32) * 5 / 9

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Negative bytes will produce confusing output. Add a guard or use Abs.


import "fmt"

func Greet(name string) string {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nit: exported functions should have godoc comments.

return s == Reverse(s)
}

func CountWords(s string) int {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nit: CountWords could be WordCount to match Go's noun-first convention (like len, cap).

}

func Truncate(s string, maxLen int) string {
if len(s) <= maxLen {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nit: len(s) counts bytes, not runes. Truncating at a byte boundary could split a multi-byte character. Use []rune(s) for correctness.

Comment thread internal/example/stack.go
@@ -0,0 +1,37 @@
package example

type Stack struct {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nit: consider using generics (Stack[T any]) instead of any for type safety.

@@ -0,0 +1,48 @@
package example

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nit: only playground.go has tests. The other 6 files have zero test coverage.

}

func CSVToSlice(csv string) []string {
if csv == "" {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Nit: this does not trim whitespace. "a, b, c" returns [" b", " c"]. Consider strings.TrimSpace on each element.

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