diff options
| author | Eyal Posener <[email protected]> | 2019-11-14 06:51:44 +0200 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2019-11-18 01:05:47 +0200 |
| commit | 8724aaf18312e54750540a9578e00d61b1c545d8 (patch) | |
| tree | d3e736b4fb279975bbcc017ae1bad53e454c5773 /testing.go | |
| parent | 05b68ffc813dd10c420993cb1cf927b346c057b8 (diff) | |
V2
Diffstat (limited to 'testing.go')
| -rw-r--r-- | testing.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/testing.go b/testing.go new file mode 100644 index 0000000..3336aa6 --- /dev/null +++ b/testing.go @@ -0,0 +1,29 @@ +package complete + +import ( + "sort" + "testing" + + "github.com/posener/complete/internal/arg" +) + +// Test is a testing helper function for testing bash completion of a given completer. +func Test(t *testing.T, cmp Completer, args string, want []string) { + t.Helper() + got, err := completer{Completer: cmp, args: arg.Parse(args)}.complete() + if err != nil { + t.Fatal(err) + } + sort.Strings(got) + sort.Strings(want) + if len(want) != len(got) { + t.Errorf("got != want: want = %+v, got = %+v", want, got) + return + } + for i := range want { + if want[i] != got[i] { + t.Errorf("got != want: want = %+v, got = %+v", want, got) + return + } + } +} |
