~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lazy_regex.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-09 09:41:01 UTC
  • mto: This revision was merged to the branch mainline in revision 2069.
  • Revision ID: john@arbash-meinel.com-20061009094101-dd6f359aa5ae70a0
Add install and unistall functions, and tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
        self.assertTrue(pattern.match('foo'))
81
81
        self.assertTrue(pattern.match('Foo'))
82
82
 
 
83
    def test_findall(self):
 
84
        pattern = lazy_regex.lazy_compile('fo*')
 
85
        self.assertEqual(['f', 'fo', 'foo', 'fooo'],
 
86
                         pattern.findall('f fo foo fooo'))
 
87
 
 
88
    def test_finditer(self):
 
89
        pattern = lazy_regex.lazy_compile('fo*')
 
90
        matches = [(m.start(), m.end(), m.group())
 
91
                   for m in pattern.finditer('foo bar fop')]
 
92
        self.assertEqual([(0, 3, 'foo'), (8, 10, 'fo')], matches)
 
93
 
 
94
    def test_match(self):
 
95
        pattern = lazy_regex.lazy_compile('fo*')
 
96
        self.assertIs(None, pattern.match('baz foo'))
 
97
        self.assertEqual('fooo', pattern.match('fooo').group())
 
98
 
 
99
    def test_search(self):
 
100
        pattern = lazy_regex.lazy_compile('fo*')
 
101
        self.assertEqual('foo', pattern.search('baz foo').group())
 
102
        self.assertEqual('fooo', pattern.search('fooo').group())
 
103
 
 
104
    def test_split(self):
 
105
        pattern = lazy_regex.lazy_compile('[,;]*')
 
106
        self.assertEqual(['x', 'y', 'z'], pattern.split('x,y;z'))
 
107
 
 
108
 
 
109
class TestInstallLazyCompile(tests.TestCase):
 
110
 
 
111
    def setUp(self):
 
112
        super(TestInstallLazyCompile, self).setUp()
 
113
        self.addCleanup(lazy_regex.reset_compile)
 
114
 
 
115
    def test_install(self):
 
116
        lazy_regex.install_lazy_compile()
 
117
        pattern = re.compile('foo')
 
118
        self.assertIsInstance(pattern, lazy_regex.LazyRegex)
 
119
 
 
120
    def test_reset(self):
 
121
        lazy_regex.install_lazy_compile()
 
122
        lazy_regex.reset_compile()
 
123
        pattern = re.compile('foo')
 
124
        self.failIf(isinstance(pattern, lazy_regex.LazyRegex),
 
125
                    'lazy_regex.reset_compile() did not restore the original'
 
126
                    ' compile() function %s' % (type(pattern),))
 
127
        # but the returned object should still support regex operations
 
128
        m = pattern.match('foo')
 
129
        self.assertEqual('foo', m.group())