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 pathLiteralInt_test.py
52 lines (45 loc) · 1.52 KB
/
LiteralInt_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
from selfie_lib.Literals import LiteralInt, Language
from selfie_lib.EscapeLeadingWhitespace import EscapeLeadingWhitespace
def _encode(value: int, expected: str):
literal_int = LiteralInt()
actual = literal_int.encode(value, Language.PYTHON, EscapeLeadingWhitespace.NEVER)
assert actual == expected, f"Expected '{expected}', but got '{actual}'"
def _decode(value: str, expected: int):
literal_int = LiteralInt()
actual = literal_int.parse(value, Language.PYTHON)
assert actual == expected, f"Expected '{expected}', but got '{actual}'"
class TestLiteralInt:
def test_encode(self):
test_cases = [
(0, "0"),
(1, "1"),
(-1, "-1"),
(999, "999"),
(-999, "-999"),
(1_000, "1_000"),
(-1_000, "-1_000"),
(1_000_000, "1_000_000"),
(-1_000_000, "-1_000_000"),
(2400500, "2_400_500"),
(2400501, "2_400_501"),
(200, "200"),
(1001, "1_001"),
(1010, "1_010"),
(10010, "10_010"),
]
for value, expected in test_cases:
_encode(value, expected)
def test_decode(self):
test_cases = [
("0", 0),
("1", 1),
("-1", -1),
("999", 999),
("9_99", 999),
("9_9_9", 999),
("-999", -999),
("-9_99", -999),
("-9_9_9", -999),
]
for value, expected in test_cases:
_decode(value, expected)