Skip to content

Commit

Permalink
fix textinput.CurrentSuggestion() panic
Browse files Browse the repository at this point in the history
When suggestions are not yet set CurrentSuggestion() will panic. This change fixes that with a guard and returns an empty string when there is no current suggestion.
  • Loading branch information
Kevin Miller committed Apr 22, 2024
1 parent 48dffdd commit 7d37242
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions textinput/textinput_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package textinput

import (
"testing"
)

func Test_CurrentSuggestion(t *testing.T) {
textinput := New()
textinput.ShowSuggestions = true

suggestion := textinput.CurrentSuggestion()
expected := ""
if suggestion != expected {
t.Fatalf("Error: expected no current suggestion but was %s", suggestion)
}

textinput.SetSuggestions([]string{"test1", "test2", "test3"})
suggestion = textinput.CurrentSuggestion()
expected = ""
if suggestion != expected {
t.Fatalf("Error: expected no current suggestion but was %s", suggestion)
}

textinput.SetValue("test")
textinput.updateSuggestions()
textinput.nextSuggestion()
suggestion = textinput.CurrentSuggestion()
expected = "test2"
if suggestion != expected {
t.Fatalf("Error: expected first suggestion but was %s", suggestion)
}
}

0 comments on commit 7d37242

Please sign in to comment.