Source

winpexpect / lib / test / test_cmdline.py

#
# This file is part of WinPexpect. WinPexpect is free software that is made
# available under the MIT license. Consult the file "LICENSE" that is
# distributed together with this file for the exact licensing terms.
#
# WinPexpect is copyright (c) 2008-2010 by the WinPexpect authors. See the
# file "AUTHORS" for a complete overview.

import os
from winpexpect import split_command_line, join_command_line

from nose.tools import assert_raises


class TestCommandLine(object):

    split_ok = [
        ('a b c', ['a', 'b', 'c']),
        ('"a b c" d e', ['a b c', 'd', 'e']),
        (r'"ab\"c" "\\" d', ['ab"c', '\\', 'd']),
        (r'a\\\b d"e f"g h', [r'a\\\b', 'de fg', 'h']),
        (r'a\\\"b c d', [r'a\"b', 'c', 'd']),
        (r'a\\\\"b c" d e', [r'a\\b c', 'd', 'e']),
        ('""', ['']),
        ('"" ""', ['', '']),
        (' ', []),
        ('  ', []),
        (' a', ['a']),
        ('a ', ['a']),
        (' a ', ['a']),
        ('"  a"', ['  a'])
    ]

    split_error = [
        '"a',
        'a"b',
        '"'
    ]

    def test_split(self):
        for s,ref in self.split_ok:
            assert split_command_line(s) == ref

    def test_split_error(self):
        for s in self.split_error:
            assert_raises(ValueError, split_command_line, s)

    join_ok = [
        (['a'], 'a'),
        (['a', 'b'], 'a b'),
        (['a b'], '"a b"'),
#        (['a|b'], '"a|b"'),
        (['a"b'], r'a\"b'),
        ([r'a\b'], r'a\b'),
        ([r'a\"b'], r'a\\\"b'),
        ([r'"a\"b"'], r'\"a\\\"b\"'),
        ([r'"a\" b"'], r'"\"a\\\" b\""')
    ]

    def test_join(self):
        for l,ref in self.join_ok:
            assert join_command_line(l) == ref
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.