summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-08-11 00:07:18 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-08-11 00:07:18 +0900
commita09e411936244aa515519134dbbd938ae3cadcd4 (patch)
tree714ab2fdcd3c37adeb90c5e1bf9484f7aa5b7ded /src
parent02a7b96f33036192abb5816b5860e546e6b4e64e (diff)
Treat | as proper query when it can't be an OR operator
Diffstat (limited to 'src')
-rw-r--r--src/pattern.go5
-rw-r--r--src/pattern_test.go5
2 files changed, 7 insertions, 3 deletions
diff --git a/src/pattern.go b/src/pattern.go
index 8029fd0c..dbb3983f 100644
--- a/src/pattern.go
+++ b/src/pattern.go
@@ -152,6 +152,7 @@ func parseTerms(fuzzy bool, caseMode Case, normalize bool, str string) []termSet
sets := []termSet{}
set := termSet{}
switchSet := false
+ afterBar := false
for _, token := range tokens {
typ, inv, text := termFuzzy, false, strings.Replace(token, "\t", " ", -1)
lowerText := strings.ToLower(text)
@@ -164,10 +165,12 @@ func parseTerms(fuzzy bool, caseMode Case, normalize bool, str string) []termSet
typ = termExact
}
- if text == "|" {
+ if len(set) > 0 && !afterBar && text == "|" {
switchSet = false
+ afterBar = true
continue
}
+ afterBar = false
if strings.HasPrefix(text, "!") {
inv = true
diff --git a/src/pattern_test.go b/src/pattern_test.go
index 7adc51db..4066eb4d 100644
--- a/src/pattern_test.go
+++ b/src/pattern_test.go
@@ -16,7 +16,7 @@ func init() {
func TestParseTermsExtended(t *testing.T) {
terms := parseTerms(true, CaseSmart, false,
- "| aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$ | ^iii$ ^xxx | 'yyy | | zzz$ | !ZZZ |")
+ "aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$ | ^iii$ ^xxx | 'yyy | zzz$ | !ZZZ |")
if len(terms) != 9 ||
terms[0][0].typ != termFuzzy || terms[0][0].inv ||
terms[1][0].typ != termExact || terms[1][0].inv ||
@@ -177,7 +177,8 @@ func TestCacheKey(t *testing.T) {
test(true, "foo | bar baz", "baz", false)
test(true, "foo | bar | baz", "", false)
test(true, "foo | bar !baz", "", false)
- test(true, "| | | foo", "foo", true)
+ test(true, "| | foo", "", false)
+ test(true, "| | | foo", "foo", false)
}
func TestCacheable(t *testing.T) {