diff options
Diffstat (limited to 'internal/askcli/completion_test.go')
| -rw-r--r-- | internal/askcli/completion_test.go | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/internal/askcli/completion_test.go b/internal/askcli/completion_test.go index 5cab89b..ad25cbd 100644 --- a/internal/askcli/completion_test.go +++ b/internal/askcli/completion_test.go @@ -1,42 +1,25 @@ package askcli import ( - "os" - "path/filepath" - "runtime" "strings" "testing" ) -func TestFishCompletion_MatchesAsset(t *testing.T) { - _, file, _, ok := runtime.Caller(0) - if !ok { - t.Fatal("runtime.Caller failed") - } - assetPath := filepath.Clean(filepath.Join(filepath.Dir(file), "..", "..", "assets", "ask.fish")) - want, err := os.ReadFile(assetPath) - if err != nil { - t.Fatalf("read asset: %v", err) - } - got := FishCompletion() - if got != string(want) { - t.Fatalf("fish completion asset mismatch\n--- got ---\n%s\n--- want ---\n%s", got, string(want)) - } -} - func TestFishCompletion_IncludesCommandsAndExcludesExport(t *testing.T) { script := FishCompletion() - for _, name := range []string{"add", "list", "all", "ready", "info", "annotate", "start", "stop", "done", "priority", "tag", "dep", "urgency", "modify", "denotate", "delete", "help"} { + for _, name := range []string{"add", "list", "all", "ready", "info", "annotate", "start", "stop", "done", "priority", "tag", "dep", "urgency", "modify", "denotate", "delete", "fish", "help"} { if !strings.Contains(script, " -a '"+name+"' ") { t.Fatalf("script missing root completion for %q", name) } } for _, line := range []string{ + "# Source with: ask fish | source", "complete -c ask -n '__ask_in_dep_context' -a 'add' -d 'Add a dependency'", "complete -c ask -n '__ask_in_dep_context' -a 'rm' -d 'Remove a dependency'", "complete -c ask -n '__ask_in_dep_context' -a 'list' -d 'List dependencies'", "function __ask_task_uuids", - "set -l uuids (command ask complete-uuids 2>/dev/null)", + `set -l ask_bin "ask"`, + "set -l uuids (command $ask_bin complete-uuids 2>/dev/null)", "complete -c ask -n '__ask_in_uuid_context' -a '(__ask_task_uuids)' -d 'Task UUID'", "complete -c ask -n '__ask_in_dep_uuid_context' -a '(__ask_task_uuids)' -d 'Task UUID'", } { @@ -47,4 +30,19 @@ func TestFishCompletion_IncludesCommandsAndExcludesExport(t *testing.T) { if strings.Contains(script, "ask export") { t.Fatalf("script should not advertise non-existent export command") } + if strings.Contains(script, "assets/ask.fish") { + t.Fatalf("script should not reference a static asset") + } +} + +func TestFishCompletionFor_EmbedsBinaryPath(t *testing.T) { + script := FishCompletionFor(`/tmp/ask "$HOME"`) + for _, line := range []string{ + `set -l ask_bin "/tmp/ask \"\$HOME\""`, + "set -l uuids (command $ask_bin complete-uuids 2>/dev/null)", + } { + if !strings.Contains(script, line) { + t.Fatalf("script missing %q", line) + } + } } |
