diff options
| author | Eyal Posener <[email protected]> | 2017-05-07 19:53:55 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-07 19:57:41 +0300 |
| commit | 6fb4875efa1f536813da29972a0c3250bde8b5eb (patch) | |
| tree | c7ee97d75ed8d1d6c734256e3ff789402571bcca /match/match_test.go | |
| parent | e8f6dfad584cb1e3082bc7ea82f8c0551dd944b3 (diff) | |
Move match to a separate package
Diffstat (limited to 'match/match_test.go')
| -rw-r--r-- | match/match_test.go | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/match/match_test.go b/match/match_test.go new file mode 100644 index 0000000..f9afd46 --- /dev/null +++ b/match/match_test.go @@ -0,0 +1,114 @@ +package match + +import ( + "os" + "testing" +) + +func TestMatch(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) + } + + tests := []struct { + m Matcher + prefix string + want bool + }{ + { + m: Prefix("abcd"), + prefix: "", + want: true, + }, + { + m: Prefix("abcd"), + prefix: "ab", + want: true, + }, + { + m: Prefix("abcd"), + prefix: "ac", + want: false, + }, + { + m: Prefix(""), + prefix: "ac", + want: false, + }, + { + m: Prefix(""), + prefix: "", + want: true, + }, + { + m: File("file.txt"), + prefix: "", + want: true, + }, + { + m: File("./file.txt"), + prefix: "", + want: true, + }, + { + m: File("./file.txt"), + prefix: "f", + want: true, + }, + { + m: File("./file.txt"), + prefix: "file.", + want: true, + }, + { + m: File("./file.txt"), + prefix: "./f", + want: true, + }, + { + m: File("./file.txt"), + prefix: "other.txt", + want: false, + }, + { + m: File("./file.txt"), + prefix: "/file.txt", + want: false, + }, + { + m: File("/file.txt"), + prefix: "file.txt", + want: false, + }, + { + m: File("/file.txt"), + prefix: "./file.txt", + want: false, + }, + { + m: File("/file.txt"), + prefix: "/file.txt", + want: true, + }, + { + m: File("/file.txt"), + prefix: "/fil", + want: true, + }, + } + + for _, tt := range tests { + name := tt.m.String() + "/" + tt.prefix + t.Run(name, func(t *testing.T) { + got := tt.m.Match(tt.prefix) + if got != tt.want { + t.Errorf("Failed %s: got = %t, want: %t", name, got, tt.want) + } + }) + } +} |
