]> granicus.if.org Git - python/commitdiff
bpo-30591: Added test for textwrap backtracking. (#1988)
authorJonathan Eunice <jonathan.eunice@gmail.com>
Wed, 7 Jun 2017 20:49:13 +0000 (16:49 -0400)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 7 Jun 2017 20:49:13 +0000 (23:49 +0300)
Lib/test/test_textwrap.py

index 5a33c151642c629c355321f1064aa7359f0ef505..47d97bda86fd1fabf3202b9ee202ef1895b12e93 100644 (file)
@@ -559,6 +559,17 @@ class MaxLinesTestCase(BaseTestCase):
                         placeholder=' [truncated]...')
         self.check_wrap(self.text, 80, [self.text], placeholder='.' * 1000)
 
+    def test_placeholder_backtrack(self):
+        # Test special case when max_lines insufficient, but what
+        # would be last wrapped line so long the placeholder cannot
+        # be added there without violence. So, textwrap backtracks,
+        # adding placeholder to the penultimate line.
+        text = 'Good grief Python features are advancing quickly!'
+        self.check_wrap(text, 12,
+                        ['Good grief', 'Python*****'],
+                        max_lines=3,
+                        placeholder='*****')
+
 
 class LongWordTestCase (BaseTestCase):
     def setUp(self):