diff options
| author | Eyal Posener <[email protected]> | 2017-05-06 21:04:11 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-06 21:04:11 +0300 |
| commit | 2b6aed2b1e974a733c0dc614a9617c33a54c208c (patch) | |
| tree | d9f9de0148c079071095e96c1033c39f0c898de1 /run_test.go | |
| parent | 07b98cb91243293e26564058a78f28b83aa81cd4 (diff) | |
| parent | 9963a854946be0603f9e79ccba0a8b2688b20053 (diff) | |
Merge pull request #3 from posener/predicate-as-function-type
Predicate as function type
Diffstat (limited to 'run_test.go')
| -rw-r--r-- | run_test.go | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/run_test.go b/run_test.go index 9800b6a..4cbf36d 100644 --- a/run_test.go +++ b/run_test.go @@ -9,30 +9,37 @@ import ( func TestCompleter_Complete(t *testing.T) { t.Parallel() + // Set debug environment variable so logs will be printed if testing.Verbose() { os.Setenv(envDebug, "1") } + // Change to tests directory for testing completion of files and directories + err := os.Chdir("./tests") + if err != nil { + t.Fatal(err) + } + c := Command{ Sub: map[string]Command{ "sub1": { - Flags: map[string]*Predicate{ + Flags: map[string]Predicate{ "-flag1": PredictAnything, "-flag2": PredictNothing, }, }, "sub2": { - Flags: map[string]*Predicate{ + Flags: map[string]Predicate{ "-flag2": PredictNothing, "-flag3": PredictSet("opt1", "opt2", "opt12"), }, - Args: PredictDirs("./tests/").Or(PredictFiles("./tests/*.md")), + Args: Predicate(PredictDirs).Or(PredictFiles("*.md")), }, }, - Flags: map[string]*Predicate{ + Flags: map[string]Predicate{ "-h": PredictNothing, "-global1": PredictAnything, - "-o": PredictFiles("./tests/*.txt"), + "-o": PredictFiles("*.txt"), }, } @@ -44,7 +51,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 +91,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 +139,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, }, { |
