287
287
win32utils.set_file_attr_hidden(path)
290
class TestUnicodeShlex(tests.TestCase):
292
def assertAsTokens(self, expected, line, single_quotes_allowed=False):
293
s = win32utils.UnicodeShlex(line,
294
single_quotes_allowed=single_quotes_allowed)
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
single_quotes_allowed=True)
313
self.assertAsTokens([(True, u'foo bar')], u"'fo''o b''ar'",
314
single_quotes_allowed=True)
315
self.assertAsTokens([(True, u'foo bar')], u'"fo""o b""ar"',
316
single_quotes_allowed=True)
317
self.assertAsTokens([(True, u'foo bar')], u'"fo"\'o b\'"ar"',
318
single_quotes_allowed=True)
320
def test_nested_quotations(self):
321
self.assertAsTokens([(True, u'foo"" bar')], u"\"foo\\\"\\\" bar\"")
322
self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"")
323
self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"",
324
single_quotes_allowed=True)
325
self.assertAsTokens([(True, u'foo"" bar')], u"'foo\"\" bar'",
326
single_quotes_allowed=True)
328
def test_empty_result(self):
329
self.assertAsTokens([], u'')
330
self.assertAsTokens([], u' ')
332
def test_quoted_empty(self):
333
self.assertAsTokens([(True, '')], u'""')
334
self.assertAsTokens([(False, u"''")], u"''")
335
self.assertAsTokens([(True, '')], u"''", single_quotes_allowed=True)
337
def test_unicode_chars(self):
338
self.assertAsTokens([(False, u'f\xb5\xee'), (False, u'\u1234\u3456')],
339
u'f\xb5\xee \u1234\u3456')
341
def test_newline_in_quoted_section(self):
342
self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u'"foo\nbar\nbaz\n"')
343
self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u"'foo\nbar\nbaz\n'",
344
single_quotes_allowed=True)
346
def test_escape_chars(self):
347
self.assertAsTokens([(False, u'foo\\bar')], u'foo\\bar')
349
def test_escape_quote(self):
350
self.assertAsTokens([(True, u'foo"bar')], u'"foo\\"bar"')
351
self.assertAsTokens([(True, u'foo\\"bar')], u'"foo\\\\\\"bar"')
352
self.assertAsTokens([(True, u'foo\\bar')], u'"foo\\\\"bar"')
354
def test_double_escape(self):
355
self.assertAsTokens([(True, u'foo\\\\bar')], u'"foo\\\\bar"')
356
self.assertAsTokens([(False, u'foo\\\\bar')], u"foo\\\\bar")
358
def test_multiple_quoted_args(self):
359
self.assertAsTokens([(True, u'x x'), (True, u'y y')],
361
self.assertAsTokens([(True, u'x x'), (True, u'y y')],
362
u'"x x" \'y y\'', single_quotes_allowed=True)
365
292
class Test_CommandLineToArgv(tests.TestCaseInTempDir):