@Test public void expandUnicode() { for (int i = 0; i < 0xFFFF; ++i) { String expected = Character.toString((char) i); String str = String.format("\\u%04x", i); Assertions.assertEquals(expected, PatternUtils.expandEscapedChars(str)); } }
@Test public void expandHexLower() { for (int i = 0; i < 0xFF; ++i) { String expected = Character.toString((char) i); String str = String.format("\\x%02x", i); Assertions.assertEquals(expected, PatternUtils.expandEscapedChars(str)); } }
@Test public void expandHexUpper() { for (int i = 0; i < 0xFF; ++i) { String expected = Character.toString((char) i); String str = String.format("\\x%02X", i); Assertions.assertEquals(expected, PatternUtils.expandEscapedChars(str)); } }
@Test public void expandOctal() { for (int i = 0; i < 128; ++i) { String expected = Character.toString((char) i); String str = "\\0" + Integer.toString(i, 8); Assertions.assertEquals(expected, PatternUtils.expandEscapedChars(str)); } }
@Test public void expandHexInvalid() { Assertions.assertThrows(IllegalArgumentException.class, () -> PatternUtils.expandEscapedChars("\\xZZ")); }
@Test public void expandHexPartial() { Assertions.assertThrows(IllegalArgumentException.class, () -> PatternUtils.expandEscapedChars("\\xF")); }
@Test public void expandOctalEmpty() { Assertions.assertThrows(IllegalArgumentException.class, () -> PatternUtils.expandEscapedChars("\\0")); }
@Test public void expandCarriageReturn() { Assertions.assertEquals("\r", PatternUtils.expandEscapedChars("\\r")); }
@Test public void expandSlash() { Assertions.assertEquals("\\\\", PatternUtils.expandEscapedChars("\\\\")); }
@Test public void expandOctalInvalid() { Assertions.assertThrows(IllegalArgumentException.class, () -> PatternUtils.expandEscapedChars("\\0AAA")); }
@Test public void expandUnicodePartial() { Assertions.assertThrows(IllegalArgumentException.class, () -> PatternUtils.expandEscapedChars("\\u00A")); }
@Test public void expandUnicodeInvalid() { Assertions.assertThrows(IllegalArgumentException.class, () -> PatternUtils.expandEscapedChars("\\uZZZZ")); }
@Test public void danglingEscape() { Assertions.assertThrows(IllegalArgumentException.class, () -> PatternUtils.expandEscapedChars("\\")); }
@Test public void expandFormFeed() { Assertions.assertEquals("\f", PatternUtils.expandEscapedChars("\\f")); }
@Test public void nonEscapedData() { Assertions.assertEquals("abc", PatternUtils.expandEscapedChars("abc")); }
@Test public void expandTab() { Assertions.assertEquals("\t", PatternUtils.expandEscapedChars("\\t")); }
@Test public void expandAlert() { Assertions.assertEquals("\u0007", PatternUtils.expandEscapedChars("\\a")); }
@Test public void other() { Assertions.assertEquals("\\[", PatternUtils.expandEscapedChars("\\[")); }
@Test public void expandNewLine() { Assertions.assertEquals("\n", PatternUtils.expandEscapedChars("\\n")); }
@Test public void expandEscape() { Assertions.assertEquals("\u001B", PatternUtils.expandEscapedChars("\\e")); }