Repository navigation
Expand file tree
/
Copy pathcompletion_test.go
More file actions
126 lines (115 loc) · 4.64 KB
/
Copy pathcompletion_test.go
File metadata and controls
126 lines (115 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package flaggy_test
import (
"strings"
"testing"
"github.com/integrii/flaggy"
)
// newCompletionParser builds a parser populated with the fictitious fleet commands used
// to validate shell completion generators across every supported shell variant.
func newCompletionParser() (*flaggy.Parser, []string) {
p := flaggy.NewParser("starfleet")
var route string
p.String(&route, "w", "warp", "Enable warp calibration during deployment")
p.AddPositionalValue(&route, "sector", 2, false, "Target sector coordinate")
commands := []string{"deploy", "destroy", "diagnose", "dock"}
for _, name := range commands {
sub := flaggy.NewSubcommand(name)
sub.Description = "Handle " + name + " operations"
p.AttachSubcommand(sub, 1)
}
return p, commands
}
// verifyCompletionCoverage ensures that each fictitious command surfaces within the
// produced completion output so developers can trust the generator to describe real CLIs.
func verifyCompletionCoverage(t *testing.T, output string, commands []string, shell string) {
t.Helper()
for _, name := range commands {
if !strings.Contains(output, name) {
t.Fatalf("expected %s completion to list command %s: %s", shell, name, output)
}
}
}
// TestGenerateBashCompletion exercises bash completions with the shared fleet commands.
func TestGenerateBashCompletion(t *testing.T) {
p, commands := newCompletionParser()
out := flaggy.GenerateBashCompletion(p)
verifyCompletionCoverage(t, out, commands, "bash")
if !strings.Contains(out, "--warp") {
t.Fatalf("expected bash completion to include long flag name: %s", out)
}
if !strings.Contains(out, "-w") {
t.Fatalf("expected bash completion to include short flag name: %s", out)
}
if !strings.Contains(out, "sector") {
t.Fatalf("expected bash completion to include positional name: %s", out)
}
}
// TestGenerateZshCompletion exercises zsh completions with the shared fleet commands.
func TestGenerateZshCompletion(t *testing.T) {
p, commands := newCompletionParser()
out := flaggy.GenerateZshCompletion(p)
verifyCompletionCoverage(t, out, commands, "zsh")
if !strings.Contains(out, "--warp") {
t.Fatalf("expected zsh completion to include long flag name: %s", out)
}
if !strings.Contains(out, "-w") {
t.Fatalf("expected zsh completion to include short flag name: %s", out)
}
if !strings.Contains(out, "sector") {
t.Fatalf("expected zsh completion to include positional name: %s", out)
}
}
// TestGenerateFishCompletion exercises fish completions with the shared fleet commands.
func TestGenerateFishCompletion(t *testing.T) {
p, commands := newCompletionParser()
out := flaggy.GenerateFishCompletion(p)
verifyCompletionCoverage(t, out, commands, "fish")
if !strings.Contains(out, "complete -c starfleet") {
t.Fatalf("expected fish completion to target starfleet: %s", out)
}
if !strings.Contains(out, "-l warp") {
t.Fatalf("expected fish completion to include long flag name: %s", out)
}
if !strings.Contains(out, "-s w") {
t.Fatalf("expected fish completion to include short flag name: %s", out)
}
if !strings.Contains(out, "sector") {
t.Fatalf("expected fish completion to include positional name: %s", out)
}
}
// TestGeneratePowerShellCompletion exercises PowerShell completions with fleet commands.
func TestGeneratePowerShellCompletion(t *testing.T) {
p, commands := newCompletionParser()
out := flaggy.GeneratePowerShellCompletion(p)
verifyCompletionCoverage(t, out, commands, "powershell")
if !strings.Contains(out, "Register-ArgumentCompleter") {
t.Fatalf("expected powershell completion to register completer: %s", out)
}
if !strings.Contains(out, "--warp") {
t.Fatalf("expected powershell completion to include long flag name: %s", out)
}
if !strings.Contains(out, "-w") {
t.Fatalf("expected powershell completion to include short flag name: %s", out)
}
if !strings.Contains(out, "sector") {
t.Fatalf("expected powershell completion to include positional name: %s", out)
}
}
// TestGenerateNushellCompletion exercises Nushell completions with the fleet commands.
func TestGenerateNushellCompletion(t *testing.T) {
p, commands := newCompletionParser()
out := flaggy.GenerateNushellCompletion(p)
verifyCompletionCoverage(t, out, commands, "nushell")
if !strings.Contains(out, "extern \"starfleet\"") {
t.Fatalf("expected nushell completion to expose extern signature: %s", out)
}
if !strings.Contains(out, "\"--warp\"") {
t.Fatalf("expected nushell completion to include long flag name: %s", out)
}
if !strings.Contains(out, "\"-w\"") {
t.Fatalf("expected nushell completion to include short flag name: %s", out)
}
if !strings.Contains(out, "\"sector\"") {
t.Fatalf("expected nushell completion to include positional name: %s", out)
}
}