aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authornatsuoto <[email protected]>2026-07-01 17:13:47 +0530
committernatsuoto <[email protected]>2026-07-01 17:13:47 +0530
commit080d5ac837ea8039b857d41dc9b258486748e5fe (patch)
tree52f2021db055cbb04cd8039217a8361cce9b68ce /tests
parent2d9e7395dc62ca7ff9c0bf508ca4fb5e823b538e (diff)
downloadedify-080d5ac837ea8039b857d41dc9b258486748e5fe.tar.xz
edify-080d5ac837ea8039b857d41dc9b258486748e5fe.zip
fix!: dangling quantifier raises DanglingQuantifierError at emit
Diffstat (limited to 'tests')
-rw-r--r--tests/errors/dangling_quantifier.test.py52
1 files changed, 52 insertions, 0 deletions
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