Skip to content

Commit

Permalink
Remove unused methods and more repreated dict tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Jul 29, 2018
1 parent 6541f8e commit f4d4223
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
38 changes: 37 additions & 1 deletion tests/test_textparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def test_grammar_zero_or_more_partial_element_match(self):

def test_grammar_zero_or_more_end(self):
grammar = Grammar(
Sequence(ZeroOrMore('WORD', Sequence('WORD', 'NUMBER')),
Sequence(ZeroOrMore('WORD', end=Sequence('WORD', 'NUMBER')),
Sequence('WORD', 'NUMBER')))

datas = [
Expand Down Expand Up @@ -301,6 +301,27 @@ def test_grammar_zero_or_more_dict(self):
tree = grammar.parse(tokens)
self.assertEqual(tree, expected_tree)

def test_grammar_zero_or_more_dict_end(self):
grammar = Grammar(
Sequence(ZeroOrMoreDict('WORD', end=Sequence('WORD', 'NUMBER')),
Sequence('WORD', 'NUMBER')))

datas = [
(
[('WORD', 'bar'), ('NUMBER', '1')],
[{}, ['bar', '1']]
),
(
[('WORD', 'foo'), ('WORD', 'bar'), ('NUMBER', '1')],
[{'f': ['foo']}, ['bar', '1']]
)
]

for tokens, expected_tree in datas:
tokens = tokenize(tokens)
tree = grammar.parse(tokens)
self.assertEqual(tree, expected_tree)

def test_grammar_one_or_more(self):
grammar = Grammar(OneOrMore('WORD'))

Expand Down Expand Up @@ -434,6 +455,21 @@ def test_grammar_one_or_more_dict_mismatch(self):

self.assertEqual(cm.exception.offset, line)

def test_grammar_one_or_more_dict_end_mismatch(self):
grammar = Grammar(OneOrMoreDict('WORD', Sequence('WORD', 'NUMBER')))

datas = [
[('WORD', 'bar', 1), ('NUMBER', '1', 2)]
]

for tokens in datas:
tokens = tokenize(tokens)

with self.assertRaises(textparser.GrammarError) as cm:
grammar.parse(tokens)

self.assertEqual(cm.exception.offset, 1)

def test_grammar_any(self):
grammar = Grammar(Any())

Expand Down
7 changes: 0 additions & 7 deletions textparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ def restore(self):
def update(self):
self._stack[-1] = self._pos

def load(self):
self._pos = self._stack[-1]

def mark_max(self):
if self._pos > self._max_pos:
self._max_pos = self._pos

def mark_max_restore(self):
if self._pos > self._max_pos:
self._max_pos = self._pos
Expand Down

0 comments on commit f4d4223

Please sign in to comment.