Skip to content

Commit

Permalink
Test the tokenizer error.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Jul 22, 2018
1 parent 6825c18 commit 3d5cf98
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_textparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from textparser import Sequence
from textparser import DelimitedList
from textparser import Token
from textparser import TokenizerError


def tokenize(items):
Expand Down Expand Up @@ -49,6 +50,22 @@ def test_delimited_list(self):
tree = grammar.parse(tokens)
self.assertEqual(tree, expected_tree)

def test_tokenizer_error(self):
datas = [
(2, 'hej', 'he>>!<<j'),
(0, 'a\nb\n', '>>!<<a'),
(1, 'a\nb\n', 'a>>!<<'),
(2, 'a\nb\n', '>>!<<b')
]

for offset, string, message in datas:
with self.assertRaises(TokenizerError) as cm:
raise TokenizerError(0, 1, offset, string)

self.assertEqual(
str(cm.exception),
'Invalid syntax at line 0, column 1: "{}"'.format(message))


if __name__ == '__main__':
unittest.main()

0 comments on commit 3d5cf98

Please sign in to comment.