diff options
| author | Eyal Posener <[email protected]> | 2019-07-05 17:33:47 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-07-05 17:33:47 +0300 |
| commit | 2f2ff270a9f6adcef8351b1bdf5319b5d612b53f (patch) | |
| tree | 0dbc83883d33ac239db651f19be3fe67fd3dc361 /predict_test.go | |
| parent | 6ffe496ea9530c0638974624ed9dd429f9ad592e (diff) | |
| parent | 72c5c945f0d5861ba1d4e51a0a5ac36a4bef3868 (diff) | |
Merge pull request #98 from posener/refactor
Some refactorings
Diffstat (limited to 'predict_test.go')
| -rw-r--r-- | predict_test.go | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/predict_test.go b/predict_test.go index 24df78d..c376207 100644 --- a/predict_test.go +++ b/predict_test.go @@ -1,6 +1,8 @@ package complete import ( + "fmt" + "os" "sort" "strings" "testing" @@ -167,3 +169,103 @@ func TestPredicate(t *testing.T) { } } } + +func TestMatchFile(t *testing.T) { + t.Parallel() + + // Change to tests directory for testing completion of + // files and directories + err := os.Chdir("../tests") + if err != nil { + panic(err) + } + + type matcherTest struct { + prefix string + want bool + } + + tests := []struct { + long string + tests []matcherTest + }{ + { + long: "file.txt", + tests: []matcherTest{ + {prefix: "", want: true}, + {prefix: "f", want: true}, + {prefix: "./f", want: true}, + {prefix: "./.", want: false}, + {prefix: "file.", want: true}, + {prefix: "./file.", want: true}, + {prefix: "file.txt", want: true}, + {prefix: "./file.txt", want: true}, + {prefix: "other.txt", want: false}, + {prefix: "/other.txt", want: false}, + {prefix: "/file.txt", want: false}, + {prefix: "/fil", want: false}, + {prefix: "/file.txt2", want: false}, + {prefix: "/.", want: false}, + }, + }, + { + long: "./file.txt", + tests: []matcherTest{ + {prefix: "", want: true}, + {prefix: "f", want: true}, + {prefix: "./f", want: true}, + {prefix: "./.", want: false}, + {prefix: "file.", want: true}, + {prefix: "./file.", want: true}, + {prefix: "file.txt", want: true}, + {prefix: "./file.txt", want: true}, + {prefix: "other.txt", want: false}, + {prefix: "/other.txt", want: false}, + {prefix: "/file.txt", want: false}, + {prefix: "/fil", want: false}, + {prefix: "/file.txt2", want: false}, + {prefix: "/.", want: false}, + }, + }, + { + long: "/file.txt", + tests: []matcherTest{ + {prefix: "", want: true}, + {prefix: "f", want: false}, + {prefix: "./f", want: false}, + {prefix: "./.", want: false}, + {prefix: "file.", want: false}, + {prefix: "./file.", want: false}, + {prefix: "file.txt", want: false}, + {prefix: "./file.txt", want: false}, + {prefix: "other.txt", want: false}, + {prefix: "/other.txt", want: false}, + {prefix: "/file.txt", want: true}, + {prefix: "/fil", want: true}, + {prefix: "/file.txt2", want: false}, + {prefix: "/.", want: false}, + }, + }, + { + long: "./", + tests: []matcherTest{ + {prefix: "", want: true}, + {prefix: ".", want: true}, + {prefix: "./", want: true}, + {prefix: "./.", want: false}, + }, + }, + } + + for _, tt := range tests { + for _, ttt := range tt.tests { + name := fmt.Sprintf("long=%q&prefix=%q", tt.long, ttt.prefix) + t.Run(name, func(t *testing.T) { + got := matchFile(tt.long, ttt.prefix) + if got != ttt.want { + t.Errorf("Failed %s: got = %t, want: %t", name, got, ttt.want) + } + }) + } + } +} |
