|
3 | 3 | import sys |
4 | 4 | import unittest |
5 | 5 | from unittest import mock |
6 | | -from test.support import requires |
| 6 | +from test.support import requires, subTests |
7 | 7 | from test.support.isolation import runInSubprocess |
8 | 8 | import tkinter |
9 | 9 | from tkinter import EventType |
@@ -163,5 +163,38 @@ def test_fix_x11_paste(self): |
163 | 163 | self.assertEqual(after, before[cls]) |
164 | 164 |
|
165 | 165 |
|
| 166 | +class CLIargsTest(unittest.TestCase): |
| 167 | + "Test the command line splitting and joining functions (gh-93016)." |
| 168 | + |
| 169 | + # Expected results were verified against sys.argv of python.exe. |
| 170 | + @subTests('cli_string,args', [ |
| 171 | + (r'c:\Users', [r'c:\Users']), |
| 172 | + (r'\\server\share', [r'\\server\share']), |
| 173 | + (r'"c:\Program Files\x" 1 2', [r'c:\Program Files\x', '1', '2']), |
| 174 | + (r' x y ', ['x', 'y']), |
| 175 | + ('a\tb', ['a', 'b']), |
| 176 | + (r'"a b"c', ['a bc']), |
| 177 | + (r'a"b c"d', ['ab cd']), |
| 178 | + (r'"a""b"', ['a"b']), |
| 179 | + (r'a\"b', ['a"b']), |
| 180 | + (r'a\\"b c" d', ['a\\b c', 'd']), |
| 181 | + (r'a\\\"b', ['a\\"b']), |
| 182 | + (r'"x\\"', ['x\\']), |
| 183 | + ('"c:\\Users\\"', ['c:\\Users"']), |
| 184 | + ('x\\', ['x\\']), |
| 185 | + (r'""', ['']), |
| 186 | + (r'"" a', ['', 'a']), |
| 187 | + (r'"', ['']), |
| 188 | + ('', []), |
| 189 | + ]) |
| 190 | + def test_split_windows(self, cli_string, args): |
| 191 | + self.assertEqual(util._split_windows(cli_string), args) |
| 192 | + |
| 193 | + @subTests('args', [['a'], ['a b'], [r'c:\x'], ['q"q'], ["s's"], [''], |
| 194 | + ['\\'], ['\\"'], ['a b', r'c:\x', '', 'q"q']]) |
| 195 | + def test_split_join(self, args): |
| 196 | + self.assertEqual(util.split_cli_args(util.join_cli_args(args)), args) |
| 197 | + |
| 198 | + |
166 | 199 | if __name__ == '__main__': |
167 | 200 | unittest.main(verbosity=2) |
0 commit comments