diff options
| author | Eyal Posener <[email protected]> | 2017-05-06 22:59:42 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-06 22:59:42 +0300 |
| commit | 8d6ebaa18327f3cb65b38ab3d0ba6b4a8dc231ea (patch) | |
| tree | e2e1d6d5db886b08e5bbc066553c602aa6319df2 | |
| parent | 91a264bb4097838b8332a30e8c24953f98b83350 (diff) | |
Add match tests
| -rw-r--r-- | match_test.go | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/match_test.go b/match_test.go new file mode 100644 index 0000000..2607c89 --- /dev/null +++ b/match_test.go @@ -0,0 +1,104 @@ +package complete + +import "testing" + +func TestMatch(t *testing.T) { + t.Parallel() + + tests := []struct { + m Matcher + prefix string + want bool + }{ + { + m: MatchPrefix("abcd"), + prefix: "", + want: true, + }, + { + m: MatchPrefix("abcd"), + prefix: "ab", + want: true, + }, + { + m: MatchPrefix("abcd"), + prefix: "ac", + want: false, + }, + { + m: MatchPrefix(""), + prefix: "ac", + want: false, + }, + { + m: MatchPrefix(""), + prefix: "", + want: true, + }, + { + m: MatchFileName("file.txt"), + prefix: "", + want: true, + }, + { + m: MatchFileName("./file.txt"), + prefix: "", + want: true, + }, + { + m: MatchFileName("./file.txt"), + prefix: "f", + want: true, + }, + { + m: MatchFileName("./file.txt"), + prefix: "file.", + want: true, + }, + { + m: MatchFileName("./file.txt"), + prefix: "./f", + want: true, + }, + { + m: MatchFileName("./file.txt"), + prefix: "other.txt", + want: false, + }, + { + m: MatchFileName("./file.txt"), + prefix: "/file.txt", + want: false, + }, + { + m: MatchFileName("/file.txt"), + prefix: "file.txt", + want: false, + }, + { + m: MatchFileName("/file.txt"), + prefix: "./file.txt", + want: false, + }, + { + m: MatchFileName("/file.txt"), + prefix: "/file.txt", + want: true, + }, + { + m: MatchFileName("/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) + } + }) + } +} |
