Skip to content

chore: add tests for myers panics#45

Merged
KimNorgaard merged 1 commit intomainfrom
chore/add-myers-tests
Mar 18, 2026
Merged

chore: add tests for myers panics#45
KimNorgaard merged 1 commit intomainfrom
chore/add-myers-tests

Conversation

@KimNorgaard
Copy link
Contributor

Add two tests that confirm the panics revealed in #44 (9d6d18c).

Add two tests that confirm the panics revealed in #44 (9d6d18c).
@KimNorgaard KimNorgaard requested review from a team and gh-netic-robot as code owners March 18, 2026 18:12
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Panic Prevention: Added two new test cases to specifically confirm and prevent panics that were previously identified in issue fix: panic in linear myers algorithm #44 (commit 9d6d18c) within the Myers diff algorithm's linear space implementation.
  • Test Coverage: The new tests cover two distinct panic scenarios: an 'x/y clamping panic' and a 'prefix/suffix limit panic', ensuring robustness for edge cases in diff calculations.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +1297 to +1321
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)
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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)
		})
	}
}

@KimNorgaard KimNorgaard merged commit e4c9d81 into main Mar 18, 2026
1 check passed
@KimNorgaard KimNorgaard deleted the chore/add-myers-tests branch March 18, 2026 18:23
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.

2 participants