Skip to content

Commit 881a921

Browse files
committed
Merge pull request #5 from mriehl/master
Refactored tests, added range tests
2 parents 4836e41 + 278c986 commit 881a921

File tree

2 files changed

+76
-53
lines changed

2 files changed

+76
-53
lines changed

tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
from verbal_expressions_test import *

tests/verbal_expressions_test.py

Lines changed: 76 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,108 +6,132 @@
66
class VerExTest(unittest.TestCase):
77
'''
88
Tests for verbal_expressions.py
9-
10-
The "range" method test is lacking, because I couldn't really understand its use.
11-
I could use some help. :)
129
'''
10+
1311
def setUp(self):
1412
self.v = VerEx()
15-
13+
1614
def tearDown(self):
1715
self.v = None
1816
self.exp = None
19-
20-
def test__str__(self):
17+
18+
def test_should_render_verex_as_string(self):
2119
self.assertEquals(str(self.v.add('^$')), '^$')
22-
23-
def test_start_of_line(self):
20+
21+
def test_should_match_characters_in_range(self):
22+
self.exp = self.v.start_of_line().range('a', 'c').regex()
23+
for character in ['a', 'b', 'c']:
24+
self.assertRegexpMatches(character, self.exp)
25+
26+
def test_should_not_match_characters_outside_of_range(self):
27+
self.exp = self.v.start_of_line().range('a', 'c').regex()
28+
self.assertNotRegexpMatches('d', self.exp)
29+
30+
def test_should_match_characters_in_extended_range(self):
31+
self.exp = self.v.start_of_line().range('a', 'b', 'X', 'Z').regex()
32+
for character in ['a', 'b']:
33+
self.assertRegexpMatches(character, self.exp)
34+
for character in ['X', 'Y', 'Z']:
35+
self.assertRegexpMatches(character, self.exp)
36+
37+
def test_should_not_match_characters_outside_of_extended_range(self):
38+
self.exp = self.v.start_of_line().range('a', 'b', 'X', 'Z').regex()
39+
self.assertNotRegexpMatches('c', self.exp)
40+
self.assertNotRegexpMatches('W', self.exp)
41+
42+
43+
def test_should_match_start_of_line(self):
2444
self.exp = self.v.start_of_line().regex()
2545
self.assertRegexpMatches('text ', self.exp, 'Not started :(')
26-
27-
def test_end_of_line(self):
46+
47+
def test_should_match_end_of_line(self):
2848
self.exp = self.v.start_of_line().end_of_line().regex()
2949
self.assertRegexpMatches('', self.exp, 'It\'s not the end!')
30-
31-
def test_anything(self):
50+
51+
def test_should_match_anything(self):
3252
self.exp = self.v.start_of_line().anything().end_of_line().regex()
3353
self.assertRegexpMatches('!@#$%¨&*()__+{}', self.exp, 'Not so anything...')
34-
35-
def test_anything_but(self):
54+
55+
def test_should_match_anything_but_specified_element_when_element_is_not_found(self):
3656
self.exp = self.v.start_of_line().anything_but('X').end_of_line().regex()
3757
self.assertRegexpMatches('Y Files', self.exp, 'Found the X!')
38-
39-
def test_anything_but_false(self):
58+
59+
def test_should_not_match_anything_but_specified_element_when_specified_element_is_found(self):
4060
self.exp = self.v.start_of_line().anything_but('X').end_of_line().regex()
41-
self.assertFalse(re.match(self.exp, 'VerEX'), 'Didn\'t found the X :(')
61+
self.assertNotRegexpMatches('VerEX', self.exp, 'Didn\'t found the X :(')
4262

43-
def test_find_true(self):
63+
def test_should_find_element(self):
4464
self.exp = self.v.start_of_line().find('Wally').end_of_line().regex()
4565
self.assertRegexpMatches('Wally', self.exp, '404! Wally not Found!')
4666

47-
def test_find_false(self):
67+
def test_should_not_find_missing_element(self):
4868
self.exp = self.v.start_of_line().find('Wally').end_of_line().regex()
49-
self.assertFalse(re.match(self.exp, 'Wall-e'), 'DAFUQ is Wall-e?')
69+
self.assertNotRegexpMatches('Wall-e', self.exp, 'DAFUQ is Wall-e?')
5070

