aboutsummaryrefslogtreecommitdiff
path: root/tests/library/invariants.test.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-07-17 14:43:56 +0530
committerGitHub <[email protected]>2026-07-17 14:43:56 +0530
commitd27e5f4145972990544975a033d03abdd3a5f596 (patch)
treeb0d069809b22ee040e3bd294b6b7a868d926fde8 /tests/library/invariants.test.py
parent8bff9a0ec3c7b7207ecd994ace4c696b71fd84f5 (diff)
parent5d71c2f3b7218895a10bf485ddd3a04df2c4f66e (diff)
downloadedify-main.tar.xz
edify-main.zip
Multi-locale phone validator, expanded corpora, and all-validator round-trip + operator-algebra coverage (#288)HEADmain
Completes the remaining non-docs library items on the v1.0.0 milestone: a genuinely multi-locale `phone` validator, real per-locale corpus hardening, and an end-to-end coverage layer that exercises every shipped validator and the operator algebra. ## Multi-locale phone (#154) `phone` is rebuilt as a table-driven multi-locale model: an optional `+` or `00` prefix, two to eight digit groups of one to four digits each, single-character space/dot/dash separators, and any group optionally parenthesised. It now accepts the display forms it previously missed — leading and inline parenthesised area codes such as `(555) 123-4567` and `+44 (0)20 7946 0958`, and variable national grouping from three-group North American through five-group French — plus two-to-six-digit service and short codes. Doubled separators, bare prefixes, and letters are still rejected. The corpus grows from a seven-string smoke test to twenty-one real numbers across eleven locales with ten adversarial rejects. ## Postal locale coverage (#155) Multi-locale postal codes are delivered by the existing `postal` validator; this pins it down with a twenty-code corpus spanning North America, Europe, Asia, and Oceania (including alphanumeric UK, Irish, Canadian, and Dutch shapes) with ten adversarial rejects. `zip_code` stays deliberately US-scoped, with `postal` as its locale-complete counterpart. ## Validator snapshots (#191) Every per-validator migration to a callable `Pattern` has landed, so regenerating the built-in snapshot corpus is a no-op apart from `phone`'s new emitted shape, which is refreshed here. ## End-to-end coverage of every construct (#258) - Every registered library validator now round-trips through both dict and JSON serialization with its emitted regex preserved — a property test over the full validator set, alongside the existing compiled-source invariant. - The operator algebra (`+`, `|`, and `.use()`) is asserted identical to its fluent-chain equivalent across every character-class constant, at both the emitted-string and compiled-matcher level, so the two surfaces can never drift. - Hardening corpora expand beyond the smoke-test handful to `phone`, `postal`, `semver`, `slug`, `hostname`, `port`, `isbn`, and `vin`, each with real-world accepts and adversarial rejects. Closes #154, Closes #155, Closes #191, Closes #258
Diffstat (limited to 'tests/library/invariants.test.py')
-rw-r--r--tests/library/invariants.test.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/tests/library/invariants.test.py b/tests/library/invariants.test.py
index 662e81c..340f6a4 100644
--- a/tests/library/invariants.test.py
+++ b/tests/library/invariants.test.py
@@ -18,13 +18,10 @@ def _registered_patterns() -> Iterator[tuple[str, Pattern]]:
REGISTERED_PATTERNS: list[tuple[str, Pattern]] = list(_registered_patterns())
+_IDS = [registered_name for registered_name, _ in REGISTERED_PATTERNS]
- ("name", "pattern"),
- REGISTERED_PATTERNS,
- ids=[registered_name for registered_name, _ in REGISTERED_PATTERNS],
-)
[email protected](("name", "pattern"), REGISTERED_PATTERNS, ids=_IDS)
def test_to_regex_string_matches_the_compiled_pattern_source(name: str, pattern: Pattern):
emitted_source = pattern.to_regex_string()
compiled_source = pattern.to_regex().source
@@ -32,3 +29,19 @@ def test_to_regex_string_matches_the_compiled_pattern_source(name: str, pattern:
f"library pattern {name!r} emits {emitted_source!r} but its compiled Regex reports "
f"{compiled_source!r} — the terminals have drifted apart."
)
+
+
[email protected](("name", "pattern"), REGISTERED_PATTERNS, ids=_IDS)
+def test_dict_round_trip_preserves_the_emitted_regex(name: str, pattern: Pattern):
+ restored = Pattern.from_dict(pattern.to_dict())
+ assert restored.to_regex_string() == pattern.to_regex_string(), (
+ f"library pattern {name!r} does not survive a to_dict/from_dict round trip."
+ )
+
+
[email protected](("name", "pattern"), REGISTERED_PATTERNS, ids=_IDS)
+def test_json_round_trip_preserves_the_emitted_regex(name: str, pattern: Pattern):
+ restored = Pattern.from_json(pattern.to_json())
+ assert restored.to_regex_string() == pattern.to_regex_string(), (
+ f"library pattern {name!r} does not survive a to_json/from_json round trip."
+ )