bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5037.3.2
by Martin Pool
Fix up test_cmdline to actually work |
1 |
# Copyright (C) 2010 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
||
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
18 |
from .. import ( |
5037.3.2
by Martin Pool
Fix up test_cmdline to actually work |
19 |
cmdline, |
5241.2.1
by Robert Collins
Merge up from 2.0/2.1: |
20 |
tests, |
21 |
)
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
22 |
from .features import backslashdir_feature |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
23 |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
24 |
|
4913.5.23
by Gordon Tyler
Renamed cmdline.Parser to Splitter to better match its usage. |
25 |
class TestSplitter(tests.TestCase): |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
26 |
|
27 |
def assertAsTokens(self, expected, line, single_quotes_allowed=False): |
|
4913.5.23
by Gordon Tyler
Renamed cmdline.Parser to Splitter to better match its usage. |
28 |
s = cmdline.Splitter(line, single_quotes_allowed=single_quotes_allowed) |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
29 |
self.assertEqual(expected, list(s)) |
30 |
||
31 |
def test_simple(self): |
|
32 |
self.assertAsTokens([(False, u'foo'), (False, u'bar'), (False, u'baz')], |
|
33 |
u'foo bar baz') |
|
34 |
||
35 |
def test_ignore_multiple_spaces(self): |
|
36 |
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar') |
|
37 |
||
38 |
def test_ignore_leading_space(self): |
|
39 |
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u' foo bar') |
|
40 |
||
41 |
def test_ignore_trailing_space(self): |
|
42 |
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar ') |
|
43 |
||
44 |
def test_posix_quotations(self): |
|
45 |
self.assertAsTokens([(True, u'foo bar')], u"'foo bar'", |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
46 |
single_quotes_allowed=True) |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
47 |
self.assertAsTokens([(True, u'foo bar')], u"'fo''o b''ar'", |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
48 |
single_quotes_allowed=True) |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
49 |
self.assertAsTokens([(True, u'foo bar')], u'"fo""o b""ar"', |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
50 |
single_quotes_allowed=True) |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
51 |
self.assertAsTokens([(True, u'foo bar')], u'"fo"\'o b\'"ar"', |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
52 |
single_quotes_allowed=True) |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
53 |
|
54 |
def test_nested_quotations(self): |
|
55 |
self.assertAsTokens([(True, u'foo"" bar')], u"\"foo\\\"\\\" bar\"") |
|
56 |
self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"") |
|
57 |
self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"", |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
58 |
single_quotes_allowed=True) |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
59 |
self.assertAsTokens([(True, u'foo"" bar')], u"'foo\"\" bar'", |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
60 |
single_quotes_allowed=True) |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
61 |
|
62 |
def test_empty_result(self): |
|
63 |
self.assertAsTokens([], u'') |
|
64 |
self.assertAsTokens([], u' ') |
|
65 |
||
66 |
def test_quoted_empty(self): |
|
67 |
self.assertAsTokens([(True, '')], u'""') |
|
68 |
self.assertAsTokens([(False, u"''")], u"''") |
|
69 |
self.assertAsTokens([(True, '')], u"''", single_quotes_allowed=True) |
|
6571.2.1
by Ross Lagerwall
Handle empty quoted strings in command lines |
70 |
self.assertAsTokens([(False, u'a'), (True, u''), (False, u'c')], |
71 |
u'a "" c') |
|
72 |
self.assertAsTokens([(False, u'a'), (True, u''), (False, u'c')], |
|
73 |
u"a '' c", single_quotes_allowed=True) |
|
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
74 |
|
75 |
def test_unicode_chars(self): |
|
76 |
self.assertAsTokens([(False, u'f\xb5\xee'), (False, u'\u1234\u3456')], |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
77 |
u'f\xb5\xee \u1234\u3456') |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
78 |
|
79 |
def test_newline_in_quoted_section(self): |
|
80 |
self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u'"foo\nbar\nbaz\n"') |
|
81 |
self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u"'foo\nbar\nbaz\n'", |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
82 |
single_quotes_allowed=True) |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
83 |
|
84 |
def test_escape_chars(self): |
|
85 |
self.assertAsTokens([(False, u'foo\\bar')], u'foo\\bar') |
|
86 |
||
87 |
def test_escape_quote(self): |
|
88 |
self.assertAsTokens([(True, u'foo"bar')], u'"foo\\"bar"') |
|
89 |
self.assertAsTokens([(True, u'foo\\"bar')], u'"foo\\\\\\"bar"') |
|
90 |
self.assertAsTokens([(True, u'foo\\bar')], u'"foo\\\\"bar"') |
|
91 |
||
92 |
def test_double_escape(self): |
|
93 |
self.assertAsTokens([(True, u'foo\\\\bar')], u'"foo\\\\bar"') |
|
94 |
self.assertAsTokens([(False, u'foo\\\\bar')], u"foo\\\\bar") |
|
5050.1.3
by Vincent Ladeuil
Delete spurious spaces. |
95 |
|
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
96 |
def test_multiple_quoted_args(self): |
97 |
self.assertAsTokens([(True, u'x x'), (True, u'y y')], |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
98 |
u'"x x" "y y"') |
4913.5.20
by Gordon Tyler
Fixed end-of-lines in test_cmdline.py. |
99 |
self.assertAsTokens([(True, u'x x'), (True, u'y y')], |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
100 |
u'"x x" \'y y\'', single_quotes_allowed=True) |
5241.2.1
by Robert Collins
Merge up from 2.0/2.1: |
101 |
|
102 |
def test_n_backslashes_handling(self): |
|
103 |
# https://bugs.launchpad.net/bzr/+bug/528944
|
|
104 |
# actually we care about the doubled backslashes when they're
|
|
105 |
# represents UNC paths.
|
|
106 |
# But in fact there is too much weird corner cases
|
|
107 |
# (see https://bugs.launchpad.net/tortoisebzr/+bug/569050)
|
|
108 |
# so to reproduce every bit of windows command-line handling
|
|
109 |
# could be not worth of efforts?
|
|
110 |
self.requireFeature(backslashdir_feature) |
|
111 |
self.assertAsTokens([(True, r'\\host\path')], r'"\\host\path"') |
|
112 |
self.assertAsTokens([(False, r'\\host\path')], r'\\host\path') |
|
113 |
# handling of " after the 2n and 2n+1 backslashes
|
|
114 |
# inside and outside the quoted string
|
|
115 |
self.assertAsTokens([(True, r'\\'), (False, r'*.py')], r'"\\\\" *.py') |
|
116 |
self.assertAsTokens([(True, r'\\" *.py')], r'"\\\\\" *.py"') |
|
117 |
self.assertAsTokens([(True, r'\\ *.py')], r'\\\\" *.py"') |
|
118 |
self.assertAsTokens([(False, r'\\"'), (False, r'*.py')], |
|
119 |
r'\\\\\" *.py') |
|
120 |
self.assertAsTokens([(True, u'\\\\')], u'"\\\\') |