go-prompt/render_test.go

49 lines
893 B
Go
Raw Normal View History

2017-07-15 09:51:33 +00:00
package prompt
import (
"reflect"
2017-07-15 13:23:47 +00:00
"testing"
2017-07-15 09:51:33 +00:00
)
func TestFormatCompletion(t *testing.T) {
2017-07-17 17:01:24 +00:00
scenarioTable := []struct {
scenario string
completions []string
prefix string
suffix string
expected []string
maxWidth int
2017-07-17 14:17:08 +00:00
expectedWidth int
2017-07-17 17:01:24 +00:00
}{
2017-07-17 14:17:08 +00:00
{
scenario: "",
completions: []string{
"select",
"from",
"insert",
"where",
},
prefix: " ",
suffix: " ",
expected: []string{
" select ",
" from ",
" insert ",
" where ",
},
2017-07-17 17:01:24 +00:00
maxWidth: 20,
2017-07-17 14:17:08 +00:00
expectedWidth: 8,
},
2017-07-15 09:51:33 +00:00
}
2017-07-17 14:17:08 +00:00
for _, s := range scenarioTable {
ac, width := formatCompletions(s.completions, s.maxWidth, s.prefix, s.suffix)
if !reflect.DeepEqual(ac, s.expected) {
t.Errorf("Should be %#v, but got %#v", s.expected, ac)
}
if width != s.expectedWidth {
t.Errorf("Should be %#v, but got %#v", s.expectedWidth, width)
}
2017-07-15 09:51:33 +00:00
}
}