aboutsummaryrefslogtreecommitdiff
path: root/tests/library/invariants.test.py
diff options
context:
space:
mode:
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."
+ )