test: fix parse tests & add completion snapshot tests

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
Chapman Pendery
2023-09-26 17:24:40 -07:00
parent 389c213e35
commit b58211f4ee
17 changed files with 135 additions and 18 deletions
+9 -1
View File
@@ -11,4 +11,12 @@ clean:
.PHONY: build
build:
go build -o clac main.go
go build -o clac main.go
.PHONY: snapshot
snapshot:
UPDATE_SNAPSHOTS=true go test ./...
.PHONY: test
test:
go test ./...
@@ -0,0 +1,3 @@
([]string) (len=1) {
(string) (len=12) "--bug-report"
}
@@ -0,0 +1,3 @@
([]string) (len=1) {
(string) (len=6) "status"
}
@@ -0,0 +1,20 @@
([]string) (len=18) {
(string) (len=17) "--no-descriptions",
(string) (len=22) "--artifact-server-path",
(string) (len=22) "--artifact-server-port",
(string) (len=24) "--container-architecture",
(string) (len=25) "--container-daemon-socket",
(string) (len=2) "-C",
(string) (len=2) "-n",
(string) (len=10) "--env-file",
(string) (len=17) "--github-instance",
(string) (len=18) "--insecure-secrets",
(string) (len=6) "--json",
(string) (len=12) "--no-recurse",
(string) (len=18) "--no-skip-checkout",
(string) (len=2) "-q",
(string) (len=13) "--secret-file",
(string) (len=2) "-v",
(string) (len=2) "-W",
(string) (len=2) "-h"
}
@@ -0,0 +1,12 @@
([]string) (len=10) {
(string) (len=9) "--nobreak",
(string) (len=9) "--nocolor",
(string) (len=12) "--nofilename",
(string) (len=10) "--nofollow",
(string) (len=9) "--nogroup",
(string) (len=11) "--noheading",
(string) (len=8) "--nommap",
(string) (len=13) "--nomultiline",
(string) (len=11) "--norecurse",
(string) (len=11) "--nonumbers"
}
@@ -0,0 +1,3 @@
([]string) (len=1) {
(string) (len=2) "-W"
}
@@ -0,0 +1,5 @@
([]string) (len=3) {
(string) (len=5) "stage",
(string) (len=6) "status",
(string) (len=5) "stash"
}
@@ -0,0 +1,3 @@
([]string) (len=1) {
(string) (len=3) "zsh"
}
+48
View File
@@ -0,0 +1,48 @@
package autocomplete
import (
"testing"
"github.com/bradleyjkemp/cupaloy"
"github.com/stretchr/testify/assert"
)
func TestLoadSuggestions(t *testing.T) {
tests := []struct {
Name string
Cmd string
Skip bool
}{
{Name: "partialPrefixFilter", Cmd: "git sta"},
{Name: "completePrefixFilter", Cmd: "git stat"},
{Name: "emptySuggestions", Cmd: "git to"},
{Name: "alreadyUsedSuggestion", Cmd: "cd ~ "},
{Name: "alreadyUsedOption", Cmd: "act --bind --b"},
{Name: "exclusiveOnOption", Cmd: "ag --affinity --no"},
{Name: "providedSuggestion", Cmd: "bw completion --shell "},
{Name: "fullyTypedSuggestion", Cmd: "ls -W"},
{Name: "noOptionsSuggestedAfterVariadicArg", Cmd: "ls item -"},
{Name: "providedArgDescription", Cmd: "act completion bash -a "},
{Name: "completedOptionWithArg", Cmd: "act completion bash -a 'actor' "},
{Name: "command", Cmd: "sudo git sta", Skip: true}, // TODO: fix skipped test
}
for _, test := range tests {
test := test
t.Run(test.Name, func(tc *testing.T) {
tc.Parallel()
if test.Skip {
tc.SkipNow()
}
suggestions, argDescription, _ := LoadSuggestions(test.Cmd)
cleanSuggestions := []string{}
for _, suggestion := range suggestions {
cleanSuggestions = append(cleanSuggestions, suggestion.Name)
}
assert.NoError(tc, cupaloy.SnapshotMulti(test.Name+"-"+"suggestions", cleanSuggestions))
if argDescription != "" {
assert.NoError(tc, cupaloy.SnapshotMulti(test.Name+"-"+"argumentDescription", argDescription))
}
})
}
}
+17 -17
View File
@@ -11,23 +11,23 @@ func TestParseCommand(t *testing.T) {
cmd string
expected []commandToken
}{
{"cmd --flag value ", []commandToken{{"cmd", true}, {"--flag", true}, {"value", true}}},
{"cmd --flag 'value' ", []commandToken{{"cmd", true}, {"--flag", true}, {"'value'", true}}},
{"cmd --flag=value ", []commandToken{{"cmd", true}, {"--flag", true}, {"value", true}}},
{"cmd --flag='value' ", []commandToken{{"cmd", true}, {"--flag", true}, {"'value'", true}}},
{"cmd 'value' ", []commandToken{{"cmd", true}, {"'value'", true}}},
{"cmd value ", []commandToken{{"cmd", true}, {"value", true}}},
{"cmd -f", []commandToken{{"cmd", true}, {"-f", false}}},
{"cmd -f=value ", []commandToken{{"cmd", true}, {"-f", true}, {"value", true}}},
{"cmd -f value ", []commandToken{{"cmd", true}, {"-f", true}, {"value", true}}},
{"cmd -f 'value' ", []commandToken{{"cmd", true}, {"-f", true}, {"'value'", true}}},
{"cmd -f='value' ", []commandToken{{"cmd", true}, {"-f", true}, {"'value'", true}}},
{"cmd -f='val", []commandToken{{"cmd", true}, {"-f", true}, {"'val", false}}},
{"cmd -f", []commandToken{{"cmd", true}, {"-f", false}}},
{"cmd -f=", []commandToken{{"cmd", true}, {"-f", true}}},
{"cmd -f ", []commandToken{{"cmd", true}, {"-f", true}}},
{"cmd", []commandToken{{"cmd", false}}},
{"cmd ", []commandToken{{"cmd", true}}},
{"cmd --flag value ", []commandToken{{"cmd", true, false}, {"--flag", true, true}, {"value", true, false}}},
{"cmd --flag 'value' ", []commandToken{{"cmd", true, false}, {"--flag", true, true}, {"'value'", true, false}}},
{"cmd --flag=value ", []commandToken{{"cmd", true, false}, {"--flag", true, true}, {"value", true, false}}},
{"cmd --flag='value' ", []commandToken{{"cmd", true, false}, {"--flag", true, true}, {"'value'", true, false}}},
{"cmd 'value' ", []commandToken{{"cmd", true, false}, {"'value'", true, false}}},
{"cmd value ", []commandToken{{"cmd", true, false}, {"value", true, false}}},
{"cmd -f", []commandToken{{"cmd", true, false}, {"-f", false, false}}},
{"cmd -f=value ", []commandToken{{"cmd", true, false}, {"-f", true, true}, {"value", true, false}}},
{"cmd -f value ", []commandToken{{"cmd", true, false}, {"-f", true, true}, {"value", true, false}}},
{"cmd -f 'value' ", []commandToken{{"cmd", true, false}, {"-f", true, true}, {"'value'", true, false}}},
{"cmd -f='value' ", []commandToken{{"cmd", true, false}, {"-f", true, true}, {"'value'", true, false}}},
{"cmd -f='val", []commandToken{{"cmd", true, false}, {"-f", true, true}, {"'val", false, false}}},
{"cmd -f", []commandToken{{"cmd", true, false}, {"-f", false, false}}},
{"cmd -f=", []commandToken{{"cmd", true, false}, {"-f", true, true}}},
{"cmd -f ", []commandToken{{"cmd", true, false}, {"-f", true, true}}},
{"cmd", []commandToken{{"cmd", false, false}}},
{"cmd ", []commandToken{{"cmd", true, false}}},
}
for _, test := range tests {
+1
View File
@@ -19,6 +19,7 @@ require (
require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
+2
View File
@@ -4,6 +4,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible h1:UafIjBvWQmS9i/xRg+CamMrnLTKNzo+bdmT/oH34c2Y=
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible/go.mod h1:Au1Xw1sgaJ5iSFktEhYsS0dbQiS1B0/XMXl+42y9Ilk=
github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY=
github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc=
github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY=