diff options
-rw-r--r-- | misc/ninja_syntax.py | 2 | ||||
-rwxr-xr-x | misc/ninja_test.py | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/misc/ninja_syntax.py b/misc/ninja_syntax.py index 97bd82b..3ecbcee 100644 --- a/misc/ninja_syntax.py +++ b/misc/ninja_syntax.py @@ -101,7 +101,7 @@ class Writer(object): def _line(self, text, indent=0): """Write 'text' word-wrapped at self.width characters.""" leading_space = ' ' * indent - while len(text) > self.width: + while len(leading_space) + len(text) > self.width: # The text is too wide; wrap if possible. # Find the rightmost space that would obey our width constraint and diff --git a/misc/ninja_test.py b/misc/ninja_test.py index 897de72..b56033e 100755 --- a/misc/ninja_test.py +++ b/misc/ninja_test.py @@ -41,6 +41,18 @@ class TestLineWordWrap(unittest.TestCase): INDENT + 'y']) + '\n', self.out.getvalue()) + def test_short_words_indented(self): + # Test that indent is taking into acount when breaking subsequent lines. + # The second line should not be ' to tree', as that's longer than the + # test layout width of 8. + self.n._line('line_one to tree') + self.assertEqual('''\ +line_one $ + to $ + tree +''', + self.out.getvalue()) + def test_few_long_words_indented(self): # Check wrapping in the presence of indenting. self.n._line(' '.join(['x', LONGWORD, 'y']), indent=1) |