summaryrefslogtreecommitdiffstats
path: root/src/pattern_test.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-06-08 23:16:31 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-06-08 23:17:24 +0900
commit0be4cead2011440b0cc40f404953f1903673adc3 (patch)
tree3295d36cace54a5ead0ddb284815b7eb9592da81 /src/pattern_test.go
parent443a80f254c8a21c17de910533bb11fcd253eb02 (diff)
Allow ^EqualMatch$
Diffstat (limited to 'src/pattern_test.go')
-rw-r--r--src/pattern_test.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/pattern_test.go b/src/pattern_test.go
index 7f00272a..fe6561c1 100644
--- a/src/pattern_test.go
+++ b/src/pattern_test.go
@@ -8,8 +8,8 @@ import (
func TestParseTermsExtended(t *testing.T) {
terms := parseTerms(ModeExtended, CaseSmart,
- "aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$")
- if len(terms) != 8 ||
+ "aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$ ^iii$")
+ if len(terms) != 9 ||
terms[0].typ != termFuzzy || terms[0].inv ||
terms[1].typ != termExact || terms[1].inv ||
terms[2].typ != termPrefix || terms[2].inv ||
@@ -17,7 +17,8 @@ func TestParseTermsExtended(t *testing.T) {
terms[4].typ != termFuzzy || !terms[4].inv ||
terms[5].typ != termExact || !terms[5].inv ||
terms[6].typ != termPrefix || !terms[6].inv ||
- terms[7].typ != termSuffix || !terms[7].inv {
+ terms[7].typ != termSuffix || !terms[7].inv ||
+ terms[8].typ != termEqual || terms[8].inv {
t.Errorf("%s", terms)
}
for idx, term := range terms {
@@ -65,6 +66,22 @@ func TestExact(t *testing.T) {
}
}
+func TestEqual(t *testing.T) {
+ defer clearPatternCache()
+ clearPatternCache()
+ pattern := BuildPattern(ModeExtended, CaseSmart, []Range{}, nil, []rune("^AbC$"))
+
+ match := func(str string, sidxExpected int, eidxExpected int) {
+ runes := []rune(str)
+ sidx, eidx := algo.EqualMatch(pattern.caseSensitive, &runes, pattern.terms[0].text)
+ if sidx != sidxExpected || eidx != eidxExpected {
+ t.Errorf("%s / %d / %d", pattern.terms, sidx, eidx)
+ }
+ }
+ match("ABC", -1, -1)
+ match("AbC", 0, 3)
+}
+
func TestCaseSensitivity(t *testing.T) {
defer clearPatternCache()
clearPatternCache()