def test_repr(self): exp = '(foo).*?(bar)' text = 'so foo is the opposite of bar but without foo there is no bar?' searched = research(exp, text) expected = ('so [[foo#1] is the opposite of [bar#2]#0] but without ' '[[foo#1] there is no [bar#2]#0]?') self.assertEqual(searched.repr, expected)
def test_sub(self): exp = '(foo).*?(bar)' text = 'so foo is the opposite of bar but without foo there is no bar?' searched = research(exp, text) searched.sub('zaz', 2) expected = ('so foo is the opposite of zaz but without foo there is ' 'no zaz?') self.assertEqual(searched.str, expected)
def test_basic(self): exp = '(foo).*?(bar)' text = 'so foo is the opposite of bar but without foo there is no bar?' searched = research(exp, text) self.assertEqual(searched[0], 'so ') self.assertEqual(searched[1].text, 'foo is the opposite of bar') self.assertEqual(searched[2], ' but without ') self.assertEqual(searched[3].text, 'foo there is no bar') self.assertEqual(searched[4], '?') matches = searched.matches self.assertEqual(2, len(matches)) self.assertEqual('foo is the opposite of bar', matches[0].text)
def test_str(self): exp = '(foo).*(bar)' text = 'so foo is the opposite of bar but without foo there is no bar?' searched = research(exp, text) self.assertEqual(searched.str, text)