51-
def test_maybe(self):
71+
def test_should_match_when_maybe_element_is_present(self):
5272
self.exp = self.v.start_of_line().find('Python2.').maybe('7').end_of_line().regex()
5373
self.assertRegexpMatches('Python2.7', self.exp, 'Version doesn\'t match!')
54-
55-
def test_any_true(self):
74+
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):
5680
self.exp = self.v.start_of_line().any('Q').anything().end_of_line().regex()
5781
self.assertRegexpMatches('Query', self.exp, 'No match found!')
58-
59-
def test_any_false(self):
82+
83+
def test_should_not_match_on_any_when_element_is_not_found(self):
6084
self.exp = self.v.start_of_line().any('Q').anything().end_of_line().regex()
61-
self.assertFalse(re.match(self.exp, 'W'), 'I\'ve found it!')
85+
self.assertNotRegexpMatches('W', self.exp, 'I\'ve found it!')
6286

63-
def test_line_break_true_n(self):
87+
def test_should_match_when_line_break_present(self):
6488
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
6589
self.assertRegexpMatches('Marco \n Polo', self.exp, 'Give me a break!!')
66-
67-
def test_line_break_true_rn(self):
90+
91+
def test_should_match_when_line_break_and_carriage_return_present(self):
6892
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
6993
self.assertRegexpMatches('Marco \r\n Polo', self.exp, 'Give me a break!!')
70-
71-
def test_line_break_false(self):
94+
95+
def test_should_not_match_when_line_break_is_missing(self):
7296
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
73-
self.assertFalse(re.match(self.exp, 'Marco Polo'), 'There\'s a break here!')
74-
75-
def test_tab_true(self):
97+
self.assertNotRegexpMatches('Marco Polo', self.exp, 'There\'s a break here!')
98+
99+
def test_should_match_when_tab_present(self):
76100
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
77101
self.assertRegexpMatches('One tab only ', self.exp, 'No tab here!')
78-
79-
def test_tab_false(self):
102+
103+
def test_should_not_match_when_tab_is_missing(self):
80104
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
81105
self.assertFalse(re.match(self.exp, 'No tab here'), 'There\'s a tab here!')
82-
83-
def test_word_true(self):
106+
107+
def test_should_match_when_word_present(self):
84108
self.exp = self.v.start_of_line().anything().word().end_of_line().regex()
85109
self.assertRegexpMatches('Oneword', self.exp, 'Not just a word!')
86-
87-
def test_word_false(self):
110+
111+
def test_not_match_when_two_words_are_present_instead_of_one(self):
88112
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
89113
self.assertFalse(re.match(self.exp, 'Two words'), 'I\'ve found two of them')
90-
91-
def test_or_true(self):
114+
115+
def test_should_match_when_or_condition_fulfilled(self):
92116
self.exp = self.v.start_of_line().anything().find('G').OR().find('h').end_of_line().regex()
93117
self.assertRegexpMatches('Github', self.exp, 'Octocat not found')
94-
95-
def test_or_false(self):
118+
119+
def test_should_not_match_when_or_condition_not_fulfilled(self):
96120
self.exp = self.v.start_of_line().anything().find('G').OR().find('h').end_of_line().regex()
97121
self.assertFalse(re.match(self.exp, 'Bitbucket'), 'Bucket not found')
98-
99-
def test_any_case(self):
122+
123+
def test_should_match_on_upper_case_when_lower_case_is_given_and_any_case_is_true(self):
100124
self.exp = self.v.start_of_line().find('THOR').end_of_line().with_any_case(True).regex()
101125
self.assertRegexpMatches('thor', self.exp, 'Upper case Thor, please!')
102-
103-
def test_multi_line(self):
126+
127+
def test_should_match_multiple_lines(self):
104128
self.exp = self.v.start_of_line().anything().find('Pong').anything().end_of_line().search_one_line(True).regex()
105129
self.assertRegexpMatches('Ping \n Pong \n Ping', self.exp, 'Pong didn\'t answer')
106-
107-
def test_email(self):
130+
131+
def test_should_match_email_address(self):
108132
self.exp = self.v.start_of_line().word().then('@').word().then('.').word().end_of_line().regex()
109133
self.assertRegexpMatches('mail@mail.com', self.exp, 'Not a valid email')
110-
111-
def test_url(self):
134+
135+
def test_should_match_url(self):
112136
self.exp = self.v.start_of_line().then('http').maybe('s').then('://').maybe('www.').word().then('.').word().maybe('/').end_of_line().regex()
113137
self.assertRegexpMatches('https://www.google.com/', self.exp, 'Not a valid email')

0 commit comments

Comments
 (0)