|
|
@ -5,11 +5,11 @@ import (
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func assertMatch(t *testing.T, fun func(bool, []rune, []rune) (int, int), caseSensitive bool, input string, pattern string, sidx int, eidx int) {
|
|
|
|
func assertMatch(t *testing.T, fun func(bool, bool, []rune, []rune) (int, int), caseSensitive bool, forward bool, input string, pattern string, sidx int, eidx int) {
|
|
|
|
if !caseSensitive {
|
|
|
|
if !caseSensitive {
|
|
|
|
pattern = strings.ToLower(pattern)
|
|
|
|
pattern = strings.ToLower(pattern)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s, e := fun(caseSensitive, []rune(input), []rune(pattern))
|
|
|
|
s, e := fun(caseSensitive, forward, []rune(input), []rune(pattern))
|
|
|
|
if s != sidx {
|
|
|
|
if s != sidx {
|
|
|
|
t.Errorf("Invalid start index: %d (expected: %d, %s / %s)", s, sidx, input, pattern)
|
|
|
|
t.Errorf("Invalid start index: %d (expected: %d, %s / %s)", s, sidx, input, pattern)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -19,33 +19,51 @@ func assertMatch(t *testing.T, fun func(bool, []rune, []rune) (int, int), caseSe
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestFuzzyMatch(t *testing.T) {
|
|
|
|
func TestFuzzyMatch(t *testing.T) {
|
|
|
|
assertMatch(t, FuzzyMatch, false, "fooBarbaz", "oBZ", 2, 9)
|
|
|
|
assertMatch(t, FuzzyMatch, false, true, "fooBarbaz", "oBZ", 2, 9)
|
|
|
|
assertMatch(t, FuzzyMatch, true, "fooBarbaz", "oBZ", -1, -1)
|
|
|
|
assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBZ", -1, -1)
|
|
|
|
assertMatch(t, FuzzyMatch, true, "fooBarbaz", "oBz", 2, 9)
|
|
|
|
assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBz", 2, 9)
|
|
|
|
assertMatch(t, FuzzyMatch, true, "fooBarbaz", "fooBarbazz", -1, -1)
|
|
|
|
assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "fooBarbazz", -1, -1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestFuzzyMatchBackward(t *testing.T) {
|
|
|
|
|
|
|
|
assertMatch(t, FuzzyMatch, false, true, "foobar fb", "fb", 0, 4)
|
|
|
|
|
|
|
|
assertMatch(t, FuzzyMatch, false, false, "foobar fb", "fb", 7, 9)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestExactMatchNaive(t *testing.T) {
|
|
|
|
func TestExactMatchNaive(t *testing.T) {
|
|
|
|
assertMatch(t, ExactMatchNaive, false, "fooBarbaz", "oBA", 2, 5)
|
|
|
|
for _, dir := range []bool{true, false} {
|
|
|
|
assertMatch(t, ExactMatchNaive, true, "fooBarbaz", "oBA", -1, -1)
|
|
|
|
assertMatch(t, ExactMatchNaive, false, dir, "fooBarbaz", "oBA", 2, 5)
|
|
|
|
assertMatch(t, ExactMatchNaive, true, "fooBarbaz", "fooBarbazz", -1, -1)
|
|
|
|
assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "oBA", -1, -1)
|
|
|
|
|
|
|
|
assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "fooBarbazz", -1, -1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestExactMatchNaiveBackward(t *testing.T) {
|
|
|
|
|
|
|
|
assertMatch(t, FuzzyMatch, false, true, "foobar foob", "oo", 1, 3)
|
|
|
|
|
|
|
|
assertMatch(t, FuzzyMatch, false, false, "foobar foob", "oo", 8, 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestPrefixMatch(t *testing.T) {
|
|
|
|
func TestPrefixMatch(t *testing.T) {
|
|
|
|
assertMatch(t, PrefixMatch, false, "fooBarbaz", "Foo", 0, 3)
|
|
|
|
for _, dir := range []bool{true, false} {
|
|
|
|
assertMatch(t, PrefixMatch, true, "fooBarbaz", "Foo", -1, -1)
|
|
|
|
assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "Foo", 0, 3)
|
|
|
|
assertMatch(t, PrefixMatch, false, "fooBarbaz", "baz", -1, -1)
|
|
|
|
assertMatch(t, PrefixMatch, true, dir, "fooBarbaz", "Foo", -1, -1)
|
|
|
|
|
|
|
|
assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "baz", -1, -1)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestSuffixMatch(t *testing.T) {
|
|
|
|
func TestSuffixMatch(t *testing.T) {
|
|
|
|
assertMatch(t, SuffixMatch, false, "fooBarbaz", "Foo", -1, -1)
|
|
|
|
for _, dir := range []bool{true, false} {
|
|
|
|
assertMatch(t, SuffixMatch, false, "fooBarbaz", "baz", 6, 9)
|
|
|
|
assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "Foo", -1, -1)
|
|
|
|
assertMatch(t, SuffixMatch, true, "fooBarbaz", "Baz", -1, -1)
|
|
|
|
assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "baz", 6, 9)
|
|
|
|
|
|
|
|
assertMatch(t, SuffixMatch, true, dir, "fooBarbaz", "Baz", -1, -1)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestEmptyPattern(t *testing.T) {
|
|
|
|
func TestEmptyPattern(t *testing.T) {
|
|
|
|
assertMatch(t, FuzzyMatch, true, "foobar", "", 0, 0)
|
|
|
|
for _, dir := range []bool{true, false} {
|
|
|
|
assertMatch(t, ExactMatchNaive, true, "foobar", "", 0, 0)
|
|
|
|
assertMatch(t, FuzzyMatch, true, dir, "foobar", "", 0, 0)
|
|
|
|
assertMatch(t, PrefixMatch, true, "foobar", "", 0, 0)
|
|
|
|
assertMatch(t, ExactMatchNaive, true, dir, "foobar", "", 0, 0)
|
|
|
|
assertMatch(t, SuffixMatch, true, "foobar", "", 6, 6)
|
|
|
|
assertMatch(t, PrefixMatch, true, dir, "foobar", "", 0, 0)
|
|
|
|
|
|
|
|
assertMatch(t, SuffixMatch, true, dir, "foobar", "", 6, 6)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|