diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-06-25 20:13:39 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-06-25 20:13:39 -0400 |
| commit | 65cdd46dce13ca35d73bdf3ebf75789df5581ac9 (patch) | |
| tree | 8fae52d890df565043d890c8cb1b4ed3d389e370 /src/test | |
| parent | 942c4e3d28e0eef3efc50160ad3562f7fa1b3695 (diff) | |
Fix escapeSplit to properly handle chaining escapes
escapeSplit will now properly handle arbitrary length escape sequences
and do the right thing.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/java/bjc/everge/StringUtilsTest.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/test/java/bjc/everge/StringUtilsTest.java b/src/test/java/bjc/everge/StringUtilsTest.java index 9eac017..b20e074 100644 --- a/src/test/java/bjc/everge/StringUtilsTest.java +++ b/src/test/java/bjc/everge/StringUtilsTest.java @@ -25,7 +25,20 @@ public class StringUtilsTest { @Test public void testEscapeSplit() { - assertSplitsTo("a / b/c", "/", " ", "a", "/ ", "b/c"); + assertSplitsTo("a|/||b/c", "|", "/", "a/|b", "c"); + + assertSplitsTo("a||/b", "|", "/", "a|", "b"); + } + + @Test + public void testLongSplit() { + assertSplitsTo("a||b||c", " ", "||", "a", "b", "c"); + + assertSplitsTo("a&&||b||c", "&&", "||", "a||b", "c"); + + assertSplitsTo("a&&&&||b||c", "&&", "||", "a&&", "b", "c"); + + assertSplitsTo("a&&&&&&||b||c", "&&", "||", "a&&||b", "c"); } @Test @@ -36,9 +49,25 @@ public class StringUtilsTest { } private void assertSplitsTo(String inp, String esc, String splat, String... right) { + assertSplitsTo(false, inp, esc, splat, right); + } + + private void assertSplitsTo(boolean doLog, String inp, String esc, String splat, String... right) { try { + if (doLog) StringUtils.isDebug = true; + String[] lst = StringUtils.escapeSplit(esc, splat, inp); + if (doLog) { + System.err.printf("[TRACE] Returned "); + + for (String str : lst) { + System.err.printf("(%s) ", str); + } + + System.err.println(); + } + assertArrayEquals(right, lst); } catch (Exception ex) { System.err.println("EXCEPTION"); @@ -46,6 +75,8 @@ public class StringUtilsTest { System.err.println(); assertTrue(false); + } finally { + if (doLog) StringUtils.isDebug = false; } } } |
