diff options
| author | student <student@192.168.1.186> | 2017-03-20 11:50:14 -0400 |
|---|---|---|
| committer | student <student@192.168.1.186> | 2017-03-20 11:50:14 -0400 |
| commit | 2fa8f2956c1c52ad2282c71509a163de7967ff2d (patch) | |
| tree | 72e19707d2ea3ccc91243f11026929524bb41ee9 /BJC-Utils2/src | |
| parent | da85aa084dbf1490cd2b7566286289006a1483fc (diff) | |
Minor testing reorg
Diffstat (limited to 'BJC-Utils2/src')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java | 3 | ||||
| -rw-r--r-- | BJC-Utils2/src/test/java/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. */ @@ -53,6 +53,25 @@ public class TokenUtilsTest_removeDQuoted { } /* + * Check handling of strings with multiple quoted strings in a row. + */ + @Test + public void testRemoveDQuoted_MultipleSerialString() { + List<String> onMultipleSerialMatchString = removeDQuotedStrings("\"hello\"\"there\""); + + assertThat(onMultipleSerialMatchString, hasItems("\"hello\"", "\"there\"")); + } + + /* + * Check handling of strings with multiple interleaved strings. + */ + @Test + public void testRemoveDQuoted_MultipleInterleavedString() { + List<String> onMultipleInterleaveMatchString = removeDQuotedStrings("one\"two\"three\"four\""); + + assertThat(onMultipleInterleaveMatchString, hasItems("one", "\"two\"", "three", "\"four\"")); + } + /* * Check handling of strings without embedded strings. */ @Test @@ -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 |
