diff options
| author | Eyal Posener <[email protected]> | 2019-10-23 22:27:02 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2019-10-23 22:27:02 +0300 |
| commit | e24ae2ec882eef4b8d9f42177fd026d3db4bdb73 (patch) | |
| tree | fb1e8b3a633d8f2478736abb9f9e5c451ca538d3 | |
| parent | 2f2ff270a9f6adcef8351b1bdf5319b5d612b53f (diff) | |
reproduce sub command bug
| -rw-r--r-- | complete_test.go | 31 | ||||
| -rw-r--r-- | go.mod | 2 |
2 files changed, 24 insertions, 9 deletions
diff --git a/complete_test.go b/complete_test.go index 45fa304..7125223 100644 --- a/complete_test.go +++ b/complete_test.go @@ -20,6 +20,9 @@ func TestCompleter_Complete(t *testing.T) { "-flag1": PredictAnything, "-flag2": PredictNothing, }, + Sub: Commands{ + "sub11": {}, + }, }, "sub2": { Flags: Flags{ @@ -28,6 +31,11 @@ func TestCompleter_Complete(t *testing.T) { }, Args: PredictFiles("*.md"), }, + "sub3": { + Sub: Commands{ + "sub3": {}, + }, + }, }, Flags: Flags{ "-o": PredictFiles("*.txt"), @@ -47,7 +55,7 @@ func TestCompleter_Complete(t *testing.T) { { line: "cmd ", point: -1, - want: []string{"sub1", "sub2"}, + want: []string{"sub1", "sub2", "sub3"}, }, { line: "cmd -", @@ -57,7 +65,7 @@ func TestCompleter_Complete(t *testing.T) { { line: "cmd -h ", point: -1, - want: []string{"sub1", "sub2"}, + want: []string{"sub1", "sub2", "sub3"}, }, { line: "cmd -global1 ", // global1 is known follow flag @@ -67,7 +75,7 @@ func TestCompleter_Complete(t *testing.T) { { line: "cmd sub", point: -1, - want: []string{"sub1", "sub2"}, + want: []string{"sub1", "sub2", "sub3"}, }, { line: "cmd sub1", @@ -82,7 +90,12 @@ func TestCompleter_Complete(t *testing.T) { { line: "cmd sub1 ", point: -1, - want: []string{}, + want: []string{"sub11"}, + }, + { + line: "cmd sub3 ", + point: -1, + want: []string{"sub3"}, }, { line: "cmd sub1 -", @@ -142,7 +155,7 @@ func TestCompleter_Complete(t *testing.T) { { line: "cmd -no-such-flag ", point: -1, - want: []string{"sub1", "sub2"}, + want: []string{"sub1", "sub2", "sub3"}, }, { line: "cmd -no-such-flag -", @@ -157,7 +170,7 @@ func TestCompleter_Complete(t *testing.T) { { line: "cmd no-such-command ", point: -1, - want: []string{"sub1", "sub2"}, + want: []string{"sub1", "sub2", "sub3"}, }, { line: "cmd -o ", @@ -212,12 +225,12 @@ func TestCompleter_Complete(t *testing.T) { { line: "cmd -o ./readme.md ", point: -1, - want: []string{"sub1", "sub2"}, + want: []string{"sub1", "sub2", "sub3"}, }, { line: "cmd -o=./readme.md ", point: -1, - want: []string{"sub1", "sub2"}, + want: []string{"sub1", "sub2", "sub3"}, }, { line: "cmd -o sub2 -flag3 ", @@ -256,7 +269,7 @@ func TestCompleter_Complete(t *testing.T) { line: "cmd -o ", // ^ point: 4, - want: []string{"sub1", "sub2"}, + want: []string{"sub1", "sub2", "sub3"}, }, } @@ -1,3 +1,5 @@ module github.com/posener/complete require github.com/hashicorp/go-multierror v1.0.0 + +go 1.13 |
