From a3a0b80effd34e1ee58e6644ea04e2df2f08dc4b Mon Sep 17 00:00:00 2001 From: natsuoto <279971144+natsuoto@users.noreply.github.com> Date: Wed, 1 Jul 2026 16:53:15 +0530 Subject: feat: convenience char classes .letter() .uppercase() .lowercase() .alphanumeric() --- tests/builder/builder.test.py | 24 ++++++++++++++++++++++++ tests/pattern/classes.test.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'tests') diff --git a/tests/builder/builder.test.py b/tests/builder/builder.test.py index 33aa17d..ddd1997 100644 --- a/tests/builder/builder.test.py +++ b/tests/builder/builder.test.py @@ -170,6 +170,30 @@ def test_null_byte(): regex_compilation("\\0", expr) +def test_letter(): + expr = RegexBuilder().letter() + regex_equality("[a-zA-Z]", expr) + regex_compilation("[a-zA-Z]", expr) + + +def test_uppercase(): + expr = RegexBuilder().uppercase() + regex_equality("[A-Z]", expr) + regex_compilation("[A-Z]", expr) + + +def test_lowercase(): + expr = RegexBuilder().lowercase() + regex_equality("[a-z]", expr) + regex_compilation("[a-z]", expr) + + +def test_alphanumeric(): + expr = RegexBuilder().alphanumeric() + regex_equality("[a-zA-Z0-9]", expr) + regex_compilation("[a-zA-Z0-9]", expr) + + def test_any_of_basic(): expr = RegexBuilder().any_of().string("hello").digit().word().char(".").char("#").end() regex_equality("(?:hello|\\d|\\w|[\\.\\#])", expr) diff --git a/tests/pattern/classes.test.py b/tests/pattern/classes.test.py index de6bfc0..8a82353 100644 --- a/tests/pattern/classes.test.py +++ b/tests/pattern/classes.test.py @@ -3,15 +3,19 @@ import pytest from edify import ( + ALPHANUMERIC, ANY_CHAR, CARRIAGE_RETURN, DIGIT, + LETTER, + LOWERCASE, NEW_LINE, NON_DIGIT, NON_WHITESPACE, NON_WORD, NULL_BYTE, TAB, + UPPERCASE, WHITESPACE, WORD, Pattern, @@ -32,6 +36,10 @@ from edify import ( (CARRIAGE_RETURN, "\\r"), (TAB, "\\t"), (NULL_BYTE, "\\0"), + (LETTER, "[a-zA-Z]"), + (UPPERCASE, "[A-Z]"), + (LOWERCASE, "[a-z]"), + (ALPHANUMERIC, "[a-zA-Z0-9]"), ], ) def test_character_class_constant_compiles_to_expected_regex(constant, expected): @@ -52,7 +60,29 @@ def test_character_class_constant_compiles_to_expected_regex(constant, expected) CARRIAGE_RETURN, TAB, NULL_BYTE, + LETTER, + UPPERCASE, + LOWERCASE, + ALPHANUMERIC, ], ) def test_character_class_constant_is_a_pattern(constant): assert isinstance(constant, Pattern) + + +@pytest.mark.parametrize( + ("constant", "hit_input", "miss_input"), + [ + (LETTER, "A", "4"), + (LETTER, "z", " "), + (UPPERCASE, "Q", "q"), + (LOWERCASE, "q", "Q"), + (ALPHANUMERIC, "4", " "), + (ALPHANUMERIC, "A", "!"), + ], +) +def test_convenience_char_class_constant_matches_expected_characters( + constant, hit_input, miss_input +): + assert constant.test(hit_input) is True + assert constant.test(miss_input) is False -- cgit v1.2.3