summaryrefslogtreecommitdiff
path: root/predict/predict_test.go
blob: 04c210ae54238d607b94c9057c17f24aaf80da9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package predict

import (
	"testing"

	"github.com/posener/complete/v2"
	"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)
		})
	}
}