Skip to content

Commit a4823a7

Browse files
Apply suggestions from Serhiy
1 parent b6f128f commit a4823a7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Lib/test/test_tools/test_i18n.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,13 +540,13 @@ def test_normalize_wrap(self):
540540
data = normalize(raw, 'UTF-8', 'msgid', 30)
541541
self.assertEqual(expected, data)
542542

543-
def test_normalize_nostr(self):
543+
def test_normalize_empty_str(self):
544544
data = normalize('', 'UTF-8', 'msgid', 30)
545545
self.assertEqual('""', data)
546546

547547
def test_normalize_single_word(self):
548548
for s in ("fee", "fi", "fo", "fums"):
549-
data = normalize(s, 'UTF-8', 'msgid', 3)
549+
data = normalize(s, 'UTF-8', 'msgid', 8)
550550
self.assertNotIn('""', data) # did not wrap
551551

552552
def test_normalize_split_on_whitespace(self):
@@ -557,6 +557,11 @@ def test_normalize_split_on_whitespace(self):
557557
data = normalize(s, 'UTF-8', 'msgid', 10)
558558
self.assertEqual(s_expected, data)
559559

560+
s = f'longlonglong\r\nword'
561+
s_expected = f'""\n"longlonglong\\r\\n"\n"word"'
562+
data = normalize(s, 'UTF-8', 'msgid', 30)
563+
self.assertEqual(s_expected, data)
564+
560565

561566
def extract_from_snapshots():
562567
snapshots = {

Tools/i18n/pygettext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ def normalize(s, encoding, prefix, width):
230230
words = _space_splitter.findall(line)
231231
words.reverse()
232232
buf = []
233-
size = 2
233+
size = 0
234234
while words:
235235
word = words.pop()
236236
escaped_word = escape(word, encoding)
237237
escaped_word_len = len(escaped_word)
238238
new_size = size + escaped_word_len
239-
if new_size <= width or not buf:
239+
if new_size + 2 <= width or not buf:
240240
buf.append(escaped_word)
241241
size = new_size
242242
else:

0 commit comments

Comments
 (0)