mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
fix textinput.CurrentSuggestion() panic
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.
This commit is contained in:
committed by
Maas Lalani
parent
48dffdd97e
commit
63b0917193
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user