### Question:
PatternUtils { @SuppressWarnings("PMD.NcssCount") static String escape(String str) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < str.length(); ++i) { char c = str.charAt(i); switch (c) { case '\t': builder.append("\\t"); break; case '\n': builder.append("\\n"); break; case '\r': builder.append("\\r"); break; case '\f': builder.append("\\f"); break; case '\\': builder.append("\\\\"); break; case '^': builder.append("\\^"); break; case '$': builder.append("\\$"); break; case '.': builder.append("\\."); break; case '?': builder.append("\\?"); break; case '*': builder.append("\\*"); break; case '+': builder.append("\\+"); break; case '[': builder.append("\\["); break; case ']': builder.append("\\]"); break; case '(': builder.append("\\("); break; case ')': builder.append("\\)"); break; case '{': builder.append("\\{"); break; case '}': builder.append("\\}"); break; default: if (c <= ' ' || c > '~') { builder.append(String.format("\\u%04x", (int) c)); } else { builder.append(c); } break; } } return builder.toString(); } private  PatternUtils(); static PatternMatcher compile(String pattern);  }### Answer:
@Test public void escapeSpecial() { String input = "\t\n\r\f\\^$.?*+[](){}"; String expected = "\\t\\n\\r\\f\\\\\\^\\$\\.\\?\\*\\+\\[\\]\\(\\)\\{\\}"; Assertions.assertEquals(expected, PatternUtils.escape(input)); }
@Test public void escapePrintable() { String special = "\t\n\r\f\\^$.?*+[](){}"; for (char i = '!'; i <= '~'; ++i) { if (special.indexOf(i) != -1) { continue; } String expected = Character.toString(i); Assertions.assertEquals(expected, PatternUtils.escape(expected)); } }
@Test public void escapeControl() { String special = "\t\n\r\f"; for (int i = 0; i < '!'; ++i) { if (special.indexOf(i) != -1) { continue; } String input = Character.toString((char) i); String expected = String.format("\\u%04x", i); Assertions.assertEquals(expected, PatternUtils.escape(input)); } }
@Test public void escapeDelete() { Assertions.assertEquals("\\u007f", PatternUtils.escape("\u007f")); }