diff options
| author | natsuoto <[email protected]> | 2026-07-15 14:05:41 +0530 |
|---|---|---|
| committer | natsuoto <[email protected]> | 2026-07-15 14:05:41 +0530 |
| commit | f14a239abc99f3575bbc3ce26a6b4e3871891b0c (patch) | |
| tree | a857847064faa8e1af393f5b61a314f620fa4908 /tests/discipline | |
| parent | 111a310d05df79582a0d8f51c20046b63a002cd7 (diff) | |
| download | edify-f14a239abc99f3575bbc3ce26a6b4e3871891b0c.tar.xz edify-f14a239abc99f3575bbc3ce26a6b4e3871891b0c.zip | |
feat!(builder): close the match-verb surface at test/match/search/findall/sub; reach fullmatch/finditer/subn/split via .to_regex()
Diffstat (limited to 'tests/discipline')
| -rw-r--r-- | tests/discipline/matcher.test.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/discipline/matcher.test.py b/tests/discipline/matcher.test.py new file mode 100644 index 0000000..8697daf --- /dev/null +++ b/tests/discipline/matcher.test.py @@ -0,0 +1,42 @@ +"""Discipline test — the builder exposes exactly the five closed match verbs.""" + +import pytest + +from edify import Pattern, RegexBuilder + +_ALLOWED_MATCH_VERBS = frozenset({"test", "match", "search", "findall", "sub"}) +_FORBIDDEN_MATCH_VERBS = frozenset({"fullmatch", "finditer", "subn", "split"}) +_FORBIDDEN_RE_PATTERN_ATTRS = frozenset({"groups", "groupindex", "pattern", "flags"}) + + [email protected]("factory", [RegexBuilder, Pattern]) +def test_builder_exposes_every_allowed_match_verb(factory): + builder = factory() + for verb in _ALLOWED_MATCH_VERBS: + assert callable(getattr(builder, verb)), f"missing verb: {verb}" + + [email protected]("factory", [RegexBuilder, Pattern]) +def test_builder_does_not_expose_any_forbidden_match_verb(factory): + builder = factory() + for verb in _FORBIDDEN_MATCH_VERBS: + assert not hasattr(builder, verb), ( + f"builder must not expose re.Pattern verb {verb!r}; " + "use .to_regex() and call it on the Regex wrapper instead" + ) + + [email protected]("factory", [RegexBuilder, Pattern]) +def test_builder_does_not_expose_re_pattern_metadata_attributes(factory): + builder = factory() + for attribute in _FORBIDDEN_RE_PATTERN_ATTRS: + assert not hasattr(builder, attribute), ( + f"builder must not expose re.Pattern attribute {attribute!r}" + ) + + +def test_regex_wrapper_exposes_every_re_pattern_verb(): + regex = RegexBuilder().string("a").to_regex() + re_pattern_verbs = (_ALLOWED_MATCH_VERBS | _FORBIDDEN_MATCH_VERBS) - {"test"} + for verb in re_pattern_verbs: + assert callable(getattr(regex, verb)), f"Regex wrapper missing verb: {verb}" |
