From 080d5ac837ea8039b857d41dc9b258486748e5fe Mon Sep 17 00:00:00 2001 From: natsuoto <279971144+natsuoto@users.noreply.github.com> Date: Wed, 1 Jul 2026 17:13:47 +0530 Subject: fix!: dangling quantifier raises DanglingQuantifierError at emit --- tests/errors/dangling_quantifier.test.py | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/errors/dangling_quantifier.test.py (limited to 'tests/errors') diff --git a/tests/errors/dangling_quantifier.test.py b/tests/errors/dangling_quantifier.test.py new file mode 100644 index 0000000..7823996 --- /dev/null +++ b/tests/errors/dangling_quantifier.test.py @@ -0,0 +1,52 @@ +"""Tests for :class:`DanglingQuantifierError` raised at emit time.""" + +import pytest + +from edify import Pattern, RegexBuilder +from edify.errors.quantifier import DanglingQuantifierError + + +def test_to_regex_string_raises_when_a_bare_quantifier_has_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().exactly(3).to_regex_string() + + +def test_to_regex_string_raises_for_optional_with_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().optional().to_regex_string() + + +def test_to_regex_string_raises_for_zero_or_more_with_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().zero_or_more().to_regex_string() + + +def test_to_regex_string_raises_for_one_or_more_with_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().one_or_more().to_regex_string() + + +def test_to_regex_string_raises_for_between_with_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().between(2, 5).to_regex_string() + + +def test_pattern_to_regex_string_raises_when_a_bare_quantifier_has_no_operand(): + with pytest.raises(DanglingQuantifierError): + Pattern().exactly(3).to_regex_string() + + +def test_to_regex_raises_when_a_bare_quantifier_has_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().at_least(2).to_regex() + + +def test_message_hints_at_appending_an_operand(): + with pytest.raises(DanglingQuantifierError, match="Append an element"): + RegexBuilder().exactly(3).to_regex_string() + + +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 -- cgit v1.2.3 From 1941e22bb31046c3f1ce57f1fe9c0363756d2572 Mon Sep 17 00:00:00 2001 From: natsuoto <279971144+natsuoto@users.noreply.github.com> Date: Wed, 1 Jul 2026 17:25:58 +0530 Subject: fix!: stacked quantifiers raise StackedQuantifierError at chain time --- tests/errors/stacked_quantifier.test.py | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/errors/stacked_quantifier.test.py (limited to 'tests/errors') 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 -- cgit v1.2.3 From 644f52066d0552ad31ac702910d0bc158b091451 Mon Sep 17 00:00:00 2001 From: natsuoto <279971144+natsuoto@users.noreply.github.com> Date: Wed, 1 Jul 2026 17:29:14 +0530 Subject: chore: consolidate quantifier error tests into tests/errors/quantifier.test.py --- tests/errors/dangling_quantifier.test.py | 52 ------------------- tests/errors/quantifier.test.py | 88 ++++++++++++++++++++++++++++++++ tests/errors/stacked_quantifier.test.py | 42 --------------- 3 files changed, 88 insertions(+), 94 deletions(-) delete mode 100644 tests/errors/dangling_quantifier.test.py create mode 100644 tests/errors/quantifier.test.py delete mode 100644 tests/errors/stacked_quantifier.test.py (limited to 'tests/errors') diff --git a/tests/errors/dangling_quantifier.test.py b/tests/errors/dangling_quantifier.test.py deleted file mode 100644 index 7823996..0000000 --- a/tests/errors/dangling_quantifier.test.py +++ /dev/null @@ -1,52 +0,0 @@ -"""Tests for :class:`DanglingQuantifierError` raised at emit time.""" - -import pytest - -from edify import Pattern, RegexBuilder -from edify.errors.quantifier import DanglingQuantifierError - - -def test_to_regex_string_raises_when_a_bare_quantifier_has_no_operand(): - with pytest.raises(DanglingQuantifierError): - RegexBuilder().exactly(3).to_regex_string() - - -def test_to_regex_string_raises_for_optional_with_no_operand(): - with pytest.raises(DanglingQuantifierError): - RegexBuilder().optional().to_regex_string() - - -def test_to_regex_string_raises_for_zero_or_more_with_no_operand(): - with pytest.raises(DanglingQuantifierError): - RegexBuilder().zero_or_more().to_regex_string() - - -def test_to_regex_string_raises_for_one_or_more_with_no_operand(): - with pytest.raises(DanglingQuantifierError): - RegexBuilder().one_or_more().to_regex_string() - - -def test_to_regex_string_raises_for_between_with_no_operand(): - with pytest.raises(DanglingQuantifierError): - RegexBuilder().between(2, 5).to_regex_string() - - -def test_pattern_to_regex_string_raises_when_a_bare_quantifier_has_no_operand(): - with pytest.raises(DanglingQuantifierError): - Pattern().exactly(3).to_regex_string() - - -def test_to_regex_raises_when_a_bare_quantifier_has_no_operand(): - with pytest.raises(DanglingQuantifierError): - RegexBuilder().at_least(2).to_regex() - - -def test_message_hints_at_appending_an_operand(): - with pytest.raises(DanglingQuantifierError, match="Append an element"): - RegexBuilder().exactly(3).to_regex_string() - - -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 diff --git a/tests/errors/quantifier.test.py b/tests/errors/quantifier.test.py new file mode 100644 index 0000000..27b5ddf --- /dev/null +++ b/tests/errors/quantifier.test.py @@ -0,0 +1,88 @@ +"""Tests for the :mod:`edify.errors.quantifier` exception classes.""" + +import pytest + +from edify import Pattern, RegexBuilder +from edify.errors.quantifier import DanglingQuantifierError, StackedQuantifierError + + +def test_to_regex_string_raises_when_a_bare_quantifier_has_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().exactly(3).to_regex_string() + + +def test_to_regex_string_raises_for_optional_with_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().optional().to_regex_string() + + +def test_to_regex_string_raises_for_zero_or_more_with_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().zero_or_more().to_regex_string() + + +def test_to_regex_string_raises_for_one_or_more_with_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().one_or_more().to_regex_string() + + +def test_to_regex_string_raises_for_between_with_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().between(2, 5).to_regex_string() + + +def test_pattern_to_regex_string_raises_when_a_bare_quantifier_has_no_operand(): + with pytest.raises(DanglingQuantifierError): + Pattern().exactly(3).to_regex_string() + + +def test_to_regex_raises_when_a_bare_quantifier_has_no_operand(): + with pytest.raises(DanglingQuantifierError): + RegexBuilder().at_least(2).to_regex() + + +def test_dangling_message_hints_at_appending_an_operand(): + with pytest.raises(DanglingQuantifierError, match="Append an element"): + RegexBuilder().exactly(3).to_regex_string() + + +def test_dangling_quantifier_error_message_contains_expected_text(): + error = DanglingQuantifierError() + assert "Dangling quantifier" in str(error) + 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 -- cgit v1.2.3