diff options
| author | natsuoto <[email protected]> | 2026-07-01 15:36:40 +0530 |
|---|---|---|
| committer | natsuoto <[email protected]> | 2026-07-01 15:36:40 +0530 |
| commit | a7974d090211955c394e0fecbc547f73b7786a97 (patch) | |
| tree | 890106bf873d10604d5d141444519a039441bd14 /tests/pattern/operators.test.py | |
| parent | d46c40de921dd2ba62fbfcd0e2e4591eee8de2a9 (diff) | |
| download | edify-a7974d090211955c394e0fecbc547f73b7786a97.tar.xz edify-a7974d090211955c394e0fecbc547f73b7786a97.zip | |
feat: humre-style functional API — operators, constants, factories, matcher
Diffstat (limited to 'tests/pattern/operators.test.py')
| -rw-r--r-- | tests/pattern/operators.test.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/pattern/operators.test.py b/tests/pattern/operators.test.py new file mode 100644 index 0000000..74b672f --- /dev/null +++ b/tests/pattern/operators.test.py @@ -0,0 +1,54 @@ +"""Tests for the ``+`` and ``|`` operators on :class:`Pattern`.""" + +from edify import DIGIT, END, START, WORD, Pattern + + +def test_plus_concatenates_two_patterns(): + combined = Pattern().string("hello") + Pattern().string("world") + assert combined.to_regex_string() == "helloworld" + + +def test_plus_preserves_anchors_from_both_operands(): + combined = START + Pattern().exactly(4).digit() + END + assert combined.to_regex_string() == "^\\d{4}$" + + +def test_plus_returns_a_new_pattern_and_leaves_operands_untouched(): + left = Pattern().digit() + right = Pattern().word() + combined = left + right + assert combined is not left + assert combined is not right + assert left.to_regex_string() == "\\d" + assert right.to_regex_string() == "\\w" + + +def test_plus_using_module_constants_produces_expected_string(): + combined = DIGIT + WORD + assert combined.to_regex_string() == "\\d\\w" + + +def test_or_produces_alternation_between_two_patterns(): + combined = Pattern().string("http") | Pattern().string("https") + assert combined.to_regex_string() == "(?:http|https)" + + +def test_or_returns_a_new_pattern_and_leaves_operands_untouched(): + left = Pattern().string("cat") + right = Pattern().string("dog") + combined = left | right + assert combined is not left + assert combined is not right + assert left.to_regex_string() == "cat" + assert right.to_regex_string() == "dog" + + +def test_or_chaining_produces_three_way_alternation(): + combined = Pattern().string("cat") | Pattern().string("dog") | Pattern().string("fish") + assert combined.to_regex_string() == "(?:(?:cat|dog)|fish)" + + +def test_plus_composes_with_or_to_form_a_realistic_pattern(): + scheme = Pattern().string("http") | Pattern().string("https") + combined = scheme + Pattern().string("://") + assert combined.to_regex_string() == "(?:http|https)://" |
