@@ -19,6 +19,8 @@ def test_no_match():
1919 assert result .matches is False
2020 assert result .failed_at == 0
2121 assert result .partial_matches == []
22+ # Should mention expected literal and got
23+ assert 'expected literal' in result .reason and 'got' in result .reason
2224 print ('test_no_match passed' )
2325
2426def test_partial_match ():
@@ -29,7 +31,8 @@ def test_partial_match():
2931 assert result .matches is False
3032 assert result .failed_at == 2
3133 assert result .partial_matches == ['ab' ]
32- assert 'unexpected character' in result .reason or 'failed at position' in result .reason
34+ # Should mention expected literal and got
35+ assert 'expected literal' in result .reason and 'got' in result .reason
3336 print ('test_partial_match passed' )
3437
3538def test_too_short ():
@@ -38,9 +41,52 @@ def test_too_short():
3841 assert result .matches is False
3942 assert result .failed_at == 2
4043 assert result .partial_matches == ['ab' ]
41- assert 'too short' in result .reason or 'failed at position' in result .reason
44+ # Should mention string too short or expected more input
45+ assert 'too short' in result .reason or 'expected more input' in result .reason
4246 print ('test_too_short passed' )
4347
48+ def test_charclass_fail ():
49+ tester = RegexTester ()
50+ result = tester .test (r'[0-9][a-z][A-Z]' , '1a!' )
51+ assert result .matches is False
52+ assert result .failed_at == 2
53+ assert 'expected character in [A-Z]' in result .reason and 'got' in result .reason
54+ print ('test_charclass_fail passed' )
55+
56+ def test_escape_fail ():
57+ tester = RegexTester ()
58+ # \d
59+ result = tester .test (r'\d' , 'a' )
60+ assert result .matches is False
61+ assert result .failed_at == 0
62+ assert r'expected \d' in result .reason and 'got' in result .reason
63+ # \w
64+ result = tester .test (r'\w' , '!' )
65+ assert result .matches is False
66+ assert result .failed_at == 0
67+ assert r'expected \w' in result .reason and 'got' in result .reason
68+ # \s
69+ result = tester .test (r'\s' , 'A' )
70+ assert result .matches is False
71+ assert result .failed_at == 0
72+ assert r'expected \s' in result .reason and 'got' in result .reason
73+ # \D
74+ result = tester .test (r'\D' , '5' )
75+ assert result .matches is False
76+ assert result .failed_at == 0
77+ assert r'expected \D' in result .reason and 'got' in result .reason
78+ # \S
79+ result = tester .test (r'\S' , ' ' )
80+ assert result .matches is False
81+ assert result .failed_at == 0
82+ assert r'expected \S' in result .reason and 'got' in result .reason
83+ # \W
84+ result = tester .test (r'\W' , 'a' )
85+ assert result .matches is False
86+ assert result .failed_at == 0
87+ assert r'expected \W' in result .reason and 'got' in result .reason
88+ print ('test_escape_fail passed' )
89+
4490def test_regex_features ():
4591 tester = RegexTester ()
4692 result = tester .test (r'\d{2,4}' , '123' )
@@ -67,6 +113,8 @@ def main():
67113 test_no_match ()
68114 test_partial_match ()
69115 test_too_short ()
116+ test_charclass_fail ()
117+ test_escape_fail ()
70118 test_regex_features ()
71119 test_flag_sensitive_match ()
72120 print ('All tester tests passed!' )
0 commit comments