@@ -194,37 +194,94 @@ func TestMutuallyExclusiveFlagsCompletion(t *testing.T) {
194194 Writer : out ,
195195 Flags : []Flag {
196196 & StringFlag {
197- Name : "l1 " ,
197+ Name : "gf " ,
198198 },
199199 },
200200 MutuallyExclusiveFlags : []MutuallyExclusiveFlags {
201201 {
202202 Flags : [][]Flag {
203203 {
204204 & StringFlag {
205- Name : "m1 " ,
205+ Name : "mexg1_1 " ,
206206 },
207207 & StringFlag {
208- Name : "m2 " ,
208+ Name : "mexg1_2 " ,
209209 },
210210 },
211211 {
212212 & StringFlag {
213- Name : "l2 " ,
213+ Name : "mexg2_1 " ,
214214 },
215215 },
216216 },
217217 },
218218 },
219219 }
220220
221- os .Args = []string {"foo" , "-" , completionFlag }
222- err := cmd .Run (buildTestContext (t ), os .Args )
223- assert .NoError (t , err , "Expected no error for completion" )
224- assert .Contains (t , out .String (), "l1" , "Expected output to contain flag l1" )
225- assert .Contains (t , out .String (), "m1" , "Expected output to contain flag m1" )
226- assert .Contains (t , out .String (), "m2" , "Expected output to contain flag m2" )
227- assert .Contains (t , out .String (), "l2" , "Expected output to contain flag l2" )
221+ tests := []struct {
222+ name string
223+ args []string
224+ expectGlobal bool
225+ expectMexg1_1 bool
226+ expectMexg1_2 bool
227+ expectMexg2_1 bool
228+ }{
229+ {
230+ name : "flag completion all" ,
231+ args : []string {"foo" , "-" , completionFlag },
232+ expectGlobal : true ,
233+ expectMexg1_1 : true ,
234+ expectMexg1_2 : true ,
235+ expectMexg2_1 : true ,
236+ },
237+ {
238+ name : "flag completion local" ,
239+ args : []string {"foo" , "-mex" , completionFlag },
240+ expectMexg1_1 : true ,
241+ expectMexg1_2 : true ,
242+ expectMexg2_1 : true ,
243+ },
244+ {
245+ name : "flag completion local group-1" ,
246+ args : []string {"foo" , "-mexg1" , completionFlag },
247+ expectMexg1_1 : true ,
248+ expectMexg1_2 : true ,
249+ },
250+ {
251+ name : "flag completion local group-2" ,
252+ args : []string {"foo" , "-mexg2" , completionFlag },
253+ expectMexg2_1 : true ,
254+ },
255+ }
256+
257+ for _ , test := range tests {
258+ t .Run (test .name , func (t * testing.T ) {
259+ out .Reset ()
260+ os .Args = test .args
261+ err := cmd .Run (buildTestContext (t ), os .Args )
262+ assert .NoError (t , err , "Expected no error for completion" )
263+ if test .expectGlobal {
264+ assert .Contains (t , out .String (), "gf" , "Expected output to contain flag gf" )
265+ } else {
266+ assert .NotContains (t , out .String (), "gf" , "Expected output to not contain flag gf" )
267+ }
268+ if test .expectMexg1_1 {
269+ assert .Contains (t , out .String (), "mexg1_1" , "Expected output to contain flag mexg1_1" )
270+ } else {
271+ assert .NotContains (t , out .String (), "mexg1_1" , "Expected output to not contain flag mexg1_1" )
272+ }
273+ if test .expectMexg1_2 {
274+ assert .Contains (t , out .String (), "mexg1_2" , "Expected output to contain flag mexg1_2" )
275+ } else {
276+ assert .NotContains (t , out .String (), "mexg1_2" , "Expected output to not contain flag mexg1_2" )
277+ }
278+ if test .expectMexg2_1 {
279+ assert .Contains (t , out .String (), "mexg2_1" , "Expected output to contain flag mexg2_1" )
280+ } else {
281+ assert .NotContains (t , out .String (), "mexg2_1" , "Expected output to not contain flag mexg2_1" )
282+ }
283+ })
284+ }
228285}
229286
230287type mockWriter struct {
0 commit comments