gogcli/internal/cmd/completion_test.go
salmonumbrella dae8aa4643 fix(completion): enable shell completions in release builds
Implements working shell completions for bash, zsh, fish, and PowerShell.

Changes:
- Add CompletionInternalCmd for kong's __complete helper
- Refactor completion generation to use kong's built-in support
- Extract newParser() for reuse in completion generation
- Add baseDescription() to avoid duplication

The completion command now generates valid scripts that work when
eval'd in the user's shell configuration.

Fixes #65

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-17 03:24:07 +00:00

35 lines
792 B
Go

package cmd
import (
"context"
"strings"
"testing"
)
func TestCompletionCmd(t *testing.T) {
cases := map[string]string{
"bash": "complete -F _gog_complete gog",
"zsh": "bashcompinit",
"fish": "complete -c gog",
"powershell": "Register-ArgumentCompleter",
}
for shell, marker := range cases {
shell := shell
marker := marker
t.Run(shell, func(t *testing.T) {
out := captureStdout(t, func() {
cmd := &CompletionCmd{Shell: shell}
if err := cmd.Run(context.Background()); err != nil {
t.Fatalf("run: %v", err)
}
})
if !strings.Contains(out, "__complete") {
t.Fatalf("expected __complete hook, got %q", out)
}
if !strings.Contains(out, marker) {
t.Fatalf("expected %q in output, got %q", marker, out)
}
})
}
}