/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_win32utils.py

  • Committer: Gordon Tyler
  • Date: 2010-01-14 04:56:20 UTC
  • mto: (5037.3.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5046.
  • Revision ID: gordon@doxxx.net-20100114045620-lhl4en5s8jityyt8
Added optional single quote support to UnicodeShlex and thus command_line_to_argv (defaults to disabled).

- Fixed unnecessary win32 platform checks in tests.
- Added extra tests for single quote support in UnicodeShlex.
- Changed commands.shlex_split_unicode to allow single quotes on win32 for better cross-platform compatibility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
293
293
 
294
294
class TestUnicodeShlex(tests.TestCase):
295
295
 
296
 
    def assertAsTokens(self, expected, line):
297
 
        s = win32utils.UnicodeShlex(line)
 
296
    def assertAsTokens(self, expected, line, single_quotes_allowed=False):
 
297
        s = win32utils.UnicodeShlex(line,
 
298
                                    single_quotes_allowed=single_quotes_allowed)
298
299
        self.assertEqual(expected, list(s))
299
300
 
300
301
    def test_simple(self):
313
314
    def test_nested_quotations(self):
314
315
        self.assertAsTokens([(True, u'foo"" bar')], u"\"foo\\\"\\\" bar\"")
315
316
        self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"")
 
317
        self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"",
 
318
            single_quotes_allowed=True)
 
319
        self.assertAsTokens([(True, u'foo"" bar')], u"'foo\"\" bar'",
 
320
            single_quotes_allowed=True)
316
321
 
317
322
    def test_empty_result(self):
318
323
        self.assertAsTokens([], u'')
321
326
    def test_quoted_empty(self):
322
327
        self.assertAsTokens([(True, '')], u'""')
323
328
        self.assertAsTokens([(False, u"''")], u"''")
 
329
        self.assertAsTokens([(True, '')], u"''", single_quotes_allowed=True)
324
330
 
325
331
    def test_unicode_chars(self):
326
332
        self.assertAsTokens([(False, u'f\xb5\xee'), (False, u'\u1234\u3456')],
328
334
 
329
335
    def test_newline_in_quoted_section(self):
330
336
        self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u'"foo\nbar\nbaz\n"')
 
337
        self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u"'foo\nbar\nbaz\n'",
 
338
            single_quotes_allowed=True)
331
339
 
332
340
    def test_escape_chars(self):
333
341
        self.assertAsTokens([(False, u'foo\\bar')], u'foo\\bar')
344
352
    def test_multiple_quoted_args(self):
345
353
        self.assertAsTokens([(True, u'x x'), (True, u'y y')],
346
354
            u'"x x" "y y"')
 
355
        self.assertAsTokens([(True, u'x x'), (True, u'y y')],
 
356
            u'"x x" \'y y\'', single_quotes_allowed=True)
347
357
 
348
358
 
349
359
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
350
360
 
351
 
    def assertCommandLine(self, expected, line):
 
361
    def assertCommandLine(self, expected, line, single_quotes_allowed=False):
352
362
        # Strictly speaking we should respect parameter order versus glob
353
363
        # expansions, but it's not really worth the effort here
354
 
        self.assertEqual(expected,
355
 
                         sorted(win32utils.command_line_to_argv(line)))
 
364
        argv = win32utils.command_line_to_argv(line,
 
365
                single_quotes_allowed=single_quotes_allowed)
 
366
        self.assertEqual(expected, sorted(argv))
356
367
 
357
368
    def test_glob_paths(self):
358
369
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
368
379
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
369
380
        self.assertCommandLine([u'a/*.c'], '"a/*.c"')
370
381
        self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
 
382
        self.assertCommandLine([u'a/*.c'], "'a/*.c'",
 
383
            single_quotes_allowed=True)
371
384
 
372
385
    def test_slashes_changed(self):
373
386
        # Quoting doesn't change the supplied args
374
387
        self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
 
388
        self.assertCommandLine([u'a\\*.c'], "'a\\*.c'",
 
389
            single_quotes_allowed=True)
375
390
        # Expands the glob, but nothing matches, swaps slashes
376
391
        self.assertCommandLine([u'a/*.c'], 'a\\*.c')
377
392
        self.assertCommandLine([u'a/?.c'], 'a\\?.c')
378
393
        # No glob, doesn't touch slashes
379
394
        self.assertCommandLine([u'a\\foo.c'], 'a\\foo.c')
380
395
 
381
 
    def test_no_single_quote_supported(self):
 
396
    def test_single_quote_support(self):
382
397
        self.assertCommandLine(["add", "let's-do-it.txt"],
383
398
            "add let's-do-it.txt")
 
399
        self.assertCommandLine(["add", "lets do it.txt"],
 
400
            "add 'lets do it.txt'", single_quotes_allowed=True)
384
401
 
385
402
    def test_case_insensitive_globs(self):
386
403
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)