~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_win32utils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-17 13:49:11 UTC
  • mfrom: (4988.11.1 imports)
  • Revision ID: pqm@pqm.ubuntu.com-20100217134911-s77se00ni7xc1hz8
(Jelmer) Remove some unused imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
288
288
 
289
289
 
290
290
 
 
291
class TestUnicodeShlex(tests.TestCase):
 
292
 
 
293
    def assertAsTokens(self, expected, line):
 
294
        s = win32utils.UnicodeShlex(line)
 
295
        self.assertEqual(expected, list(s))
 
296
 
 
297
    def test_simple(self):
 
298
        self.assertAsTokens([(False, u'foo'), (False, u'bar'), (False, u'baz')],
 
299
                            u'foo bar baz')
 
300
 
 
301
    def test_ignore_multiple_spaces(self):
 
302
        self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo  bar')
 
303
 
 
304
    def test_ignore_leading_space(self):
 
305
        self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'  foo bar')
 
306
 
 
307
    def test_ignore_trailing_space(self):
 
308
        self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar  ')
 
309
 
 
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'")],
 
313
            u"'fo''o 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")],
 
316
            u'"fo"\'o b\'"ar"')
 
317
 
 
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\"")
 
321
 
 
322
    def test_empty_result(self):
 
323
        self.assertAsTokens([], u'')
 
324
        self.assertAsTokens([], u'    ')
 
325
 
 
326
    def test_quoted_empty(self):
 
327
        self.assertAsTokens([(True, '')], u'""')
 
328
        self.assertAsTokens([(False, u"''")], u"''")
 
329
 
 
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')
 
333
 
 
334
    def test_newline_in_quoted_section(self):
 
335
        self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u'"foo\nbar\nbaz\n"')
 
336
 
 
337
    def test_escape_chars(self):
 
338
        self.assertAsTokens([(False, u'foo\\bar')], u'foo\\bar')
 
339
 
 
340
    def test_escape_quote(self):
 
341
        self.assertAsTokens([(True, u'foo"bar')], u'"foo\\"bar"')
 
342
 
 
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")
 
346
 
291
347
 
292
348
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
293
349
 
294
 
    def assertCommandLine(self, expected, line, single_quotes_allowed=False):
 
350
    def assertCommandLine(self, expected, line):
295
351
        # Strictly speaking we should respect parameter order versus glob
296
352
        # 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))
 
353
        self.assertEqual(expected,
 
354
                         sorted(win32utils._command_line_to_argv(line)))
300
355
 
301
356
    def test_glob_paths(self):
302
357
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
312
367
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
313
368
        self.assertCommandLine([u'a/*.c'], '"a/*.c"')
314
369
        self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
315
 
        self.assertCommandLine([u'a/*.c'], "'a/*.c'",
316
 
            single_quotes_allowed=True)
317
370
 
318
371
    def test_slashes_changed(self):
319
372
        # Quoting doesn't change the supplied args
320
373
        self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
321
 
        self.assertCommandLine([u'a\\*.c'], "'a\\*.c'",
322
 
            single_quotes_allowed=True)
323
374
        # Expands the glob, but nothing matches, swaps slashes
324
375
        self.assertCommandLine([u'a/*.c'], 'a\\*.c')
325
376
        self.assertCommandLine([u'a/?.c'], 'a\\?.c')
326
377
        # No glob, doesn't touch slashes
327
378
        self.assertCommandLine([u'a\\foo.c'], 'a\\foo.c')
328
379
 
329
 
    def test_single_quote_support(self):
 
380
    def test_no_single_quote_supported(self):
330
381
        self.assertCommandLine(["add", "let's-do-it.txt"],
331
382
            "add let's-do-it.txt")
332
 
        self.assertCommandLine(["add", "lets do it.txt"],
333
 
            "add 'lets do it.txt'", single_quotes_allowed=True)
334
383
 
335
384
    def test_case_insensitive_globs(self):
336
385
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)