summaryrefslogtreecommitdiff
path: root/match/match_test.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-08 06:33:45 +0300
committerGitHub <[email protected]>2017-05-08 06:33:45 +0300
commit6dd6a04d241b1c267d686d5b4b112f8e8d3f7338 (patch)
tree28d9df10ae15cb7736f6a57f904eaf95083097ee /match/match_test.go
parente8f6dfad584cb1e3082bc7ea82f8c0551dd944b3 (diff)
parent328144c31b5abd57be42f18ffb8a442c78619097 (diff)
Merge pull request #8 from posener/move-match
Move match
Diffstat (limited to 'match/match_test.go')
-rw-r--r--match/match_test.go114
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)
+ }
+ })
+ }
+}