Skip to content

Commit

Permalink
Add other option for B to better track capture state
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-ai committed Jun 3, 2024
1 parent 3f2a3ef commit 7c64496
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def test_no_infinite_loop_extra_indirection(self):

@pytest.mark.timeout(5)
def test_captures_from_root(self):
B = select(["x", ""], name="B")
B = select(["x", "y", ""], name="B")
A = select([B, ""], recurse=True, name="A")
parser = EarleyCommitParser(A)

Expand All @@ -219,16 +219,21 @@ def test_captures_from_root(self):
assert mock.call_count == 1
assert captures == {"B": b"x", "A": b"x"}

parser.consume_byte(b"x")
parser.consume_byte(b"y")
captures, _ = parser.get_captures()
assert mock.call_count == 2
assert captures == {"B": b"x", "A": b"xx"}
assert captures == {"B": b"y", "A": b"xy"}

parser.consume_byte(b"x")
captures, _ = parser.get_captures()
assert mock.call_count == 3
assert captures == {"B": b"x", "A": b"xyx"}

@pytest.mark.timeout(5)
def test_partial_captures(self):
B = select(["x", ""], name="B")
B = select(["x", "y", ""], name="B")
A = select([B, ""], recurse=True, name="A")
C = A + "y"
C = A + "z"
parser = EarleyCommitParser(C)

with patch.object(
Expand All @@ -241,14 +246,14 @@ def test_partial_captures(self):
assert mock.call_count == 1
assert captures == {"B": b"", "A": b"x"}

parser.consume_byte(b"x")
parser.consume_byte(b"y")
captures, _ = parser.get_captures()
assert mock.call_count == 2
assert captures == {"B": b"", "A": b"xx"}
assert captures == {"B": b"", "A": b"xy"}

# No new call to _record_captures_partial, but make sure that the captures are updated
# when finally called from root
parser.consume_byte(b"y")
parser.consume_byte(b"z")
captures, _ = parser.get_captures()
assert mock.call_count == 2 # no new call
assert captures == {"B": b"x", "A": b"xx"}
assert captures == {"B": b"y", "A": b"xy"}

0 comments on commit 7c64496

Please sign in to comment.