Skip to content

Commit

Permalink
Fix matching of Some in Some
Browse files Browse the repository at this point in the history
  • Loading branch information
scravy committed Jan 3, 2022
1 parent b71ff58 commit f0f4203
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@ def _match_subsequence(it: SeqIterator, pattern, terminators: List,
it.rewind()
raise StopIteration
if _is_a(current_pattern, Some):
it.rewind()
r = _match_some(it, current_pattern, terminators=[next_pattern, *terminators], ctx=ctx)
if r is None:
raise StopIteration
r.merge(it, ctx)
subsequence.append(item)
subsequence.extend(r.matches)
continue
if ctx.match(item, current_pattern):
Expand Down
8 changes: 5 additions & 3 deletions tests/test_some.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ def test_docstring_examples(self):
self.assertEqual([1, 2, 3], result['123'])
self.assertEqual([4, 5, 6, 7, 8, 9], result['xs'])

# def test_subsequence_not_matching(self):
# self.assertTrue(match([0, 1, 2, 2, 1, 2, 2, 4], [0, Some(1, Some(2, 2, at_least=1), at_least=2), 4]))
# # self.assertFalse(match([0, 1, 2, 2, 1, 2, 3, 4], [0, Some(1, Some(2, 2, at_least=1), at_least=2), 4]))
def test_subsequence_not_matching(self):
self.assertTrue(match([0, 1, 2, 2, 1, 2, 2, 4], [0, Some(1, Some(2, 2, at_least=1), at_least=2), 4]))

def test_subsequence_not_matching_unhappy_path(self):
self.assertFalse(match([0, 1, 2, 2, 1, 2, 3, 4], [0, Some(1, Some(2, 2, at_least=1), at_least=2), 4]))
1 change: 1 addition & 0 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_transform(self):
Arguments(foo=int, bar=float),
Returns(str),
Object(SomeClass, 8, bar='quuz'),
{"foo": 1} ** Remainder(...),
[1, 2, 3],
"foo",
1.0,
Expand Down

0 comments on commit f0f4203

Please sign in to comment.