diff options
| author | natsuoto <[email protected]> | 2026-07-01 17:25:58 +0530 |
|---|---|---|
| committer | natsuoto <[email protected]> | 2026-07-01 17:25:58 +0530 |
| commit | 1941e22bb31046c3f1ce57f1fe9c0363756d2572 (patch) | |
| tree | 87efba9c96915e94f28d239e75acf38397c7467d /tests/errors/stacked_quantifier.test.py | |
| parent | 080d5ac837ea8039b857d41dc9b258486748e5fe (diff) | |
| download | edify-1941e22bb31046c3f1ce57f1fe9c0363756d2572.tar.xz edify-1941e22bb31046c3f1ce57f1fe9c0363756d2572.zip | |
fix!: stacked quantifiers raise StackedQuantifierError at chain time
Diffstat (limited to 'tests/errors/stacked_quantifier.test.py')
| -rw-r--r-- | tests/errors/stacked_quantifier.test.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/errors/stacked_quantifier.test.py b/tests/errors/stacked_quantifier.test.py new file mode 100644 index 0000000..4e512dd --- /dev/null +++ b/tests/errors/stacked_quantifier.test.py @@ -0,0 +1,42 @@ +"""Tests for :class:`StackedQuantifierError` raised on stacked quantifier chain calls.""" + +import pytest + +from edify import Pattern, RegexBuilder +from edify.errors.quantifier import StackedQuantifierError + + +def test_stacking_one_or_more_over_exactly_raises(): + with pytest.raises(StackedQuantifierError): + RegexBuilder().one_or_more().exactly(3).digit() + + +def test_stacking_optional_over_at_least_raises(): + with pytest.raises(StackedQuantifierError): + RegexBuilder().optional().at_least(2).digit() + + +def test_stacking_between_over_zero_or_more_raises(): + with pytest.raises(StackedQuantifierError): + RegexBuilder().zero_or_more().between(1, 3).digit() + + +def test_stacking_lazy_variants_also_raises(): + with pytest.raises(StackedQuantifierError): + RegexBuilder().one_or_more_lazy().exactly(2).digit() + + +def test_stacking_on_pattern_raises(): + with pytest.raises(StackedQuantifierError): + Pattern().one_or_more().exactly(3).digit() + + +def test_a_valid_quantifier_element_quantifier_element_chain_works(): + expr = RegexBuilder().one_or_more().digit().exactly(3).word() + assert expr.to_regex_string() == "\\d+\\w{3}" + + +def test_stacked_quantifier_error_message_contains_expected_text(): + error = StackedQuantifierError() + assert "stack" in str(error) + assert "pending" in str(error)
\ No newline at end of file |
