MCPcopy Create free account
hub / github.com/algolia/cli / Test_runStringSliceCompletion

Function Test_runStringSliceCompletion

pkg/cmdutil/flags_completion_test.go:10–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func Test_runStringSliceCompletion(t *testing.T) {
11 allowedMap := map[string]string{
12 "settings": "settings",
13 "synonyms": "synonyms",
14 "rules": "rules",
15 }
16 prefixDescription := "copy only"
17
18 tests := []struct {
19 name string
20 toComplete string
21 results []string
22 }{
23 {
24 name: "first input, no letter",
25 toComplete: "",
26 results: []string{
27 "rules\tcopy only rules",
28 "settings\tcopy only settings",
29 "synonyms\tcopy only synonyms",
30 },
31 },
32 {
33 name: "second input (settings already passed), no letter",
34 toComplete: "settings,s",
35 results: []string{"settings,synonyms\tcopy only settings and synonyms"},
36 },
37 {
38 name: "first input, first letter",
39 toComplete: "s",
40 results: []string{"settings\tcopy only settings", "synonyms\tcopy only synonyms"},
41 },
42 {
43 name: "second input (settings already passed), first letter",
44 toComplete: "settings,s",
45 results: []string{"settings,synonyms\tcopy only settings and synonyms"},
46 },
47 {
48 name: "third input (settings and synonyms already passed), no letter",
49 toComplete: "settings,synonyms,",
50 results: []string{"settings,synonyms,rules\tcopy only settings, synonyms and rules"},
51 },
52 }
53
54 for _, tt := range tests {
55 t.Run(tt.name, func(t *testing.T) {
56 results, rule := runStringSliceCompletion(
57 allowedMap,
58 tt.toComplete,
59 prefixDescription,
60 )
61
62 assert.Equal(t, tt.results, results)
63 assert.Equal(t, cobra.ShellCompDirectiveNoSpace, rule)
64 })
65 }
66}

Callers

nothing calls this directly

Calls 2

runStringSliceCompletionFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected