From 2fa8f2956c1c52ad2282c71509a163de7967ff2d Mon Sep 17 00:00:00 2001 From: student Date: Mon, 20 Mar 2017 11:50:14 -0400 Subject: Minor testing reorg --- .../java/bjc/utils/parserutils/TokenUtils.java | 3 +- .../bjc/utils/test/parserutils/TokenUtilsTest.java | 87 ++++++++++++++++++++-- 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java index 4e2bc22..69315cb 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java @@ -153,7 +153,8 @@ public class TokenUtils { while (possibleEscapeFinder.find()) { if (!escapeFinder.find()) { - throw new IllegalArgumentException("Illegal escape sequence " + possibleEscapeFinder.group()); + throw new IllegalArgumentException( + String.format("Illegal escape sequence '%s' at position %d", possibleEscapeFinder.group(), possibleEscapeFinder.start())); } String escapeSeq = escapeFinder.group(); diff --git a/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java b/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java index 371a50a..0230943 100644 --- a/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java +++ b/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java @@ -12,14 +12,14 @@ import org.junit.rules.ExpectedException; import static bjc.utils.parserutils.TokenUtils.*; -public class TokenUtilsTest_removeDQuoted { +public class TokenUtilsTest { @Rule - public ExpectedException exp; - - public TokenUtilsTest_removeDQuoted(ExpectedException exp) { - this.exp = exp; - } - + public ExpectedException exp = ExpectedException.none(); + + /* + * Test removeDQuoted + */ + /* * Check handling of mismatched strings with no matching strings. */ @@ -52,6 +52,25 @@ public class TokenUtilsTest_removeDQuoted { assertThat(onSingleMatchString, hasItems("hello", "\"there\"")); } + /* + * Check handling of strings with multiple quoted strings in a row. + */ + @Test + public void testRemoveDQuoted_MultipleSerialString() { + List onMultipleSerialMatchString = removeDQuotedStrings("\"hello\"\"there\""); + + assertThat(onMultipleSerialMatchString, hasItems("\"hello\"", "\"there\"")); + } + + /* + * Check handling of strings with multiple interleaved strings. + */ + @Test + public void testRemoveDQuoted_MultipleInterleavedString() { + List onMultipleInterleaveMatchString = removeDQuotedStrings("one\"two\"three\"four\""); + + assertThat(onMultipleInterleaveMatchString, hasItems("one", "\"two\"", "three", "\"four\"")); + } /* * Check handling of strings without embedded strings. */ @@ -71,4 +90,58 @@ public class TokenUtilsTest_removeDQuoted { assertThat(onEmptyString, hasItems("")); } + + /* + * Test descapeString + */ + /* + * Check handling of empty strings. + */ + @Test + public void testDescapeString_EmptyString() { + String onEmptyString = descapeString(""); + + assertThat(onEmptyString, is("")); + } + + /* + * Check handling of strings without escapes + */ + @Test + public void testDescapeString_NonescapeString() { + String onNonescapeString = descapeString("hello there"); + + assertThat(onNonescapeString, is("hello there")); + } + + /* + * Check handling of strings with single escapes. + */ + @Test + public void testDescapeString_SingleEscapeString() { + String onSingleEscapeString = descapeString("hello\\tthere"); + + assertThat(onSingleEscapeString, is("hello\tthere")); + } + + /* + * Check handling of strings with multiple escapes. + */ + @Test + public void testDescapeString_MultipleEscapeString() { + String onMultipleEscapeString = descapeString("hello\\tthere\\tworld"); + + assertThat(onMultipleEscapeString, is("hello\tthere\tworld")); + } + + /* + * Check handling of strings with invalid single escapes. + */ + @Test + public void testDescapeString_InvalidSingleEscapeString() throws IllegalArgumentException { + exp.expect(IllegalArgumentException.class); + exp.expectMessage(containsString("at position 0")); + + descapeString("\\x"); + } } \ No newline at end of file -- cgit v1.2.3