Skip to content

Commit

Permalink
Test edge case in current_line directly
Browse files Browse the repository at this point in the history
A pragma: no cover was removed from StringReader.current_line and its useless edge case was given its own test.
  • Loading branch information
drhagen committed Apr 28, 2018
1 parent d62e824 commit 0a0a7d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parsita/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def next_token(self) -> str:

def current_line(self):
characters_consumed = 0
for line_index, line in enumerate(StringIO(self.source)): # pragma: no cover
for line_index, line in enumerate(StringIO(self.source)):
if characters_consumed + len(line) > self.position:
# The line with the error has been found
character_index = self.position - characters_consumed
Expand Down
7 changes: 7 additions & 0 deletions tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ def test_state_creation(self):
error = ParseError('Expected a but found b at index 0')
self.assertEqual(str(error), 'Expected a but found b at index 0')
self.assertEqual(repr(error), "ParseError('Expected a but found b at index 0')")

def test_current_line(self):
# This test only exists to get 100% test coverage without doing a pragma: no cover on the whole current_line
# method. Under normal operation, the for loop should never complete because the position is also on some
# line. Here, the position has been artificially advanced beyond the length of the input.
reader = StringReader('foo', 3)
self.assertEqual(reader.current_line(), None)

0 comments on commit 0a0a7d9

Please sign in to comment.