From dd1f26522c965612cb4f55b44e700b8b85868b27 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 1 Feb 2017 02:05:58 +0900 Subject: [PATCH] Fix caching scheme when --exact is set and '-prefix is used --- src/pattern.go | 2 +- src/pattern_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/pattern.go b/src/pattern.go index 731104f..4f64660 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -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 } diff --git a/src/pattern_test.go b/src/pattern_test.go index ea0082f..9d66c79 100644 --- a/src/pattern_test.go +++ b/src/pattern_test.go @@ -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) +}