85
90
[['a', 'a'], ['a', 'a']]])
87
def build_ascii_tree(self):
92
def test_tree_ascii(self):
93
"""Checks the glob expansion and path separation char
88
95
self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
89
96
'b', 'b1', 'b2', 'b3',
90
97
'c/', 'c/c1', 'c/c2',
91
98
'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
99
self._run_testset([
104
101
[[u'a'], [u'a']],
105
102
[[u'a', u'a' ], [u'a', u'a']],
107
105
[[u'd'], [u'd']],
108
106
[[u'd/'], [u'd/']],
111
110
[[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
113
112
[[u'a?'], [u'a1', u'a2']],
114
113
[[u'a??'], [u'a11', u'a.1']],
115
114
[[u'b[1-2]'], [u'b1', u'b2']],
115
[[u'A?'], [u'a1', u'a2']],
117
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()
128
118
[[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
129
119
[[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
130
120
[[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
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']],
121
[[u'*/'], [u'c/', u'd/']],
122
[[u'*\\'], [u'c/', u'd/']]])
142
124
def test_tree_unicode(self):
143
125
"""Checks behaviour with non-ascii filenames"""
144
self.build_unicode_tree()
126
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
145
127
self._run_testset([
147
129
[[u'\u1234'], [u'\u1234']],
158
140
[[u'\u1235/?'], [u'\u1235/\u1235']],
159
141
[[u'\u1235/*'], [u'\u1235/\u1235']],
142
[[u'\u1235\\?'], [u'\u1235/\u1235']],
143
[[u'\u1235\\*'], [u'\u1235/\u1235']],
160
144
[[u'?/'], [u'\u1235/']],
161
145
[[u'*/'], [u'\u1235/']],
146
[[u'?\\'], [u'\u1235/']],
147
[[u'*\\'], [u'\u1235/']],
162
148
[[u'?/?'], [u'\u1235/\u1235']],
163
149
[[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']],
173
[[u'\u1235\\?'], [u'\u1235/\u1235']],
174
[[u'\u1235\\*'], [u'\u1235/\u1235']],
175
[[u'?\\'], [u'\u1235/']],
176
[[u'*\\'], [u'\u1235/']],
177
150
[[u'?\\?'], [u'\u1235/\u1235']],
178
[[u'*\\*'], [u'\u1235/\u1235']],
151
[[u'*\\*'], [u'\u1235/\u1235']]])
181
153
def _run_testset(self, testset):
182
154
for pattern, expected in testset:
285
261
os.makedirs(u'\u1234\\.bzr')
286
262
path = osutils.abspath(u'\u1234\\.bzr')
287
263
win32utils.set_file_attr_hidden(path)
291
class TestUnicodeShlex(tests.TestCase):
293
def assertAsTokens(self, expected, line):
294
s = win32utils.UnicodeShlex(line)
295
self.assertEqual(expected, list(s))
297
def test_simple(self):
298
self.assertAsTokens([(False, u'foo'), (False, u'bar'), (False, u'baz')],
301
def test_ignore_multiple_spaces(self):
302
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar')
304
def test_ignore_leading_space(self):
305
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u' foo bar')
307
def test_ignore_trailing_space(self):
308
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar ')
310
def test_posix_quotations(self):
311
self.assertAsTokens([(True, u'foo bar')], u'"foo bar"')
312
self.assertAsTokens([(False, u"'fo''o"), (False, u"b''ar'")],
314
self.assertAsTokens([(True, u'foo bar')], u'"fo""o b""ar"')
315
self.assertAsTokens([(True, u"fo'o"), (True, u"b'ar")],
318
def test_nested_quotations(self):
319
self.assertAsTokens([(True, u'foo"" bar')], u"\"foo\\\"\\\" bar\"")
320
self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"")
322
def test_empty_result(self):
323
self.assertAsTokens([], u'')
324
self.assertAsTokens([], u' ')
326
def test_quoted_empty(self):
327
self.assertAsTokens([(True, '')], u'""')
328
self.assertAsTokens([(False, u"''")], u"''")
330
def test_unicode_chars(self):
331
self.assertAsTokens([(False, u'f\xb5\xee'), (False, u'\u1234\u3456')],
332
u'f\xb5\xee \u1234\u3456')
334
def test_newline_in_quoted_section(self):
335
self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u'"foo\nbar\nbaz\n"')
337
def test_escape_chars(self):
338
self.assertAsTokens([(False, u'foo\\bar')], u'foo\\bar')
340
def test_escape_quote(self):
341
self.assertAsTokens([(True, u'foo"bar')], u'"foo\\"bar"')
343
def test_double_escape(self):
344
self.assertAsTokens([(True, u'foo\\bar')], u'"foo\\\\bar"')
345
self.assertAsTokens([(False, u'foo\\\\bar')], u"foo\\\\bar")
348
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
350
def assertCommandLine(self, expected, line):
351
# Strictly speaking we should respect parameter order versus glob
352
# expansions, but it's not really worth the effort here
353
self.assertEqual(expected,
354
sorted(win32utils._command_line_to_argv(line)))
356
def test_glob_paths(self):
357
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
358
self.assertCommandLine([u'a/b.c', u'a/c.c'], 'a/*.c')
359
self.build_tree(['b/', 'b/b.c', 'b/d.c', 'b/d.h'])
360
self.assertCommandLine([u'a/b.c', u'b/b.c'], '*/b.c')
361
self.assertCommandLine([u'a/b.c', u'a/c.c', u'b/b.c', u'b/d.c'],
363
# Bash style, just pass through the argument if nothing matches
364
self.assertCommandLine([u'*/*.qqq'], '*/*.qqq')
366
def test_quoted_globs(self):
367
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
368
self.assertCommandLine([u'a/*.c'], '"a/*.c"')
369
self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
371
def test_slashes_changed(self):
372
# Quoting doesn't change the supplied args
373
self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
374
# Expands the glob, but nothing matches, swaps slashes
375
self.assertCommandLine([u'a/*.c'], 'a\\*.c')
376
self.assertCommandLine([u'a/?.c'], 'a\\?.c')
377
# No glob, doesn't touch slashes
378
self.assertCommandLine([u'a\\foo.c'], 'a\\foo.c')
380
def test_no_single_quote_supported(self):
381
self.assertCommandLine(["add", "let's-do-it.txt"],
382
"add let's-do-it.txt")
384
def test_case_insensitive_globs(self):
385
self.requireFeature(tests.CaseInsCasePresFilenameFeature)
386
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
387
self.assertCommandLine([u'A/b.c'], 'A/B*')
389
def test_backslashes(self):
390
self.requireFeature(BackslashDirSeparatorFeature)
391
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
392
self.assertCommandLine([u'a/b.c'], 'a\\b*')