Skip to content

Commit

Permalink
Add an additional check to test_q_count().
Browse files Browse the repository at this point in the history
  • Loading branch information
JorjMcKie authored and julian-smith-artifex-com committed May 8, 2024
1 parent 00d54f2 commit 64159ac
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/test_balance_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ def test_q_count():
assert page._count_q_balance() == (1, 0)
assert page.is_wrapped is False

# Prepend more data that yield a different type of imbalanced contents:
# Although counts of q and Q are equal now, the unshielded 'cm' before
# the first 'q' makes the contents unusable for insertions.
pymupdf.TOOLS._insert_contents(page, b"1 0 0 -1 0 0 cm q ", False) # prepend
assert page.is_wrapped is False
if page._count_q_balance() == (0, 0):
print("imbalance undetected by q balance count")

text = "Hello, World!"
page.insert_text((100, 100), text) # establishes balance!

# this should have produced a balanced graphics state
assert page._count_q_balance() == (0, 0)
assert page.is_wrapped

# an appended "pop" must be balanced by a prepended "push"
pymupdf.TOOLS._insert_contents(page, b"Q", True) # append
Expand Down

0 comments on commit 64159ac

Please sign in to comment.