Expressions { public static String unescape(StringLiteral stringLiteral) { List<StringElement> elements = stringLiteral.stringElements(); if (elements.size() == 1) { return unescape(elements.get(0)); } return elements.stream() .map(Expressions::unescape) .collect(Collectors.joining()); } private  Expressions(); static boolean isFalsy(@Nullable Expression expression); static Expression singleAssignedValue(Name name); static Expression removeParentheses(@Nullable Expression expression); static String unescape(StringLiteral stringLiteral); static String unescape(StringElement stringElement);  }
@Test public void unescape_string_literal() { assertThat(unescape(stringLiteral("''"))).isEqualTo(""); assertThat(unescape(stringLiteral("'' ''"))).isEqualTo(""); assertThat(unescape(stringLiteral("'abc' 'def'"))).isEqualTo("abcdef"); assertThat(unescape(stringLiteral("'\\u0061' r'\\u0061' f'{value}'"))).isEqualTo("a\\u0061{value}"); }
@Test public void unescape_string_element_using_different_prefix() { assertThat(unescape(stringElement("''"))).isEqualTo(""); assertThat(unescape(stringElement("b''"))).isEqualTo(""); assertThat(unescape(stringElement("'a'"))).isEqualTo("a"); assertThat(unescape(stringElement("u'a\\tc'"))).isEqualTo("a\tc"); assertThat(unescape(stringElement("r'a\\tc'"))).isEqualTo("a\\tc"); assertThat(unescape(stringElement("fR'a\\tc'"))).isEqualTo("a\\tc"); assertThat(unescape(stringElement("f'name:\\n{name}'"))).isEqualTo("name:\n{name}"); assertThat(unescape(stringElement("F'{name}'"))).isEqualTo("{name}"); assertThat(unescape(stringElement("u'abc'"))).isEqualTo("abc"); assertThat(unescape(stringElement("b'\\x48'"))).isEqualTo("H"); assertThat(unescape(stringElement("br'\\x48'"))).isEqualTo("\\x48"); assertThat(unescape(stringElement("rb'\\x48'"))).isEqualTo("\\x48"); }
@Test public void unescape_string_element_containing_ignored_line_beak() { assertThat(unescape(stringElement("'a\\\nb'"))).isEqualTo("ab"); assertThat(unescape(stringElement("'a\\\r\nb'"))).isEqualTo("ab"); assertThat(unescape(stringElement("'a\\\r'"))).isEqualTo("a"); assertThat(unescape(stringElement("'a\\\rb'"))).isEqualTo("ab"); }
@Test public void unescape_string_element_backslash_and_quotes() { assertThat(unescape(stringElement("'\\\\'"))).isEqualTo("\\"); assertThat(unescape(stringElement("'0\\\\'"))).isEqualTo("0\\"); assertThat(unescape(stringElement("'\\\\0'"))).isEqualTo("\\0"); assertThat(unescape(stringElement("'\\'\\\"\\''"))).isEqualTo("'\"'"); }
@Test public void unescape_string_element_named_escape_sequences() { assertThat(unescape(stringElement("'\\a'"))).isEqualTo("\u0007"); assertThat(unescape(stringElement("'\\b'"))).isEqualTo("\u0008"); assertThat(unescape(stringElement("'\\f'"))).isEqualTo("\u000C"); assertThat(unescape(stringElement("'\\n'"))).isEqualTo("\n"); assertThat(unescape(stringElement("'\\r'"))).isEqualTo("\r"); assertThat(unescape(stringElement("'\\t'"))).isEqualTo("\t"); assertThat(unescape(stringElement("'\\v'"))).isEqualTo("\u000B"); }
@Test public void unescape_string_element_python_string_with_x_u_U_escape_sequences() { assertThat(unescape(stringElement("'\\x48\\u0065\\U0000006c\\x6c\\x6f\\x20\\x57\\x6f\\x72\\x6c\\x64\\x21'"))) .isEqualTo("Hello World!"); }
@Test public void unescape_string_element_python_bytes_with_x_u_U_escape_sequences() { assertThat(unescape(stringElement("b'\\x48\\u0065\\U0000006c\\x6c'"))).isEqualTo("H\\u0065\\U0000006cl"); }
@Test public void unescape_string_element_various_octal_length() { assertThat(unescape(stringElement("'\\0'"))).isEqualTo("\u0000"); assertThat(unescape(stringElement("'\\1'"))).isEqualTo("\u0001"); assertThat(unescape(stringElement("'\\7'"))).isEqualTo("\u0007"); assertThat(unescape(stringElement("'\\10'"))).isEqualTo("\u0008"); assertThat(unescape(stringElement("'a\\777b'"))).isEqualTo("a\u01FFb"); assertThat(unescape(stringElement("'a\\7777b'"))).isEqualTo("a\u01FF7b"); assertThat(unescape(stringElement("'a\\78b'"))).isEqualTo("a\u00078b"); assertThat(unescape(stringElement("'\\o12'"))).isEqualTo("\n"); assertThat(unescape(stringElement("'\\o5 \\o6'"))).isEqualTo("\u0005 \u0006"); }
@Test public void unescape_string_element_unsupported() { assertThat(unescape(stringElement("'\\N{LATIN CAPITAL LETTER A}'"))).isEqualTo("\\N{LATIN CAPITAL LETTER A}"); }