Files
bubbles/textinput/textinput_test.go
T
2025-01-28 09:24:43 -05:00

46 lines
1.2 KiB
Go

package textinput
import (
"strings"
"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)
}
textinput.Blur()
if strings.HasSuffix(textinput.View(), "test2") {
t.Fatalf("Error: suggestions should not be rendered when input isn't focused. expected \"> test\" but got \"%s\"", textinput.View())
}
}
func Test_SlicingOutsideCap(t *testing.T) {
textinput := New()
textinput.Placeholder = "作業ディレクトリを指定してください"
textinput.Width = 32
textinput.View()
}