Skip to content

Commit

Permalink
Fix layout width in ninja_syntax.py.
Browse files Browse the repository at this point in the history
The last line would sometimes be needlessly longer than the layout
width. One example is line 67 in the build.ninja generated by
ninja's own configure.py: Before this patch, ninja_syntax would
create a 81 character line.
  • Loading branch information
nico committed May 2, 2012
1 parent 4d1674f commit 7ef52b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion misc/ninja_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _count_dollars_before_index(self, s, i):
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
Expand Down
12 changes: 12 additions & 0 deletions misc/ninja_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def test_few_long_words(self):
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)
Expand Down

0 comments on commit 7ef52b4

Please sign in to comment.