-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathtest_normalized_string.py
More file actions
43 lines (37 loc) · 1.15 KB
/
test_normalized_string.py
File metadata and controls
43 lines (37 loc) · 1.15 KB
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
import pytest
from babel.messages.pofile import _NormalizedString
def test_normalized_string():
ab = _NormalizedString('"a"', '"b"')
ac = _NormalizedString('"a"', '"c"')
z = _NormalizedString()
assert ab < ac # __lt__
assert ac > ab # __gt__
assert ab != ac # __ne__
assert not z # __nonzero__ / __bool__
assert sorted([ac, ab, z]) == [z, ab, ac] # sorted() is stable
@pytest.mark.parametrize(
"original, denormalized",
(
('""', ""),
('"a"', "a"),
('"a\\n"', "a\n"),
('"a\\r"', "a\r"),
('"a\\t"', "a\t"),
('"a\\""', 'a"'),
('"a\\\\"', "a\\"),
),
)
def test_denormalized_simple_normalized_string(original, denormalized):
assert denormalized == _NormalizedString(original).denormalize()
@pytest.mark.parametrize(
"originals, denormalized",
(
(('"a"', '"b"'), "ab"),
(('"a"', '"b"'), "ab"),
(('"ab"', '""'), "ab"),
(('"ab"', '"c"'), "abc"),
(('"a"', '"bc"'), "abc"),
),
)
def test_denormalized_multi_normalized_string(originals, denormalized):
assert denormalized == _NormalizedString(*originals).denormalize()