@@ -7,14 +7,15 @@ class VerExTest(unittest.TestCase):
7
7
'''
8
8
Tests for verbal_expressions.py
9
9
'''
10
+
10
11
def setUp (self ):
11
12
self .v = VerEx ()
12
13
13
14
def tearDown (self ):
14
15
self .v = None
15
16
self .exp = None
16
17
17
- def test__str__ (self ):
18
+ def test_should_render_verex_as_string (self ):
18
19
self .assertEquals (str (self .v .add ('^$' )), '^$' )
19
20
20
21
def test_should_match_characters_in_range (self ):
@@ -39,94 +40,98 @@ def test_should_not_match_characters_outside_of_extended_range(self):
39
40
self .assertNotRegexpMatches ('W' , self .exp )
40
41
41
42
42
- def test_start_of_line (self ):
43
+ def test_should_match_start_of_line (self ):
43
44
self .exp = self .v .start_of_line ().regex ()
44
45
self .assertRegexpMatches ('text ' , self .exp , 'Not started :(' )
45
46
46
- def test_end_of_line (self ):
47
+ def test_should_match_end_of_line (self ):
47
48
self .exp = self .v .start_of_line ().end_of_line ().regex ()
48
49
self .assertRegexpMatches ('' , self .exp , 'It\' s not the end!' )
49
50
50
- def test_anything (self ):
51
+ def test_should_match_anything (self ):
51
52
self .exp = self .v .start_of_line ().anything ().end_of_line ().regex ()
52
53
self .assertRegexpMatches ('!@#$%¨&*()__+{}' , self .exp , 'Not so anything...' )
53
54
54
- def test_anything_but (self ):
55
+ def test_should_match_anything_but_specified_element_when_element_is_not_found (self ):
55
56
self .exp = self .v .start_of_line ().anything_but ('X' ).end_of_line ().regex ()
56
57
self .assertRegexpMatches ('Y Files' , self .exp , 'Found the X!' )
57
58
58
- def test_anything_but_false (self ):
59
+ def test_should_not_match_anything_but_specified_element_when_specified_element_is_found (self ):
59
60
self .exp = self .v .start_of_line ().anything_but ('X' ).end_of_line ().regex ()
60
- self .assertFalse ( re . match ( self . exp , 'VerEX' ) , 'Didn\' t found the X :(' )
61
+ self .assertNotRegexpMatches ( 'VerEX' , self . exp , 'Didn\' t found the X :(' )
61
62
62
- def test_find_true (self ):
63
+ def test_should_find_element (self ):
63
64
self .exp = self .v .start_of_line ().find ('Wally' ).end_of_line ().regex ()
64
65
self .assertRegexpMatches ('Wally' , self .exp , '404! Wally not Found!' )
65
66
66
- def test_find_false (self ):
67
+ def test_should_not_find_missing_element (self ):
67
68
self .exp = self .v .start_of_line ().find ('Wally' ).end_of_line ().regex ()
68
- self .assertFalse ( re . match ( self . exp , 'Wall-e' ) , 'DAFUQ is Wall-e?' )
69
+ self .assertNotRegexpMatches ( 'Wall-e' , self . exp , 'DAFUQ is Wall-e?' )
69
70
70
- def test_maybe (self ):
71
+ def test_should_match_when_maybe_element_is_present (self ):
71
72
self .exp = self .v .start_of_line ().find ('Python2.' ).maybe ('7' ).end_of_line ().regex ()
72
73
self .assertRegexpMatches ('Python2.7' , self .exp , 'Version doesn\' t match!' )
73
74
74
- def test_any_true (self ):
75
+ def test_should_match_when_maybe_element_is_missing (self ):
76
+ self .exp = self .v .start_of_line ().find ('Python2.' ).maybe ('7' ).end_of_line ().regex ()
77
+ self .assertRegexpMatches ('Python2.' , self .exp , 'Version doesn\' t match!' )
78
+
79
+ def test_should_match_on_any_when_element_is_found (self ):
75
80
self .exp = self .v .start_of_line ().any ('Q' ).anything ().end_of_line ().regex ()
76
81
self .assertRegexpMatches ('Query' , self .exp , 'No match found!' )
77
82
78
- def test_any_false (self ):
83
+ def test_should_not_match_on_any_when_element_is_not_found (self ):
79
84
self .exp = self .v .start_of_line ().any ('Q' ).anything ().end_of_line ().regex ()
80
- self .assertFalse ( re . match ( self . exp , 'W' ) , 'I\' ve found it!' )
85
+ self .assertNotRegexpMatches ( 'W' , self . exp , 'I\' ve found it!' )
81
86
82
- def test_line_break_true_n (self ):
87
+ def test_should_match_when_line_break_present (self ):
83
88
self .exp = self .v .start_of_line ().anything ().line_break ().anything ().end_of_line ().regex ()
84
89
self .assertRegexpMatches ('Marco \n Polo' , self .exp , 'Give me a break!!' )
85
90
86
- def test_line_break_true_rn (self ):
91
+ def test_should_match_when_line_break_and_carriage_return_present (self ):
87
92
self .exp = self .v .start_of_line ().anything ().line_break ().anything ().end_of_line ().regex ()
88
93
self .assertRegexpMatches ('Marco \r \n Polo' , self .exp , 'Give me a break!!' )
89
94
90
- def test_line_break_false (self ):
95
+ def test_should_not_match_when_line_break_is_missing (self ):
91
96
self .exp = self .v .start_of_line ().anything ().line_break ().anything ().end_of_line ().regex ()
92
- self .assertFalse ( re . match ( self . exp , 'Marco Polo' ) , 'There\' s a break here!' )
97
+ self .assertNotRegexpMatches ( 'Marco Polo' , self . exp , 'There\' s a break here!' )
93
98
94
- def test_tab_true (self ):
99
+ def test_should_match_when_tab_present (self ):
95
100
self .exp = self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
96
101
self .assertRegexpMatches ('One tab only ' , self .exp , 'No tab here!' )
97
102
98
- def test_tab_false (self ):
103
+ def test_should_not_match_when_tab_is_missing (self ):
99
104
self .exp = self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
100
105
self .assertFalse (re .match (self .exp , 'No tab here' ), 'There\' s a tab here!' )
101
106
102
- def test_word_true (self ):
107
+ def test_should_match_when_word_present (self ):
103
108
self .exp = self .v .start_of_line ().anything ().word ().end_of_line ().regex ()
104
109
self .assertRegexpMatches ('Oneword' , self .exp , 'Not just a word!' )
105
110
106
- def test_word_false (self ):
111
+ def test_not_match_when_two_words_are_present_instead_of_one (self ):
107
112
self .exp = self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
108
113
self .assertFalse (re .match (self .exp , 'Two words' ), 'I\' ve found two of them' )
109
114
110
- def test_or_true (self ):
115
+ def test_should_match_when_or_condition_fulfilled (self ):
111
116
self .exp = self .v .start_of_line ().anything ().find ('G' ).OR ().find ('h' ).end_of_line ().regex ()
112
117
self .assertRegexpMatches ('Github' , self .exp , 'Octocat not found' )
113
118
114
- def test_or_false (self ):
119
+ def test_should_not_match_when_or_condition_not_fulfilled (self ):
115
120
self .exp = self .v .start_of_line ().anything ().find ('G' ).OR ().find ('h' ).end_of_line ().regex ()
116
121
self .assertFalse (re .match (self .exp , 'Bitbucket' ), 'Bucket not found' )
117
122
118
- def test_any_case (self ):
123
+ def test_should_match_on_upper_case_when_lower_case_is_given_and_any_case_is_true (self ):
119
124
self .exp = self .v .start_of_line ().find ('THOR' ).end_of_line ().with_any_case (True ).regex ()
120
125
self .assertRegexpMatches ('thor' , self .exp , 'Upper case Thor, please!' )
121
126
122
- def test_multi_line (self ):
127
+ def test_should_match_multiple_lines (self ):
123
128
self .exp = self .v .start_of_line ().anything ().find ('Pong' ).anything ().end_of_line ().search_one_line (True ).regex ()
124
129
self .assertRegexpMatches ('Ping \n Pong \n Ping' , self .exp , 'Pong didn\' t answer' )
125
130
126
- def test_email (self ):
131
+ def test_should_match_email_address (self ):
127
132
self .exp = self .v .start_of_line ().word ().then ('@' ).word ().then ('.' ).word ().end_of_line ().regex ()
128
133
self .assertRegexpMatches ('mail@mail.com' , self .exp , 'Not a valid email' )
129
134
130
- def test_url (self ):
135
+ def test_should_match_url (self ):
131
136
self .exp = self .v .start_of_line ().then ('http' ).maybe ('s' ).then ('://' ).maybe ('www.' ).word ().then ('.' ).word ().maybe ('/' ).end_of_line ().regex ()
132
137
self .assertRegexpMatches ('https://www.google.com/' , self .exp , 'Not a valid email' )
0 commit comments