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
292
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
350
def assertCommandLine(self, expected, line):
294
def assertCommandLine(self, expected, line, single_quotes_allowed=False):
351
295
# Strictly speaking we should respect parameter order versus glob
352
296
# expansions, but it's not really worth the effort here
353
self.assertEqual(expected,
354
sorted(win32utils._command_line_to_argv(line)))
297
argv = win32utils._command_line_to_argv(line,
298
single_quotes_allowed=single_quotes_allowed)
299
self.assertEqual(expected, sorted(argv))
356
301
def test_glob_paths(self):
357
302
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
367
312
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
368
313
self.assertCommandLine([u'a/*.c'], '"a/*.c"')
369
314
self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
315
self.assertCommandLine([u'a/*.c'], "'a/*.c'",
316
single_quotes_allowed=True)
371
318
def test_slashes_changed(self):
372
319
# Quoting doesn't change the supplied args
373
320
self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
321
self.assertCommandLine([u'a\\*.c'], "'a\\*.c'",
322
single_quotes_allowed=True)
374
323
# Expands the glob, but nothing matches, swaps slashes
375
324
self.assertCommandLine([u'a/*.c'], 'a\\*.c')
376
325
self.assertCommandLine([u'a/?.c'], 'a\\?.c')
377
326
# No glob, doesn't touch slashes
378
327
self.assertCommandLine([u'a\\foo.c'], 'a\\foo.c')
380
def test_no_single_quote_supported(self):
329
def test_single_quote_support(self):
381
330
self.assertCommandLine(["add", "let's-do-it.txt"],
382
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)
384
335
def test_case_insensitive_globs(self):
385
336
self.requireFeature(tests.CaseInsCasePresFilenameFeature)