85
93
[['a', 'a'], ['a', 'a']]])
87
def build_ascii_tree(self):
95
def test_tree_ascii(self):
96
"""Checks the glob expansion and path separation char
88
98
self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
89
99
'b', 'b1', 'b2', 'b3',
90
100
'c/', 'c/c1', 'c/c2',
91
101
'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']],
107
108
[[u'd'], [u'd']],
108
109
[[u'd/'], [u'd/']],
111
113
[[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
113
115
[[u'a?'], [u'a1', u'a2']],
114
116
[[u'a??'], [u'a11', u'a.1']],
115
117
[[u'b[1-2]'], [u'b1', u'b2']],
118
[[u'A?'], [u'a1', u'a2']],
117
120
[[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
121
[[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
129
122
[[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
130
123
[[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']],
124
[[u'*/'], [u'c/', u'd/']],
125
[[u'*\\'], [u'c/', u'd/']]])
142
127
def test_tree_unicode(self):
143
128
"""Checks behaviour with non-ascii filenames"""
144
self.build_unicode_tree()
129
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
145
130
self._run_testset([
147
132
[[u'\u1234'], [u'\u1234']],
158
143
[[u'\u1235/?'], [u'\u1235/\u1235']],
159
144
[[u'\u1235/*'], [u'\u1235/\u1235']],
145
[[u'\u1235\\?'], [u'\u1235/\u1235']],
146
[[u'\u1235\\*'], [u'\u1235/\u1235']],
160
147
[[u'?/'], [u'\u1235/']],
161
148
[[u'*/'], [u'\u1235/']],
149
[[u'?\\'], [u'\u1235/']],
150
[[u'*\\'], [u'\u1235/']],
162
151
[[u'?/?'], [u'\u1235/\u1235']],
163
152
[[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
153
[[u'?\\?'], [u'\u1235/\u1235']],
178
[[u'*\\*'], [u'\u1235/\u1235']],
154
[[u'*\\*'], [u'\u1235/\u1235']]])
181
156
def _run_testset(self, testset):
182
157
for pattern, expected in testset:
270
class TestUnicodeShlex(tests.TestCase):
272
def assertAsTokens(self, expected, line):
273
s = win32utils.UnicodeShlex(line)
274
self.assertEqual(expected, list(s))
276
def test_simple(self):
277
self.assertAsTokens([(False, u'foo'), (False, u'bar'), (False, u'baz')],
280
def test_ignore_multiple_spaces(self):
281
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar')
283
def test_ignore_leading_space(self):
284
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u' foo bar')
286
def test_ignore_trailing_space(self):
287
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar ')
289
def test_posix_quotations(self):
290
self.assertAsTokens([(True, u'foo bar')], u'"foo bar"')
291
self.assertAsTokens([(True, u'foo bar')], u"'foo bar'")
292
self.assertAsTokens([(True, u'foo bar')], u"'fo''o b''ar'")
293
self.assertAsTokens([(True, u'foo bar')], u'"fo""o b""ar"')
294
self.assertAsTokens([(True, u'foo bar')], u'"fo"\'o b\'"ar"')
296
def test_nested_quotations(self):
297
self.assertAsTokens([(True, u'foo"" bar')], u"'foo\"\" bar'")
298
self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"")
300
def test_empty_result(self):
301
self.assertAsTokens([], u'')
302
self.assertAsTokens([], u' ')
304
def test_quoted_empty(self):
305
self.assertAsTokens([(True, '')], u'""')
306
self.assertAsTokens([(True, '')], u"''")
308
def test_unicode_chars(self):
309
self.assertAsTokens([(False, u'f\xb5\xee'), (False, u'\u1234\u3456')],
310
u'f\xb5\xee \u1234\u3456')
312
def test_newline_in_quoted_section(self):
313
self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u'"foo\nbar\nbaz\n"')
314
self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u"'foo\nbar\nbaz\n'")
316
def test_escape_chars(self):
317
self.assertAsTokens([(False, u'foo\\bar')], u'foo\\bar')
319
def test_escape_quote(self):
320
self.assertAsTokens([(True, u'foo"bar')], u'"foo\\"bar"')
321
self.assertAsTokens([(True, u'foo\\"bar')], u"'foo\\\"bar'")
323
def test_double_escape(self):
324
self.assertAsTokens([(True, u'foo\\bar')], u'"foo\\\\bar"')
325
self.assertAsTokens([(True, u'foo\\\\bar')], u"'foo\\\\bar'")
326
self.assertAsTokens([(False, u'foo\\\\bar')], u"foo\\\\bar")
292
329
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
294
def assertCommandLine(self, expected, line, single_quotes_allowed=False):
295
# Strictly speaking we should respect parameter order versus glob
296
# expansions, but it's not really worth the effort here
297
argv = win32utils._command_line_to_argv(line,
298
single_quotes_allowed=single_quotes_allowed)
299
self.assertEqual(expected, sorted(argv))
331
def assertCommandLine(self, expected, line):
332
self.assertEqual(expected, win32utils._command_line_to_argv(line))
301
334
def test_glob_paths(self):
302
335
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
311
344
def test_quoted_globs(self):
312
345
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
313
346
self.assertCommandLine([u'a/*.c'], '"a/*.c"')
314
self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
315
self.assertCommandLine([u'a/*.c'], "'a/*.c'",
316
single_quotes_allowed=True)
347
self.assertCommandLine([u'a/*.c'], "'a/*.c'")
318
349
def test_slashes_changed(self):
319
# Quoting doesn't change the supplied args
320
self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
321
self.assertCommandLine([u'a\\*.c'], "'a\\*.c'",
322
single_quotes_allowed=True)
323
# Expands the glob, but nothing matches, swaps slashes
350
self.assertCommandLine([u'a/*.c'], '"a\\*.c"')
351
# Expands the glob, but nothing matches
324
352
self.assertCommandLine([u'a/*.c'], 'a\\*.c')
325
self.assertCommandLine([u'a/?.c'], 'a\\?.c')
326
# No glob, doesn't touch slashes
327
self.assertCommandLine([u'a\\foo.c'], 'a\\foo.c')
329
def test_single_quote_support(self):
330
self.assertCommandLine(["add", "let's-do-it.txt"],
331
"add let's-do-it.txt")
332
self.assertCommandLine(["add", "lets do it.txt"],
333
"add 'lets do it.txt'", single_quotes_allowed=True)
335
def test_case_insensitive_globs(self):
336
self.requireFeature(tests.CaseInsCasePresFilenameFeature)
337
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
338
self.assertCommandLine([u'A/b.c'], 'A/B*')
340
def test_backslashes(self):
341
self.requireFeature(BackslashDirSeparatorFeature)
342
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
343
self.assertCommandLine([u'a/b.c'], 'a\\b*')
353
self.assertCommandLine([u'a/foo.c'], 'a\\foo.c')