261
264
os.makedirs(u'\u1234\\.bzr')
262
265
path = osutils.abspath(u'\u1234\\.bzr')
263
266
win32utils.set_file_attr_hidden(path)
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")
329
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
331
def assertCommandLine(self, expected, line):
332
self.assertEqual(expected, win32utils._command_line_to_argv(line))
334
def test_glob_paths(self):
335
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
336
self.assertCommandLine([u'a/b.c', u'a/c.c'], 'a/*.c')
337
self.build_tree(['b/', 'b/b.c', 'b/d.c', 'b/d.h'])
338
self.assertCommandLine([u'a/b.c', u'b/b.c'], '*/b.c')
339
self.assertCommandLine([u'a/b.c', u'a/c.c', u'b/b.c', u'b/d.c'],
341
# Bash style, just pass through the argument if nothing matches
342
self.assertCommandLine([u'*/*.qqq'], '*/*.qqq')
344
def test_quoted_globs(self):
345
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
346
self.assertCommandLine([u'a/*.c'], '"a/*.c"')
347
self.assertCommandLine([u'a/*.c'], "'a/*.c'")
349
def test_slashes_changed(self):
350
self.assertCommandLine([u'a/*.c'], '"a\\*.c"')
351
# Expands the glob, but nothing matches
352
self.assertCommandLine([u'a/*.c'], 'a\\*.c')
353
self.assertCommandLine([u'a/foo.c'], 'a\\foo.c')