Skip to content

Commit

Permalink
Don't print both start and end position for zero-length ranges.
Browse files Browse the repository at this point in the history
whitequark committed Jul 21, 2015
1 parent 72f6c5f commit bb6b143
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pythonparser/source.py
Original file line number Diff line number Diff line change
@@ -159,9 +159,13 @@ def __str__(self):
"""
Returns a Clang-style string representation of the beginning of this range.
"""
return "%s:%d:%d-%d:%d" % (self.source_buffer.name,
self.line(), self.column() + 1,
self.end().line(), self.end().column() + 1)
if self.begin_pos != self.end_pos:
return "%s:%d:%d-%d:%d" % (self.source_buffer.name,
self.line(), self.column() + 1,
self.end().line(), self.end().column() + 1)
else:
return "%s:%d:%d" % (self.source_buffer.name,
self.line(), self.column() + 1)

def __eq__(self, other):
"""
3 changes: 2 additions & 1 deletion pythonparser/test/test_source.py
Original file line number Diff line number Diff line change
@@ -90,7 +90,8 @@ def test_source_lines(self):
self.assertEqual(["line two\n", "\n"], self.range(9, 18).source_lines())

def test___str__(self):
self.assertEqual("<input>:2:1-2:1", str(self.range(9, 9)))
self.assertEqual("<input>:2:1-2:2", str(self.range(9, 10)))
self.assertEqual("<input>:2:1", str(self.range(9, 9)))

def test___ne__(self):
self.assertTrue(self.range(0,0) != self.range(0,1))

0 comments on commit bb6b143

Please sign in to comment.