Skip to content

Commit e164780

Browse files
committed
add more tests
1 parent f457e20 commit e164780

1 file changed

Lines changed: 39 additions & 11 deletions

File tree

β€ŽLib/test/test_textwrap.pyβ€Ž

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,19 +1078,47 @@ def test_first_word_too_long_but_placeholder_fits(self):
10781078

10791079

10801080
class WideCharacterTestCase(BaseTestCase):
1081-
def test_wide_character(self):
1082-
def text_len(text):
1083-
n = 0
1084-
for c in text:
1085-
if unicodedata.east_asian_width(c) in {'F', 'W'}:
1086-
n += 2
1087-
else:
1088-
n += 1
1089-
return n
1081+
def text_len(self, text):
1082+
n = 0
1083+
for c in text:
1084+
if unicodedata.east_asian_width(c) in {'F', 'W'}:
1085+
n += 2
1086+
else:
1087+
n += 1
1088+
return n
10901089

1090+
def check_shorten(self, text, width, expect, **kwargs):
1091+
result = shorten(text, width, **kwargs)
1092+
self.check(result, expect)
1093+
1094+
def test_wrap(self):
10911095
text = "123 πŸ”§"
1092-
expected = ["123", "πŸ”§"]
1093-
self.check_wrap(text, 5, expected, text_len=text_len)
1096+
self.check_wrap(text, 5, ["123 πŸ”§"])
1097+
self.check_wrap(text, 5, ["123", "πŸ”§"], text_len=self.text_len)
1098+
1099+
def test_wrap_initial_indent(self):
1100+
text = "12 12"
1101+
self.check_wrap(text, 6, ["πŸ”§12 12"], initial_indent="πŸ”§")
1102+
self.check_wrap(text, 6, ["πŸ”§12", "12"], initial_indent="πŸ”§",
1103+
text_len=self.text_len)
1104+
1105+
def test_wrap_subsequent_indent(self):
1106+
text = "12 12 12 12"
1107+
self.check_wrap(text, 6, ["12 12", "πŸ”§12 12"], subsequent_indent="πŸ”§")
1108+
self.check_wrap(text, 6, ["12 12", "πŸ”§12", "πŸ”§12"],
1109+
subsequent_indent="πŸ”§", text_len=self.text_len)
1110+
1111+
def test_shorten(self):
1112+
text = "123 1234πŸ”§"
1113+
expected = "123 [...]"
1114+
self.check_shorten(text, 9, "123 1234πŸ”§")
1115+
self.check_shorten(text, 9, "123 [...]", text_len=self.text_len)
1116+
1117+
def test_shorten_placeholder(self):
1118+
text = "123 1 123"
1119+
self.check_shorten(text, 7, "123 1 πŸ”§", placeholder=" πŸ”§")
1120+
self.check_shorten(text, 7, "123 πŸ”§", placeholder=" πŸ”§",
1121+
text_len=self.text_len)
10941122

10951123

10961124
if __name__ == '__main__':

0 commit comments

Comments
Β (0)