diff options
| author | Eyal Posener <[email protected]> | 2019-11-14 06:51:44 +0200 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2019-11-18 01:05:47 +0200 |
| commit | 8724aaf18312e54750540a9578e00d61b1c545d8 (patch) | |
| tree | d3e736b4fb279975bbcc017ae1bad53e454c5773 /predict/predict_test.go | |
| parent | 05b68ffc813dd10c420993cb1cf927b346c057b8 (diff) | |
V2
Diffstat (limited to 'predict/predict_test.go')
| -rw-r--r-- | predict/predict_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/predict/predict_test.go b/predict/predict_test.go new file mode 100644 index 0000000..af3bf69 --- /dev/null +++ b/predict/predict_test.go @@ -0,0 +1,61 @@ +package predict + +import ( + "testing" + + "github.com/posener/complete" + "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) + }) + } +} |
