Ejemplo n.º 1
0
 def xtest_several_substitutions_0_1(self):
     """
     Test a few substitutions, with $0
     """
     r = Regex(r'\w(\w+)', False, False, False, '$0FOO$1')
     subs = [sub for sub in r.substitutions('the quick brown')]
     self.assertEquals(['theFOOhe', 'quickFOOuick', 'brownFOOrown'], subs)
Ejemplo n.º 2
0
 def test_multiple_substitution(self):
     """
     Test a simple match causing several substitutions.
     """
     r = Regex('foo', False, False, False, '$0')
     subs = [sub for sub in r.substitutions('foo foo foobar foo')]
     self.assertEquals(['foo', 'foo', 'foo', 'foo'], subs)
Ejemplo n.º 3
0
 def test_bad_group(self):
     """
     Test that a bad group throws an exception we know about.
     """
     r = Regex('foo', False, False, False, '$1')
     with self.assertRaises(PatternError):
         r.substitutions('foo').next()
Ejemplo n.º 4
0
 def test_no_matches(self):
     """
     Test zero-length list from no matches
     """
     r = Regex('foo', False, False, False, '$0')
     subs = [sub for sub in r.substitutions('bar')]
     self.assertEquals([], subs)
Ejemplo n.º 5
0
 def test_single_substitution(self):
     """
     Test a single simple match for entire group.
     """
     r = Regex('foo', False, False, False, '$0')
     subs = [sub for sub in r.substitutions('foobar')]
     self.assertEquals(['foo'], subs)
Ejemplo n.º 6
0
 def test_middle_single(self):
     """
     Support for explicit single word in middle.
     """
     r = Regex(r'\w+', False, False, False, '$0')
     subs = [sub for sub in r.substitutions('the quick brown fox', 2, 3)]
     self.assertEquals(['brown'], subs)
Ejemplo n.º 7
0
 def test_middle_slice(self):
     """
     Support for explicit middle slice.
     """
     r = Regex(r'\w+', False, False, False, '$0')
     subs = [sub for sub in r.substitutions('the quick brown fox', 1, 3)]
     self.assertEquals(['quick', 'brown'], subs)
Ejemplo n.º 8
0
 def test_beginning(self):
     """
     Support for explicit beginning range.
     """
     r = Regex(r'\w+', False, False, False, '$0')
     subs = [sub for sub in r.substitutions('the quick brown fox', 0, 2)]
     self.assertEquals(['the', 'quick'], subs)
Ejemplo n.º 9
0
 def test_range(self):
     """
     Should get the whole range by default.
     """
     r = Regex(r'\w+', False, False, False, '$0')
     subs = [sub for sub in r.substitutions('the quick brown fox')]
     self.assertEquals(['the', 'quick', 'brown', 'fox'], subs)
Ejemplo n.º 10
0
 def test_several_substitutions_1_2(self):
     """
     Test a few substitutions, without $0
     """
     r = Regex(r'(\w)(\w+)', False, False, False, '$1FOO$2')
     subs = [sub for sub in r.substitutions('the quick brown')]
     self.assertEquals(['tFOOhe', 'qFOOuick', 'bFOOrown'], subs)