This repository was archived by the owner on Apr 4, 2024. It is now read-only.
forked from diffplug/selfie
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLiteralString_test.py
62 lines (56 loc) · 2.28 KB
/
LiteralString_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
from selfie_lib.Literals import LiteralString
from selfie_lib.EscapeLeadingWhitespace import EscapeLeadingWhitespace
class TestLiteralString:
@pytest.mark.parametrize(
"value, expected",
[("1", '"1"'), ("\\", '"\\\\"'), ("1\n\tABC", '"1\\n\\tABC"')],
)
def test_encode_single_java(self, value, expected):
literal_string = LiteralString()
actual = literal_string._encodeSinglePython(value)
print(actual)
assert actual == expected
@pytest.mark.parametrize(
"value, expected",
[("1", "`1`"), ("\\", "`\\\\`"), ("1\n\tABC", "`1\\n\\tABC`")],
)
def test_encode_single_java_with_dollars(self, value, expected):
literal_string = LiteralString()
actual = literal_string._encodeSinglePython(value)
assert actual == expected.replace("`", '"')
# Failing due to EscapeLeadingWhitespace always being NEVER
# and not an Always option like in the original test case
@pytest.mark.parametrize(
"value, expected",
[
("1", "'''\n1'''"),
("\\", "'''\n\\\\'''"),
(" leading\ntrailing ", "'''\n" + "\\s leading\n" + "trailing \\s'''"),
],
)
def test_encode_multi_java(self, value, expected):
literal_string = LiteralString()
actual = literal_string.encodeMultiPython(value, EscapeLeadingWhitespace.NEVER)
assert actual == expected.replace("'", '"')
@pytest.mark.parametrize(
"value, expected", [("1", "1"), ("\\\\", "\\"), ("1\\n\\tABC", "1\n\tABC")]
)
def test_parse_single_java(self, value, expected):
literal_string = LiteralString()
actual = literal_string._parseSinglePython(f'"{value.replace("'", "\"")}"')
assert actual == expected
@pytest.mark.parametrize(
"value, expected",
[
("\n123\nabc", "123\nabc"),
("\n 123\n abc", "123\nabc"),
("\n 123 \n abc\t", "123\nabc"),
("\n 123 \n abc\t", "123\nabc"),
("\n 123 \\s\n abc\t\\s", "123 \nabc\t "),
],
)
def test_parse_multi_java(self, value, expected):
literal_string = LiteralString()
actual = literal_string.parseMultiPython(f'"""{value.replace("'", "\"")}"""')
assert actual == expected