aboutsummaryrefslogtreecommitdiff
path: root/tests/builder
diff options
context:
space:
mode:
author夏音 / natsuoto.exe <[email protected]>2026-07-01 16:13:54 +0530
committerGitHub <[email protected]>2026-07-01 16:13:54 +0530
commit42509f3a1d0c93c5fd43b2e2bdc42201d24a643e (patch)
tree5f1544aed63e707d5fb2aeeb87b6e7e0dc98f5cd /tests/builder
parenta757473f3551426948069a1a25ef6657a572d759 (diff)
parent341cf4fe45bb56677f0b42e287738999fb8a1ac5 (diff)
downloadedify-42509f3a1d0c93c5fd43b2e2bdc42201d24a643e.tar.xz
edify-42509f3a1d0c93c5fd43b2e2bdc42201d24a643e.zip
feat: .at_most(n) quantifier closes the symmetry gap with at_least/exactly/between (#265)
Adds `.at_most(n)` on both `RegexBuilder`/`Pattern` and as an `at_most(n, operand)` factory. Closes the symmetry gap in the quantifier lineup — we had `exactly(n)`, `at_least(n)`, and `between(lo, hi)`, but no `{0,n}` shorthand. ## What is new - `AtMostElement(times, child)` in the elements union, rendered as `{0,times}` by the quantifier suffix dispatch. - `.at_most(count)` chain method on `QuantifiersMixin` — validates `count > 0` (matches the `at_least` contract). - `at_most(count, operand)` free-function factory in the humre-style API. - Re-exported through `edify.pattern` and top-level `edify`. ## Example ```python from edify import DIGIT, at_most, Pattern at_most(3, DIGIT).to_regex_string() # \d{0,3} Pattern().at_most(3).digit().to_regex_string() # \d{0,3} ``` Closes #130
Diffstat (limited to 'tests/builder')
-rw-r--r--tests/builder/builder.test.py6
-rw-r--r--tests/builder/validation.test.py5
2 files changed, 11 insertions, 0 deletions
diff --git a/tests/builder/builder.test.py b/tests/builder/builder.test.py
index 062e1ae..33aa17d 100644
--- a/tests/builder/builder.test.py
+++ b/tests/builder/builder.test.py
@@ -348,6 +348,12 @@ def test_at_least():
regex_compilation("\\w{3,}", expr)
+def test_at_most():
+ expr = RegexBuilder().at_most(3).word()
+ regex_equality("\\w{0,3}", expr)
+ regex_compilation("\\w{0,3}", expr)
+
+
def test_between():
expr = RegexBuilder().between(3, 5).word()
regex_equality("\\w{3,5}", expr)
diff --git a/tests/builder/validation.test.py b/tests/builder/validation.test.py
index e4898ad..53128c5 100644
--- a/tests/builder/validation.test.py
+++ b/tests/builder/validation.test.py
@@ -109,6 +109,11 @@ def test_at_least_non_positive_raises():
RegexBuilder().at_least(-1).digit()
+def test_at_most_non_positive_raises():
+ with pytest.raises(MustBePositiveIntegerError):
+ RegexBuilder().at_most(0).digit()
+
+
def test_between_negative_lower_raises():
with pytest.raises(MustBeIntegerGreaterThanZeroError):
RegexBuilder().between(-1, 5).digit()