From 572087d22b013df238fad5b7a943bc739a53f02b Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Fri, 14 Jun 2013 15:09:53 +0000 Subject: [PATCH] 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 --- .../commons/lang3/StringUtilsEqualsIndexOfTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java index 663c00af4..e02ed2d0e 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java @@ -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)); }