@@ -7,14 +7,15 @@ class VerExTest(unittest.TestCase):
77 '''
88 Tests for verbal_expressions.py
99 '''
10+
1011 def setUp (self ):
1112 self .v = VerEx ()
1213
1314 def tearDown (self ):
1415 self .v = None
1516 self .exp = None
1617
17- def test__str__ (self ):
18+ def test_should_render_verex_as_string (self ):
1819 self .assertEquals (str (self .v .add ('^$' )), '^$' )
1920
2021 def test_should_match_characters_in_range (self ):
@@ -39,94 +40,98 @@ def test_should_not_match_characters_outside_of_extended_range(self):
3940 self .assertNotRegexpMatches ('W' , self .exp )
4041
4142
42- def test_start_of_line (self ):
43+ def test_should_match_start_of_line (self ):
4344 self .exp = self .v .start_of_line ().regex ()
4445 self .assertRegexpMatches ('text ' , self .exp , 'Not started :(' )
4546
46- def test_end_of_line (self ):
47+ def test_should_match_end_of_line (self ):
4748 self .exp = self .v .start_of_line ().end_of_line ().regex ()
4849 self .assertRegexpMatches ('' , self .exp , 'It\' s not the end!' )
4950
50- def test_anything (self ):
51+ def test_should_match_anything (self ):
5152 self .exp = self .v .start_of_line ().anything ().end_of_line ().regex ()
5253 self .assertRegexpMatches ('!@#$%¨&*()__+{}' , self .exp , 'Not so anything...' )
5354
54- def test_anything_but (self ):
55+ def test_should_match_anything_but_specified_element_when_element_is_not_found (self ):
5556 self .exp = self .v .start_of_line ().anything_but ('X' ).end_of_line ().regex ()
5657 self .assertRegexpMatches ('Y Files' , self .exp , 'Found the X!' )
5758
58- def test_anything_but_false (self ):
59+ def test_should_not_match_anything_but_specified_element_when_specified_element_is_found (self ):
5960 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 :(' )
6162
62- def test_find_true (self ):
63+ def test_should_find_element (self ):
6364 self .exp = self .v .start_of_line ().find ('Wally' ).end_of_line ().regex ()
6465 self .assertRegexpMatches ('Wally' , self .exp , '404! Wally not Found!' )
6566
66- def test_find_false (self ):
67+ def test_should_not_find_missing_element (self ):
6768 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?' )
6970
70- def test_maybe (self ):
71+ def test_should_match_when_maybe_element_is_present (self ):
7172 self .exp = self .v .start_of_line ().find ('Python2.' ).maybe ('7' ).end_of_line ().regex ()
7273 self .assertRegexpMatches ('Python2.7' , self .exp , 'Version doesn\' t match!' )
7374
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 ):
7580 self .exp = self .v .start_of_line ().any ('Q' ).anything ().end_of_line ().regex ()
7681 self .assertRegexpMatches ('Query' , self .exp , 'No match found!' )
7782
78- def test_any_false (self ):
83+ def test_should_not_match_on_any_when_element_is_not_found (self ):
7984 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!' )
8186
82- def test_line_break_true_n (self ):
87+ def test_should_match_when_line_break_present (self ):
8388 self .exp = self .v .start_of_line ().anything ().line_break ().anything ().end_of_line ().regex ()
8489 self .assertRegexpMatches ('Marco \n Polo' , self .exp , 'Give me a break!!' )
8590
86- def test_line_break_true_rn (self ):
91+ def test_should_match_when_line_break_and_carriage_return_present (self ):
8792 self .exp = self .v .start_of_line ().anything ().line_break ().anything ().end_of_line ().regex ()
8893 self .assertRegexpMatches ('Marco \r \n Polo' , self .exp , 'Give me a break!!' )
8994
90- def test_line_break_false (self ):
95+ def test_should_not_match_when_line_break_is_missing (self ):
9196 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!' )
9398
94- def test_tab_true (self ):
99+ def test_should_match_when_tab_present (self ):
95100 self .exp = self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
96101 self .assertRegexpMatches ('One tab only ' , self .exp , 'No tab here!' )
97102
98- def test_tab_false (self ):
103+ def test_should_not_match_when_tab_is_missing (self ):
99104 self .exp = self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
100105 self .assertFalse (re .match (self .exp , 'No tab here' ), 'There\' s a tab here!' )
101106
102- def test_word_true (self ):
107+ def test_should_match_when_word_present (self ):
103108 self .exp = self .v .start_of_line ().anything ().word ().end_of_line ().regex ()
104109 self .assertRegexpMatches ('Oneword' , self .exp , 'Not just a word!' )
105110
106- def test_word_false (self ):
111+ def test_not_match_when_two_words_are_present_instead_of_one (self ):
107112 self .exp = self .v .start_of_line ().anything ().tab ().end_of_line ().regex ()
108113 self .assertFalse (re .match (self .exp , 'Two words' ), 'I\' ve found two of them' )
109114
110- def test_or_true (self ):
115+ def test_should_match_when_or_condition_fulfilled (self ):
111116 self .exp = self .v .start_of_line ().anything ().find ('G' ).OR ().find ('h' ).end_of_line ().regex ()
112117 self .assertRegexpMatches ('Github' , self .exp , 'Octocat not found' )
113118
114- def test_or_false (self ):
119+ def test_should_not_match_when_or_condition_not_fulfilled (self ):
115120 self .exp = self .v .start_of_line ().anything ().find ('G' ).OR ().find ('h' ).end_of_line ().regex ()
116121 self .assertFalse (re .match (self .exp , 'Bitbucket' ), 'Bucket not found' )
117122
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 ):
119124 self .exp = self .v .start_of_line ().find ('THOR' ).end_of_line ().with_any_case (True ).regex ()
120125 self .assertRegexpMatches ('thor' , self .exp , 'Upper case Thor, please!' )
121126
122- def test_multi_line (self ):
127+ def test_should_match_multiple_lines (self ):
123128 self .exp = self .v .start_of_line ().anything ().find ('Pong' ).anything ().end_of_line ().search_one_line (True ).regex ()
124129 self .assertRegexpMatches ('Ping \n Pong \n Ping' , self .exp , 'Pong didn\' t answer' )
125130
126- def test_email (self ):
131+ def test_should_match_email_address (self ):
127132 self .exp = self .v .start_of_line ().word ().then ('@' ).word ().then ('.' ).word ().end_of_line ().regex ()
128133 self .assertRegexpMatches ('mail@mail.com' , self .exp , 'Not a valid email' )
129134
130- def test_url (self ):
135+ def test_should_match_url (self ):
131136 self .exp = self .v .start_of_line ().then ('http' ).maybe ('s' ).then ('://' ).maybe ('www.' ).word ().then ('.' ).word ().maybe ('/' ).end_of_line ().regex ()
132137 self .assertRegexpMatches ('https://www.google.com/' , self .exp , 'Not a valid email' )
0 commit comments