Skip to content

Commit 4933c6a

Browse files
committed
Use a valid window as the negative case and cover isMatch(CharSequence, int) directly
1 parent 2eac7bd commit 4933c6a

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎src/test/java/org/apache/commons/text/matcher/StringMatcherTest.java‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,20 @@ public void testIsMatchCharSequencePassesBufferStartThrough() {
7676
assertEquals(5, viaCharSequence.lastBufferEnd);
7777
}
7878

79+
@Test
80+
public void testIsMatchCharSequenceStartDelegatesThroughTheCorrectedOverload() {
81+
assertEquals(2, new RecordingMatcher("ab").isMatch("xabz", 1));
82+
assertEquals(0, new RecordingMatcher("ab").isMatch("xabz", 2));
83+
}
84+
7985
@Test
8086
public void testIsMatchOverloadsAgreeOnTheSameWindow() {
81-
assertEquals(new RecordingMatcher("ab").isMatch("xabz".toCharArray(), 1, 0, 4),
82-
new RecordingMatcher("ab").isMatch("xabz", 1, 0, 4));
83-
assertEquals(new RecordingMatcher("ab").isMatch("xabz".toCharArray(), 1, 2, 4),
84-
new RecordingMatcher("ab").isMatch("xabz", 1, 2, 4));
87+
// The window covers the whole pattern.
88+
assertEquals(2, new RecordingMatcher("ab").isMatch("xabz".toCharArray(), 1, 0, 4));
89+
assertEquals(2, new RecordingMatcher("ab").isMatch("xabz", 1, 0, 4));
90+
// A valid window that ends before the pattern is complete.
91+
assertEquals(0, new RecordingMatcher("ab").isMatch("xabz".toCharArray(), 1, 0, 2));
92+
assertEquals(0, new RecordingMatcher("ab").isMatch("xabz", 1, 0, 2));
8593
}
8694

8795
/**

0 commit comments

Comments
 (0)