-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1121. This is for programs that may contain a : or - in their name. Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
- Loading branch information
1 parent
2c5a0d3
commit 5782fed
Showing
3 changed files
with
88 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cobra | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestCompleteNoDesCmdInFishScript(t *testing.T) { | ||
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun} | ||
child := &Command{ | ||
Use: "child", | ||
ValidArgsFunction: validArgsFunc, | ||
Run: emptyRun, | ||
} | ||
rootCmd.AddCommand(child) | ||
|
||
buf := new(bytes.Buffer) | ||
rootCmd.GenFishCompletion(buf, false) | ||
output := buf.String() | ||
|
||
check(t, output, ShellCompNoDescRequestCmd) | ||
} | ||
|
||
func TestCompleteCmdInFishScript(t *testing.T) { | ||
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun} | ||
child := &Command{ | ||
Use: "child", | ||
ValidArgsFunction: validArgsFunc, | ||
Run: emptyRun, | ||
} | ||
rootCmd.AddCommand(child) | ||
|
||
buf := new(bytes.Buffer) | ||
rootCmd.GenFishCompletion(buf, true) | ||
output := buf.String() | ||
|
||
check(t, output, ShellCompRequestCmd) | ||
checkOmit(t, output, ShellCompNoDescRequestCmd) | ||
} | ||
|
||
func TestProgWithDash(t *testing.T) { | ||
rootCmd := &Command{Use: "root-dash", Args: NoArgs, Run: emptyRun} | ||
buf := new(bytes.Buffer) | ||
rootCmd.GenFishCompletion(buf, false) | ||
output := buf.String() | ||
|
||
// Functions name should have replace the '-' | ||
check(t, output, "__root_dash_perform_completion") | ||
checkOmit(t, output, "__root-dash_perform_completion") | ||
|
||
// The command name should not have replaced the '-' | ||
check(t, output, "-c root-dash") | ||
checkOmit(t, output, "-c root_dash") | ||
} | ||
|
||
func TestProgWithColon(t *testing.T) { | ||
rootCmd := &Command{Use: "root:colon", Args: NoArgs, Run: emptyRun} | ||
buf := new(bytes.Buffer) | ||
rootCmd.GenFishCompletion(buf, false) | ||
output := buf.String() | ||
|
||
// Functions name should have replace the ':' | ||
check(t, output, "__root_colon_perform_completion") | ||
checkOmit(t, output, "__root:colon_perform_completion") | ||
|
||
// The command name should not have replaced the ':' | ||
check(t, output, "-c root:colon") | ||
checkOmit(t, output, "-c root_colon") | ||
} |