class Regex(PatternTestCase): def test_exact(self): self.assert_match('', '') self.assert_match(' ', ' ') self.assert_match('foo', 'foo') self.assert_match('foo^', 'foo') # ^ is not special outside of [] def test_escaping(self): self.assert_match('foo(', r'foo\(') self.assert_match('foo.', r'foo\.') def test_dot(self): text = 'foo' for char in self.ALPHABET: self.assert_match(text + char, re.escape(text) + '.') def test_dots(self): text = 'foo' for suffix in self.suffixes(): self.assert_match(text + suffix, re.escape(text) + '.*') def test_square_brackets(self): text = 'foo' for suffix in self.suffixes(): square_pattern = ''.join('[%s]' % char for char in suffix) self.assert_match(text + suffix, re.escape(text) + square_pattern) test_repr = lambda self: self.assert_repr(__unit__.Regex('.')) # Assertion functions def assert_match(self, value, pattern): return super(Regex, self).assert_match(__unit__.Regex(pattern), value) def assert_no_match(self, value, pattern): return super(Regex, self) \ .assert_no_match(__unit__.Regex(pattern), value)
def assert_no_match(self, value, pattern): return super(Regex, self) \ .assert_no_match(__unit__.Regex(pattern), value)