2019-11-13 22:51:44 -06:00
|
|
|
package predict
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-11-17 17:25:16 -06:00
|
|
|
"github.com/posener/complete/v2"
|
2019-11-13 22:51:44 -06:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPredict(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
p complete.Predictor
|
|
|
|
prefix string
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "set",
|
|
|
|
p: Set{"a", "b", "c"},
|
|
|
|
want: []string{"a", "b", "c"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set/empty",
|
|
|
|
p: Set{},
|
|
|
|
want: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "or: word with nil",
|
|
|
|
p: Or(Set{"a"}, nil),
|
|
|
|
want: []string{"a"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "or: nil with word",
|
|
|
|
p: Or(nil, Set{"a"}),
|
|
|
|
want: []string{"a"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "or: word with word with word",
|
|
|
|
p: Or(Set{"a"}, Set{"b"}, Set{"c"}),
|
|
|
|
want: []string{"a", "b", "c"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "something",
|
|
|
|
p: Something,
|
|
|
|
want: []string{""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "nothing",
|
|
|
|
p: Nothing,
|
|
|
|
prefix: "a",
|
|
|
|
want: []string{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got := tt.p.Predict(tt.prefix)
|
|
|
|
assert.ElementsMatch(t, tt.want, got, "Got: %+v", got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|