summaryrefslogtreecommitdiff
path: root/testing.go
blob: 3336aa67c86334307413bc66c3397ddf8fc586b2 (plain)
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
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
		}
	}
}