258
259
class TestNonFormatSpecificCode(TestCaseWithTransport):
259
260
"""This class contains tests of workingtree that are not format specific."""
262
262
def test_gen_file_id(self):
263
gen_file_id = bzrlib.workingtree.gen_file_id
265
# We try to use the filename if possible
266
self.assertStartsWith(gen_file_id('bar'), 'bar-')
268
# but we squash capitalization, and remove non word characters
269
self.assertStartsWith(gen_file_id('Mwoo oof\t m'), 'mwoooofm-')
271
# We also remove leading '.' characters to prevent hidden file-ids
272
self.assertStartsWith(gen_file_id('..gam.py'), 'gam.py-')
273
self.assertStartsWith(gen_file_id('..Mwoo oof\t m'), 'mwoooofm-')
275
# we remove unicode characters, and still don't end up with a
277
self.assertStartsWith(gen_file_id(u'\xe5\xb5.txt'), 'txt-')
263
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_file_id,
265
self.assertStartsWith(file_id, 'filename-')
267
def test_gen_root_id(self):
268
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_root_id)
269
self.assertStartsWith(file_id, 'tree_root-')
279
# Our current method of generating unique ids adds 33 characters
280
# plus an serial number (log10(N) characters)
281
# to the end of the filename. We now restrict the filename portion to
282
# be <= 20 characters, so the maximum length should now be approx < 60
284
# Test both case squashing and length restriction
285
fid = gen_file_id('A'*50 + '.txt')
286
self.assertStartsWith(fid, 'a'*20 + '-')
287
self.failUnless(len(fid) < 60)
289
# restricting length happens after the other actions, so
290
# we preserve as much as possible
291
fid = gen_file_id('\xe5\xb5..aBcd\tefGhijKLMnop\tqrstuvwxyz')
292
self.assertStartsWith(fid, 'abcdefghijklmnopqrst-')
293
self.failUnless(len(fid) < 60)
295
def test_next_id_suffix(self):
296
bzrlib.workingtree._gen_id_suffix = None
297
bzrlib.workingtree._next_id_suffix()
298
self.assertNotEqual(None, bzrlib.workingtree._gen_id_suffix)
299
bzrlib.workingtree._gen_id_suffix = "foo-"
300
bzrlib.workingtree._gen_id_serial = 1
301
self.assertEqual("foo-2", bzrlib.workingtree._next_id_suffix())
302
self.assertEqual("foo-3", bzrlib.workingtree._next_id_suffix())
303
self.assertEqual("foo-4", bzrlib.workingtree._next_id_suffix())
304
self.assertEqual("foo-5", bzrlib.workingtree._next_id_suffix())
305
self.assertEqual("foo-6", bzrlib.workingtree._next_id_suffix())
306
self.assertEqual("foo-7", bzrlib.workingtree._next_id_suffix())
307
self.assertEqual("foo-8", bzrlib.workingtree._next_id_suffix())
308
self.assertEqual("foo-9", bzrlib.workingtree._next_id_suffix())
309
self.assertEqual("foo-10", bzrlib.workingtree._next_id_suffix())
311
271
def test__translate_ignore_rule(self):
312
272
tree = self.make_branch_and_tree('.')
313
273
# translation should return the regex, the number of groups in it,