Skip to content

Commit 51f5aa1

Browse files
committed
Merge pull request #1 from diogobeda/master
Python tests written
2 parents 84a0b43 + b56140d commit 51f5aa1

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

tests/verbal_expressions_test.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# -*- encoding: utf-8 -*-
2+
import unittest
3+
from verbal_expressions import VerEx
4+
import re
5+
6+
class VerExTest(unittest.TestCase):
7+
'''
8+
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. :)
12+
'''
13+
def setUp(self):
14+
self.v = VerEx()
15+
16+
def tearDown(self):
17+
self.v = None
18+
self.exp = None
19+
20+
def test__str__(self):
21+
self.assertEquals(str(self.v.add('^$')), '^$')
22+
23+
def test_start_of_line(self):
24+
self.exp = self.v.start_of_line().regex()
25+
self.assertRegexpMatches('text ', self.exp, 'Not started :(')
26+
27+
def test_end_of_line(self):
28+
self.exp = self.v.start_of_line().end_of_line().regex()
29+
self.assertRegexpMatches('', self.exp, 'It\'s not the end!')
30+
31+
def test_anything(self):
32+
self.exp = self.v.start_of_line().anything().end_of_line().regex()
33+
self.assertRegexpMatches('!@#$%¨&*()__+{}', self.exp, 'Not so anything...')
34+
35+
def test_anything_but(self):
36+
self.exp = self.v.start_of_line().anything_but('X').end_of_line().regex()
37+
self.assertRegexpMatches('Y Files', self.exp, 'Found the X!')
38+
39+
def test_anything_but_false(self):
40+
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 :(')
42+
43+
def test_find_true(self):
44+
self.exp = self.v.start_of_line().find('Wally').end_of_line().regex()
45+
self.assertRegexpMatches('Wally', self.exp, '404! Wally not Found!')
46+
47+
def test_find_false(self):
48+
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?')
50+
51+
def test_maybe(self):
52+
self.exp = self.v.start_of_line().find('Python2.').maybe('7').end_of_line().regex()
53+
self.assertRegexpMatches('Python2.7', self.exp, 'Version doesn\'t match!')
54+
55+
def test_any_true(self):
56+
self.exp = self.v.start_of_line().any('Q').anything().end_of_line().regex()
57+
self.assertRegexpMatches('Query', self.exp, 'No match found!')
58+
59+
def test_any_false(self):
60+
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!')
62+
63+
def test_line_break_true_n(self):
64+
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
65+
self.assertRegexpMatches('Marco \n Polo', self.exp, 'Give me a break!!')
66+
67+
def test_line_break_true_rn(self):
68+
self.exp = self.v.start_of_line().anything().line_break().anything().end_of_line().regex()
69+
self.assertRegexpMatches('Marco \r\n Polo', self.exp, 'Give me a break!!')
70+
71+
def test_line_break_false(self):
72+
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):
76+
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
77+
self.assertRegexpMatches('One tab only ', self.exp, 'No tab here!')
78+
79+
def test_tab_false(self):
80+
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
81+
self.assertFalse(re.match(self.exp, 'No tab here'), 'There\'s a tab here!')
82+
83+
def test_word_true(self):
84+
self.exp = self.v.start_of_line().anything().word().end_of_line().regex()
85+
self.assertRegexpMatches('Oneword', self.exp, 'Not just a word!')
86+
87+
def test_word_false(self):
88+
self.exp = self.v.start_of_line().anything().tab().end_of_line().regex()
89+
self.assertFalse(re.match(self.exp, 'Two words'), 'I\'ve found two of them')
90+
91+
def test_or_true(self):
92+
self.exp = self.v.start_of_line().anything().find('G').OR().find('h').end_of_line().regex()
93+
self.assertRegexpMatches('Github', self.exp, 'Octocat not found')
94+
95+
def test_or_false(self):
96+
self.exp = self.v.start_of_line().anything().find('G').OR().find('h').end_of_line().regex()
97+
self.assertFalse(re.match(self.exp, 'Bitbucket'), 'Bucket not found')
98+
99+
def test_any_case(self):
100+
self.exp = self.v.start_of_line().find('THOR').end_of_line().with_any_case(True).regex()
101+
self.assertRegexpMatches('thor', self.exp, 'Upper case Thor, please!')
102+
103+
def test_multi_line(self):
104+
self.exp = self.v.start_of_line().anything().find('Pong').anything().end_of_line().search_one_line(True).regex()
105+
self.assertRegexpMatches('Ping \n Pong \n Ping', self.exp, 'Pong didn\'t answer')
106+
107+
def test_email(self):
108+
self.exp = self.v.start_of_line().word().then('@').word().then('.').word().end_of_line().regex()
109+
self.assertRegexpMatches('mail@mail.com', self.exp, 'Not a valid email')
110+
111+
def test_url(self):
112+
self.exp = self.v.start_of_line().then('http').maybe('s').then('://').maybe('www.').word().then('.').word().maybe('/').end_of_line().regex()
113+
self.assertRegexpMatches('https://www.google.com/', self.exp, 'Not a valid email')
File renamed without changes.

0 commit comments

Comments
 (0)