summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-07-11 17:34:47 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-07-11 17:34:47 (GMT)
commit275d5fdbe40e172ab2bc99084178cb5f81334a54 (patch)
tree06df6649374c0982d53b4811b1d63e111357ae92 /Lib/test
parent5a33f813483325ab3e13596814c3eade6e0bb518 (diff)
downloadcpython-275d5fdbe40e172ab2bc99084178cb5f81334a54.zip
cpython-275d5fdbe40e172ab2bc99084178cb5f81334a54.tar.gz
cpython-275d5fdbe40e172ab2bc99084178cb5f81334a54.tar.bz2
Issue #18101: Tcl.split() now process strings nested in a tuple as it
do with byte strings. Added tests for Tcl.split() and Tcl.splitline().
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_tcl.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
index 0cc21c9..a5aaf9b 100644
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -175,6 +175,66 @@ class TclTest(unittest.TestCase):
self.assertEqual(passValue(f), f)
self.assertEqual(passValue((1, '2', (3.4,))), (1, '2', (3.4,)))
+ def test_splitlist(self):
+ splitlist = self.interp.tk.splitlist
+ call = self.interp.tk.call
+ self.assertRaises(TypeError, splitlist)
+ self.assertRaises(TypeError, splitlist, 'a', 'b')
+ self.assertRaises(TypeError, splitlist, 2)
+ testcases = [
+ ('2', ('2',)),
+ ('', ()),
+ ('{}', ('',)),
+ ('""', ('',)),
+ ('a\n b\t\r c\n ', ('a', 'b', 'c')),
+ (b'a\n b\t\r c\n ', ('a', 'b', 'c')),
+ ('a \u20ac', ('a', '\u20ac')),
+ (b'a \xe2\x82\xac', ('a', '\u20ac')),
+ ('a {b c}', ('a', 'b c')),
+ (r'a b\ c', ('a', 'b c')),
+ (('a', 'b c'), ('a', 'b c')),
+ ('a 2', ('a', '2')),
+ (('a', 2), ('a', 2)),
+ ('a 3.4', ('a', '3.4')),
+ (('a', 3.4), ('a', 3.4)),
+ ((), ()),
+ (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))),
+ ]
+ for arg, res in testcases:
+ self.assertEqual(splitlist(arg), res, msg=arg)
+ self.assertRaises(TclError, splitlist, '{')
+
+ def test_split(self):
+ split = self.interp.tk.split
+ call = self.interp.tk.call
+ self.assertRaises(TypeError, split)
+ self.assertRaises(TypeError, split, 'a', 'b')
+ self.assertRaises(TypeError, split, 2)
+ testcases = [
+ ('2', '2'),
+ ('', ''),
+ ('{}', ''),
+ ('""', ''),
+ ('{', '{'),
+ ('a\n b\t\r c\n ', ('a', 'b', 'c')),
+ (b'a\n b\t\r c\n ', ('a', 'b', 'c')),
+ ('a \u20ac', ('a', '\u20ac')),
+ (b'a \xe2\x82\xac', ('a', '\u20ac')),
+ ('a {b c}', ('a', ('b', 'c'))),
+ (r'a b\ c', ('a', ('b', 'c'))),
+ (('a', b'b c'), ('a', ('b', 'c'))),
+ (('a', 'b c'), ('a', ('b', 'c'))),
+ ('a 2', ('a', '2')),
+ (('a', 2), ('a', 2)),
+ ('a 3.4', ('a', '3.4')),
+ (('a', 3.4), ('a', 3.4)),
+ (('a', (2, 3.4)), ('a', (2, 3.4))),
+ ((), ()),
+ (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))),
+ ]
+ for arg, res in testcases:
+ self.assertEqual(split(arg), res, msg=arg)
+
def test_main():
support.run_unittest(TclTest, TkinterTest)