Fix caching scheme when --exact is set and '-prefix is used

This commit is contained in:
Junegunn Choi 2017-02-01 02:05:58 +09:00
parent 712b7b2188
commit dd1f26522c
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
2 changed files with 19 additions and 1 deletions

View File

@ -101,7 +101,7 @@ func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case,
for idx, term := range termSet {
// If the query contains inverse search terms or OR operators,
// we cannot cache the search scope
if !cacheable || idx > 0 || term.inv {
if !cacheable || idx > 0 || term.inv || !fuzzy && term.typ != termExact {
cacheable = false
break Loop
}

View File

@ -186,3 +186,21 @@ func TestCacheKey(t *testing.T) {
test(true, "foo | bar !baz", "", false)
test(true, "| | | foo", "foo", true)
}
func TestCacheable(t *testing.T) {
test := func(fuzzy bool, str string, cacheable bool) {
clearPatternCache()
pat := BuildPattern(fuzzy, algo.FuzzyMatchV2, true, CaseSmart, true, true, true, []Range{}, Delimiter{}, []rune(str))
if cacheable != pat.cacheable {
t.Errorf("Invalid Pattern.cacheable for \"%s\": %v (expected: %v)", str, pat.cacheable, cacheable)
}
}
test(true, "foo bar", true)
test(true, "foo 'bar", true)
test(true, "foo !bar", false)
test(false, "foo bar", true)
test(false, "foo '", true)
test(false, "foo 'bar", false)
test(false, "foo !bar", false)
}