/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: Robert Collins
  • Date: 2006-05-18 12:40:03 UTC
  • mto: (1714.1.2 integration)
  • mto: This revision was merged to the branch mainline in revision 1716.
  • Revision ID: robertc@robertcollins.net-20060518124003-5f97fb42c52ca941
Combine ignore rules into a single regex preventing pathological behaviour during add.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
from cStringIO import StringIO
19
19
import os
 
20
import _sre
20
21
 
21
22
import bzrlib
22
23
from bzrlib.branch import Branch
234
235
        os.mkdir('lala.OTHER')
235
236
        expected = ContentsConflict('lala', file_id='lala-id')
236
237
        self.assertEqual(list(tree.conflicts()), [expected])
 
238
 
 
239
 
 
240
class TestNonFormatSpecificCode(TestCaseWithTransport):
 
241
    """This class contains tests of workingtree that are not format specific."""
 
242
 
 
243
    def test__translate_ignore_rule(self):
 
244
        tree = self.make_branch_and_tree('.')
 
245
        # translation should return the regex, the number of groups in it,
 
246
        # and the original rule in a tuple.
 
247
        # there are three sorts of ignore rules:
 
248
        # root only - regex is the rule itself without the leading ./
 
249
        self.assertEqual(
 
250
            "(rootdirrule$)", 
 
251
            tree._translate_ignore_rule("./rootdirrule"))
 
252
        # full path - regex is the rule itself
 
253
        self.assertEqual(
 
254
            "(path\\/to\\/file$)",
 
255
            tree._translate_ignore_rule("path/to/file"))
 
256
        # basename only rule - regex is a rule that ignores everything up
 
257
        # to the last / in the filename
 
258
        self.assertEqual(
 
259
            "((?:.*/)?(?!.*/)basenamerule$)",
 
260
            tree._translate_ignore_rule("basenamerule"))
 
261
 
 
262
    def test__combine_ignore_rules(self):
 
263
        tree = self.make_branch_and_tree('.')
 
264
        # the combined ignore regexs need the outer group indices
 
265
        # placed in a dictionary with the rules that were combined.
 
266
        # an empty set of rules
 
267
        compiled_rules = tree._combine_ignore_rules([])
 
268
        # what type *is* the compiled regex to do an isinstance of ?
 
269
        self.assertEqual(0, compiled_rules[0].groups)
 
270
        self.assertEqual({}, compiled_rules[1])
 
271
        # one of each type of rule.
 
272
        compiled_rules = tree._combine_ignore_rules(
 
273
            ["rule1", "rule/two", "./three"])
 
274
        self.assertEqual(3, compiled_rules[0].groups)
 
275
        self.assertEqual(
 
276
            {0:"rule1",1:"rule/two",2:"./three"},
 
277
            compiled_rules[1])
 
278
 
 
279
    def test__get_ignore_rules_as_regex(self):
 
280
        tree = self.make_branch_and_tree('.')
 
281
        # test against the default rules.
 
282
        reference_output = tree._combine_ignore_rules(bzrlib.DEFAULT_IGNORE)
 
283
        regex_rules = tree._get_ignore_rules_as_regex()
 
284
        self.assertEqual(len(reference_output[1]), regex_rules[0].groups)
 
285
        self.assertEqual(reference_output[1], regex_rules[1])