MCPcopy Index your code
hub / github.com/celer-pkg/celer / TestTreeCmd_Completion

Function TestTreeCmd_Completion

cmds/cmd_tree_test.go:114–179  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestTreeCmd_Completion(t *testing.T) {
115 // Cleanup.
116 dirs.RemoveAllForTest()
117
118 // Setup test environment
119 setupTestEnvironment(t)
120
121 treeCmd := treeCmd{}
122 celer := configs.NewCeler()
123 treeCmd.celer = celer
124
125 tests := []struct {
126 name string
127 toComplete string
128 expectContains []string
129 expectNotContain []string
130 }{
131 {
132 name: "complete_flag",
133 toComplete: "--hide",
134 expectContains: []string{"--hide-dev"},
135 },
136 {
137 name: "complete_package",
138 toComplete: "boost",
139 expectContains: []string{"boost@1.87.0"},
140 },
141 {
142 name: "complete_project",
143 toComplete: "test",
144 expectContains: []string{"test_project"},
145 },
146 {
147 name: "no_match",
148 toComplete: "nonexistent",
149 expectNotContain: []string{"boost@1.87.0"},
150 },
151 }
152
153 for _, test := range tests {
154 t.Run(test.name, func(t *testing.T) {
155 suggestions, directive := treeCmd.completion(nil, []string{}, test.toComplete)
156
157 if directive != cobra.ShellCompDirectiveNoFileComp {
158 t.Errorf("Expected NoFileComp directive, got %d", directive)
159 }
160
161 // Check expected suggestions.
162 for _, expected := range test.expectContains {
163 found := slices.Contains(suggestions, expected)
164 if !found {
165 t.Errorf("Expected to find '%s' in suggestions, got: %v", expected, suggestions)
166 }
167 }
168
169 // Check suggestions that should not be present.
170 for _, notExpected := range test.expectNotContain {
171 for _, suggestion := range suggestions {

Callers

nothing calls this directly

Calls 4

completionMethod · 0.95
RemoveAllForTestFunction · 0.92
NewCelerFunction · 0.92
setupTestEnvironmentFunction · 0.85

Tested by

no test coverage detected