From bf2734bd75b21ae137b8def499918b884c4512fc Mon Sep 17 00:00:00 2001 From: Camden Cheek Date: Wed, 17 Apr 2024 20:37:47 -0600 Subject: [PATCH] fix off-by-one --- index_test.go | 4 ++-- matchtree.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/index_test.go b/index_test.go index 1a0653df9..8608b5bfc 100644 --- a/index_test.go +++ b/index_test.go @@ -3243,7 +3243,7 @@ func TestLineAnd(t *testing.T) { } t.Run("LineMatches", func(t *testing.T) { res := searchForTest(t, b, &q) - wantRegexpCount := 2 + wantRegexpCount := 1 if gotRegexpCount := res.RegexpsConsidered; gotRegexpCount != wantRegexpCount { t.Errorf("got %d, wanted %d", gotRegexpCount, wantRegexpCount) } @@ -3254,7 +3254,7 @@ func TestLineAnd(t *testing.T) { t.Run("ChunkMatches", func(t *testing.T) { res := searchForTest(t, b, &q, chunkOpts) - wantRegexpCount := 2 // TODO: justify this change + wantRegexpCount := 1 if gotRegexpCount := res.RegexpsConsidered; gotRegexpCount != wantRegexpCount { t.Errorf("got %d, wanted %d", gotRegexpCount, wantRegexpCount) } diff --git a/matchtree.go b/matchtree.go index 436762ceb..ce30f0980 100644 --- a/matchtree.go +++ b/matchtree.go @@ -726,12 +726,12 @@ nextLine: children[j] = children[j][1:] continue nextCandidate } - if bo <= lines[i].end { + if bo < lines[i].end { hits++ continue nextChild } - // move the `lines` iterator forward until bo <= line.end - for i < len(lines) && bo > lines[i].end { + // move the `lines` iterator forward until bo < line.end + for i < len(lines) && bo >= lines[i].end { i++ } i--