From 0be4cead2011440b0cc40f404953f1903673adc3 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 8 Jun 2015 23:16:31 +0900 Subject: Allow ^EqualMatch$ --- src/pattern_test.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/pattern_test.go') 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() -- cgit v1.2.3