aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authornatsuoto <[email protected]>2026-07-01 16:53:15 +0530
committernatsuoto <[email protected]>2026-07-01 16:53:15 +0530
commita3a0b80effd34e1ee58e6644ea04e2df2f08dc4b (patch)
tree11609e05d57cff55dbbe0b81f21c7e2363b7011e /tests
parente859ce24e5ffc95653023669f9edf4d3a0344a8e (diff)
downloadedify-a3a0b80effd34e1ee58e6644ea04e2df2f08dc4b.tar.xz
edify-a3a0b80effd34e1ee58e6644ea04e2df2f08dc4b.zip
feat: convenience char classes .letter() .uppercase() .lowercase() .alphanumeric()
Diffstat (limited to 'tests')
-rw-r--r--tests/builder/builder.test.py24
-rw-r--r--tests/pattern/classes.test.py30
2 files changed, 54 insertions, 0 deletions
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)
+
+
+ ("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