mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Add a test for the current search match after the matches change
Search a view, step to the last match, then have the view re-rendered with fewer matches in it, and the status reads "3 of 1". The positions are worked out again whenever the content changes, but the index into them stays where it was. Stepping on from there indexes the positions out of range and panics. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
acb6e48a98
commit
b54318e80c
39
pkg/gocui/search_test.go
Normal file
39
pkg/gocui/search_test.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package gocui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// writeLines writes the given lines to the view, as a task rendering content into it
|
||||
// does: one line at a time.
|
||||
func writeLines(v *View, lines ...string) {
|
||||
for _, line := range lines {
|
||||
fmt.Fprintf(v, "%s\n", line)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchStatusAfterTheMatchesChange(t *testing.T) {
|
||||
v := NewView("name", 0, 0, 40, 10, OutputNormal)
|
||||
writeLines(v, "match", "other", "match", "other", "match")
|
||||
|
||||
v.Search("match", nil)
|
||||
_ = v.gotoNextMatch()
|
||||
_ = v.gotoNextMatch()
|
||||
index, total := v.GetSearchStatus()
|
||||
assert.Equal(t, 2, index)
|
||||
assert.Equal(t, 3, total)
|
||||
|
||||
// The content is re-rendered with only the first of those matches left in it.
|
||||
v.Clear()
|
||||
writeLines(v, "match", "other", "other")
|
||||
|
||||
index, total = v.GetSearchStatus()
|
||||
/* EXPECTED:
|
||||
assert.Equal(t, 0, index)
|
||||
ACTUAL: */
|
||||
assert.Equal(t, 2, index)
|
||||
assert.Equal(t, 1, total)
|
||||
}
|
||||
Loading…
Reference in a new issue