Add more tests showing the behaviour on the index boundary

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1493107 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2013-06-14 15:09:53 +00:00
parent cf4979715f
commit 572087d22b
1 changed files with 13 additions and 0 deletions

View File

@ -619,6 +619,12 @@ public class StringUtilsEqualsIndexOfTest {
assertEquals(2, StringUtils.indexOf("aabaabaa", "b", -1));
assertEquals(2,StringUtils.indexOf("aabaabaa", "", 2));
// Test that startIndex works correctly, i.e. cannot match before startIndex
assertEquals(7, StringUtils.indexOf("12345678", "8", 5));
assertEquals(7, StringUtils.indexOf("12345678", "8", 6));
assertEquals(7, StringUtils.indexOf("12345678", "8", 7)); // 7 is last index
assertEquals(-1, StringUtils.indexOf("12345678", "8", 8));
assertEquals(5, StringUtils.indexOf(new StringBuilder("aabaabaa"), "b", 3));
}
@ -843,6 +849,13 @@ public class StringUtilsEqualsIndexOfTest {
assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", "b", -1));
assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", "b", 0));
assertEquals(0, StringUtils.lastIndexOf("aabaabaa", "a", 0));
assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", "a", -1));
// Test that fromIndex works correctly, i.e. cannot match after fromIndex
assertEquals(7, StringUtils.lastIndexOf("12345678", "8", 9));
assertEquals(7, StringUtils.lastIndexOf("12345678", "8", 8));
assertEquals(7, StringUtils.lastIndexOf("12345678", "8", 7)); // 7 is last index
assertEquals(-1, StringUtils.lastIndexOf("12345678", "8", 6));
assertEquals(2, StringUtils.lastIndexOf(new StringBuilder("aabaabaa"), "b", 3));
}