complete/match/match_test.go

115 lines
1.7 KiB
Go
Raw Normal View History

2017-05-07 11:53:55 -05:00
package match
2017-05-06 14:59:42 -05:00
2017-05-07 11:53:55 -05:00
import (
"os"
"testing"
)
2017-05-06 14:59:42 -05:00
func TestMatch(t *testing.T) {
t.Parallel()
2017-05-07 11:53:55 -05:00
// Change to tests directory for testing completion of
// files and directories
err := os.Chdir("../tests")
if err != nil {
panic(err)
}
2017-05-06 14:59:42 -05:00
tests := []struct {
m Matcher
prefix string
want bool
}{
{
2017-05-07 11:53:55 -05:00
m: Prefix("abcd"),
2017-05-06 14:59:42 -05:00
prefix: "",
want: true,
},
{
2017-05-07 11:53:55 -05:00
m: Prefix("abcd"),
2017-05-06 14:59:42 -05:00
prefix: "ab",
want: true,
},
{
2017-05-07 11:53:55 -05:00
m: Prefix("abcd"),
2017-05-06 14:59:42 -05:00
prefix: "ac",
want: false,
},
{
2017-05-07 11:53:55 -05:00
m: Prefix(""),
2017-05-06 14:59:42 -05:00
prefix: "ac",
want: false,
},
{
2017-05-07 11:53:55 -05:00
m: Prefix(""),
2017-05-06 14:59:42 -05:00
prefix: "",
want: true,
},
{
2017-05-07 11:53:55 -05:00
m: File("file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "",
want: true,
},
{
2017-05-07 11:53:55 -05:00
m: File("./file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "",
want: true,
},
{
2017-05-07 11:53:55 -05:00
m: File("./file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "f",
want: true,
},
{
2017-05-07 11:53:55 -05:00
m: File("./file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "file.",
want: true,
},
{
2017-05-07 11:53:55 -05:00
m: File("./file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "./f",
want: true,
},
{
2017-05-07 11:53:55 -05:00
m: File("./file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "other.txt",
want: false,
},
{
2017-05-07 11:53:55 -05:00
m: File("./file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "/file.txt",
want: false,
},
{
2017-05-07 11:53:55 -05:00
m: File("/file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "file.txt",
want: false,
},
{
2017-05-07 11:53:55 -05:00
m: File("/file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "./file.txt",
want: false,
},
{
2017-05-07 11:53:55 -05:00
m: File("/file.txt"),
2017-05-06 14:59:42 -05:00
prefix: "/file.txt",
want: true,
},
{
2017-05-07 11:53:55 -05:00
m: File("/file.txt"),
2017-05-06 14:59:42 -05:00
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)
}
})
}
}