32
32
from bzrlib.win32utils import glob_expand, get_app_path
38
class _NeedsGlobExpansionFeature(Feature):
35
class _BackslashDirSeparatorFeature(tests.Feature):
41
return sys.platform == 'win32'
39
os.lstat(os.getcwd() + '\\')
43
45
def feature_name(self):
44
return 'Internally performed glob expansion'
46
return "Filesystem treats '\\' as a directory separator."
46
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
48
BackslashDirSeparatorFeature = _BackslashDirSeparatorFeature()
49
51
class _RequiredModuleFeature(Feature):
73
class TestNeedsGlobExpansionFeature(TestCase):
75
def test_available(self):
76
self.assertEqual(sys.platform == 'win32',
77
NeedsGlobExpansionFeature.available())
80
self.assertTrue("performed" in str(NeedsGlobExpansionFeature))
83
75
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
85
_test_needs_features = [NeedsGlobExpansionFeature]
77
_test_needs_features = []
87
79
def test_empty_tree(self):
88
80
self.build_tree([])
93
85
[['a', 'a'], ['a', 'a']]])
95
def test_tree_ascii(self):
96
"""Checks the glob expansion and path separation char
87
def build_ascii_tree(self):
98
88
self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
99
89
'b', 'b1', 'b2', 'b3',
100
90
'c/', 'c/c1', 'c/c2',
101
91
'd/', 'd/d1', 'd/d2', 'd/e/', 'd/e/e1'])
93
def build_unicode_tree(self):
94
self.requireFeature(UnicodeFilenameFeature)
95
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/',
98
def test_tree_ascii(self):
99
"""Checks the glob expansion and path separation char
101
self.build_ascii_tree()
102
102
self._run_testset([
104
104
[[u'a'], [u'a']],
105
105
[[u'a', u'a' ], [u'a', u'a']],
108
107
[[u'd'], [u'd']],
109
108
[[u'd/'], [u'd/']],
113
111
[[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
115
113
[[u'a?'], [u'a1', u'a2']],
116
114
[[u'a??'], [u'a11', u'a.1']],
117
115
[[u'b[1-2]'], [u'b1', u'b2']],
118
[[u'A?'], [u'a1', u'a2']],
120
117
[[u'd/*'], [u'd/d1', u'd/d2', u'd/e']],
118
[[u'?/*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
119
[[u'*/*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
120
[[u'*/'], [u'c/', u'd/']],
123
def test_backslash_globbing(self):
124
self.requireFeature(BackslashDirSeparatorFeature)
125
self.build_ascii_tree()
121
128
[[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
122
129
[[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
123
130
[[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
124
[[u'*/'], [u'c/', u'd/']],
125
[[u'*\\'], [u'c/', u'd/']]])
131
[[u'*\\'], [u'c/', u'd/']],
134
def test_case_insensitive_globbing(self):
135
self.requireFeature(tests.CaseInsCasePresFilenameFeature)
136
self.build_ascii_tree()
139
[[u'A?'], [u'a1', u'a2']],
127
142
def test_tree_unicode(self):
128
143
"""Checks behaviour with non-ascii filenames"""
129
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
144
self.build_unicode_tree()
130
145
self._run_testset([
132
147
[[u'\u1234'], [u'\u1234']],
143
158
[[u'\u1235/?'], [u'\u1235/\u1235']],
144
159
[[u'\u1235/*'], [u'\u1235/\u1235']],
160
[[u'?/'], [u'\u1235/']],
161
[[u'*/'], [u'\u1235/']],
162
[[u'?/?'], [u'\u1235/\u1235']],
163
[[u'*/*'], [u'\u1235/\u1235']],
166
def test_unicode_backslashes(self):
167
self.requireFeature(BackslashDirSeparatorFeature)
168
self.build_unicode_tree()
171
[[u'\u1235\\'], [u'\u1235/']],
172
[[u'\u1235\\\u1235'], [u'\u1235/\u1235']],
145
173
[[u'\u1235\\?'], [u'\u1235/\u1235']],
146
174
[[u'\u1235\\*'], [u'\u1235/\u1235']],
147
[[u'?/'], [u'\u1235/']],
148
[[u'*/'], [u'\u1235/']],
149
175
[[u'?\\'], [u'\u1235/']],
150
176
[[u'*\\'], [u'\u1235/']],
151
[[u'?/?'], [u'\u1235/\u1235']],
152
[[u'*/*'], [u'\u1235/\u1235']],
153
177
[[u'?\\?'], [u'\u1235/\u1235']],
154
[[u'*\\*'], [u'\u1235/\u1235']]])
178
[[u'*\\*'], [u'\u1235/\u1235']],
156
181
def _run_testset(self, testset):
157
182
for pattern, expected in testset:
356
381
def test_no_single_quote_supported(self):
357
382
self.assertCommandLine(["add", "let's-do-it.txt"],
358
383
"add let's-do-it.txt")
385
def test_case_insensitive_globs(self):
386
self.requireFeature(tests.CaseInsCasePresFilenameFeature)
387
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
388
self.assertCommandLine([u'A/b.c'], 'A/B*')
390
def test_backslashes(self):
391
self.requireFeature(BackslashDirSeparatorFeature)
392
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
393
self.assertCommandLine([u'a/b.c'], 'a\\b*')