diff options
| author | Eyal Posener <[email protected]> | 2017-05-06 19:47:27 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-06 19:51:33 +0300 |
| commit | dc4c327ae8cd5602ae10eeabde9bdf6fa5624286 (patch) | |
| tree | 8ebacce9b6e90c650a0f0557426b5526abfe0705 /run_test.go | |
| parent | 60345dc6db8d1247fef2fb456d2f18f3300651ac (diff) | |
Use local completion files and directories according to typed command
Diffstat (limited to 'run_test.go')
| -rw-r--r-- | run_test.go | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/run_test.go b/run_test.go index 9800b6a..0fe52d6 100644 --- a/run_test.go +++ b/run_test.go @@ -12,6 +12,10 @@ func TestCompleter_Complete(t *testing.T) { if testing.Verbose() { os.Setenv(envDebug, "1") } + err := os.Chdir("./tests") + if err != nil { + t.Fatal(err) + } c := Command{ Sub: map[string]Command{ @@ -26,13 +30,13 @@ func TestCompleter_Complete(t *testing.T) { "-flag2": PredictNothing, "-flag3": PredictSet("opt1", "opt2", "opt12"), }, - Args: PredictDirs("./tests/").Or(PredictFiles("./tests/*.md")), + Args: PredictDirs.Or(PredictFiles("*.md")), }, }, Flags: map[string]*Predicate{ "-h": PredictNothing, "-global1": PredictAnything, - "-o": PredictFiles("./tests/*.txt"), + "-o": PredictFiles("*.txt"), }, } @@ -44,7 +48,7 @@ func TestCompleter_Complete(t *testing.T) { allGlobals = append(allGlobals, flag) } - testTXTFiles := []string{"./tests/a.txt", "./tests/b.txt", "./tests/c.txt"} + testTXTFiles := []string{"./a.txt", "./b.txt", "./c.txt"} tests := []struct { args string @@ -84,19 +88,19 @@ func TestCompleter_Complete(t *testing.T) { }, { args: "sub2 ", - want: []string{"./tests", "-flag2", "-flag3", "-h", "-global1", "-o"}, + want: []string{"./", "./dir", "./readme.md", "-flag2", "-flag3", "-h", "-global1", "-o"}, }, { - args: "sub2 tests", - want: []string{"./tests", "./tests/readme.md", "./tests/dir"}, + args: "sub2 ./", + want: []string{"./", "./readme.md", "./dir"}, }, { - args: "sub2 tests/re", - want: []string{"./tests/readme.md"}, + args: "sub2 re", + want: []string{"./readme.md"}, }, { args: "sub2 -flag2 ", - want: []string{"./tests", "-flag2", "-flag3", "-h", "-global1", "-o"}, + want: []string{"./", "./dir", "./readme.md", "-flag2", "-flag3", "-h", "-global1", "-o"}, }, { args: "sub1 -fl", @@ -132,30 +136,30 @@ func TestCompleter_Complete(t *testing.T) { }, { args: "-o ", - want: []string{}, + want: testTXTFiles, }, { - args: "-o ./tes", + args: "-o ./no-su", want: []string{}, }, { - args: "-o tests/", + args: "-o ./", want: testTXTFiles, }, { - args: "-o tests", + args: "-o ", want: testTXTFiles, }, { - args: "-o ./compl", + args: "-o ./read", want: []string{}, }, { - args: "-o ./complete.go", + args: "-o ./readme.md", want: []string{}, }, { - args: "-o ./complete.go ", + args: "-o ./readme.md ", want: allGlobals, }, { |
