| 8 | ) |
| 9 | |
| 10 | func TestPredict(t *testing.T) { |
| 11 | tests := []struct { |
| 12 | name string |
| 13 | p complete.Predictor |
| 14 | prefix string |
| 15 | want []string |
| 16 | }{ |
| 17 | { |
| 18 | name: "set", |
| 19 | p: Set{"a", "b", "c"}, |
| 20 | want: []string{"a", "b", "c"}, |
| 21 | }, |
| 22 | { |
| 23 | name: "set/empty", |
| 24 | p: Set{}, |
| 25 | want: []string{}, |
| 26 | }, |
| 27 | { |
| 28 | name: "or: word with nil", |
| 29 | p: Or(Set{"a"}, nil), |
| 30 | want: []string{"a"}, |
| 31 | }, |
| 32 | { |
| 33 | name: "or: nil with word", |
| 34 | p: Or(nil, Set{"a"}), |
| 35 | want: []string{"a"}, |
| 36 | }, |
| 37 | { |
| 38 | name: "or: word with word with word", |
| 39 | p: Or(Set{"a"}, Set{"b"}, Set{"c"}), |
| 40 | want: []string{"a", "b", "c"}, |
| 41 | }, |
| 42 | { |
| 43 | name: "something", |
| 44 | p: Something, |
| 45 | want: []string{""}, |
| 46 | }, |
| 47 | { |
| 48 | name: "nothing", |
| 49 | p: Nothing, |
| 50 | prefix: "a", |
| 51 | want: []string{}, |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | for _, tt := range tests { |
| 56 | t.Run(tt.name, func(t *testing.T) { |
| 57 | got := tt.p.Predict(tt.prefix) |
| 58 | assert.ElementsMatch(t, tt.want, got, "Got: %+v", got) |
| 59 | }) |
| 60 | } |
| 61 | } |