Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the stability of the Myers diff algorithm by introducing targeted tests. These tests are designed to reproduce and confirm specific panic conditions that were previously reported, thereby validating that the algorithm handles these edge cases gracefully and prevents future regressions related to these panics. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds two regression tests for previously identified panics in the Myers diff linear space algorithm. The tests correctly force the linear space algorithm path and assert that no error (or panic) occurs. My feedback includes a suggestion to refactor the new test function to use a table-driven approach, which is a common Go idiom that improves maintainability.
| func TestLinearSpacePanics(t *testing.T) { | ||
| // 1. x/y clamping panic | ||
| t.Run("xy clamping panic", func(t *testing.T) { | ||
| a := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"} | ||
| b := []string{"X", "Y", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "Z"} | ||
|
|
||
| _, err := myers.DiffStrings(a, b, | ||
| myers.WithLinearSpace(true), | ||
| myers.WithSmallInputThreshold(0), | ||
| ) | ||
| assert.NoError(t, err) | ||
| }) | ||
|
|
||
| // 2. prefix/suffix limit panic | ||
| t.Run("prefix suffix limit panic", func(t *testing.T) { | ||
| a := []string{"X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X"} | ||
| b := []string{"X", "X", "X", "X", "X", "X", "X", "X", "X", "X"} | ||
|
|
||
| _, err := myers.DiffStrings(a, b, | ||
| myers.WithLinearSpace(true), | ||
| myers.WithSmallInputThreshold(0), | ||
| ) | ||
| assert.NoError(t, err) | ||
| }) | ||
| } |
There was a problem hiding this comment.
For better maintainability and to follow common Go testing patterns, consider refactoring this test to be table-driven. This makes it easier to add more panic-related test cases in the future.
func TestLinearSpacePanics(t *testing.T) {
tests := []struct {
name string
a []string
b []string
}{
{
name: "xy clamping panic",
a: []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"},
b: []string{"X", "Y", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "Z"},
},
{
name: "prefix suffix limit panic",
a: []string{"X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X"},
b: []string{"X", "X", "X", "X", "X", "X", "X", "X", "X", "X"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := myers.DiffStrings(tt.a, tt.b,
myers.WithLinearSpace(true),
myers.WithSmallInputThreshold(0),
)
assert.NoError(t, err)
})
}
}
Add two tests that confirm the panics revealed in #44 (9d6d18c).