diff options
| author | natsuoto <[email protected]> | 2026-07-01 17:29:14 +0530 |
|---|---|---|
| committer | natsuoto <[email protected]> | 2026-07-01 17:29:14 +0530 |
| commit | 644f52066d0552ad31ac702910d0bc158b091451 (patch) | |
| tree | 040cc3ca818ae3af00ed68f73a889af12e657c3e /tests/errors | |
| parent | 1941e22bb31046c3f1ce57f1fe9c0363756d2572 (diff) | |
| download | edify-644f52066d0552ad31ac702910d0bc158b091451.tar.xz edify-644f52066d0552ad31ac702910d0bc158b091451.zip | |
chore: consolidate quantifier error tests into tests/errors/quantifier.test.py
Diffstat (limited to 'tests/errors')
| -rw-r--r-- | tests/errors/quantifier.test.py (renamed from tests/errors/dangling_quantifier.test.py) | 44 | ||||
| -rw-r--r-- | tests/errors/stacked_quantifier.test.py | 42 |
2 files changed, 40 insertions, 46 deletions
diff --git a/tests/errors/dangling_quantifier.test.py b/tests/errors/quantifier.test.py index 7823996..27b5ddf 100644 --- a/tests/errors/dangling_quantifier.test.py +++ b/tests/errors/quantifier.test.py @@ -1,9 +1,9 @@ -"""Tests for :class:`DanglingQuantifierError` raised at emit time.""" +"""Tests for the :mod:`edify.errors.quantifier` exception classes.""" import pytest from edify import Pattern, RegexBuilder -from edify.errors.quantifier import DanglingQuantifierError +from edify.errors.quantifier import DanglingQuantifierError, StackedQuantifierError def test_to_regex_string_raises_when_a_bare_quantifier_has_no_operand(): @@ -41,7 +41,7 @@ def test_to_regex_raises_when_a_bare_quantifier_has_no_operand(): RegexBuilder().at_least(2).to_regex() -def test_message_hints_at_appending_an_operand(): +def test_dangling_message_hints_at_appending_an_operand(): with pytest.raises(DanglingQuantifierError, match="Append an element"): RegexBuilder().exactly(3).to_regex_string() @@ -49,4 +49,40 @@ def test_message_hints_at_appending_an_operand(): def test_dangling_quantifier_error_message_contains_expected_text(): error = DanglingQuantifierError() assert "Dangling quantifier" in str(error) - assert "no operand" in str(error)
\ No newline at end of file + assert "no operand" in str(error) + + +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) diff --git a/tests/errors/stacked_quantifier.test.py b/tests/errors/stacked_quantifier.test.py deleted file mode 100644 index 4e512dd..0000000 --- a/tests/errors/stacked_quantifier.test.py +++ /dev/null @@ -1,42 +0,0 @@ -"""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 |
