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
|
2017-07-18 15:36:16 +00:00
|
|
|
completions []Suggestion
|
2017-07-17 17:01:24 +00:00
|
|
|
prefix string
|
|
|
|
suffix string
|
2017-07-18 15:36:16 +00:00
|
|
|
expected []Suggestion
|
2017-07-17 17:01:24 +00:00
|
|
|
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: "",
|
2017-07-18 15:36:16 +00:00
|
|
|
completions: []Suggestion{
|
2017-07-18 00:53:59 +00:00
|
|
|
{Text: "select"},
|
|
|
|
{Text: "from"},
|
|
|
|
{Text: "insert"},
|
|
|
|
{Text: "where"},
|
2017-07-17 14:17:08 +00:00
|
|
|
},
|
|
|
|
prefix: " ",
|
|
|
|
suffix: " ",
|
2017-07-18 15:36:16 +00:00
|
|
|
expected: []Suggestion{
|
|
|
|
{Text: " select "},
|
|
|
|
{Text: " from "},
|
|
|
|
{Text: " insert "},
|
|
|
|
{Text: " where "},
|
2017-07-17 14:17:08 +00:00
|
|
|
},
|
2017-07-17 17:01:24 +00:00
|
|
|
maxWidth: 20,
|
2017-07-17 14:17:08 +00:00
|
|
|
expectedWidth: 8,
|
|
|
|
},
|
2017-07-18 15:36:16 +00:00
|
|
|
{
|
|
|
|
scenario: "",
|
|
|
|
completions: []Suggestion{
|
|
|
|
{Text: "select", Description: "select description"},
|
|
|
|
{Text: "from", Description: "from description"},
|
|
|
|
{Text: "insert", Description: "insert description"},
|
|
|
|
{Text: "where", Description: "where description"},
|
|
|
|
},
|
|
|
|
prefix: " ",
|
|
|
|
suffix: " ",
|
|
|
|
expected: []Suggestion{
|
|
|
|
{Text: " select ", Description: " select description "},
|
|
|
|
{Text: " from ", Description: " from description "},
|
|
|
|
{Text: " insert ", Description: " insert description "},
|
|
|
|
{Text: " where ", Description: " where description "},
|
|
|
|
},
|
|
|
|
maxWidth: 40,
|
|
|
|
expectedWidth: 28,
|
|
|
|
},
|
2017-07-15 09:51:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:17:08 +00:00
|
|
|
for _, s := range scenarioTable {
|
2017-07-18 15:36:16 +00:00
|
|
|
ac, width := formatCompletions(s.completions, s.maxWidth)
|
2017-07-17 14:17:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|