(t *testing.T)
| 112 | } |
| 113 | |
| 114 | func 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 { |
nothing calls this directly
no test coverage detected