annotate Lib/test/string_tests.py @ 74006:88198b93ff2f

Issue #13560: Add PyUnicode_EncodeLocale() * Use PyUnicode_EncodeLocale() in time.strftime() if wcsftime() is not available * Document my last changes in Misc/NEWS
author Victor Stinner <victor.stinner@haypocalc.com>
date Sat, 17 Dec 2011 04:13:41 +0100
parents c1effa2cdd20
children f7e05d205a52
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1 """
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
2 Common tests shared by test_str, test_unicode, test_userstring and test_string.
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
3 """
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
4
41716
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41642
diff changeset
5 import unittest, string, sys, struct
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 45504
diff changeset
6 from test import support
45302
b1cb6b44b798 Move UserList to collections.
Raymond Hettinger <python@rcn.com>
parents: 44160
diff changeset
7 from collections import UserList
13527
07c31182f237 add more tests of string.join variants to run_method_tests
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13517
diff changeset
8
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
9 class Sequence:
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
10 def __init__(self, seq='wxyz'): self.seq = seq
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
11 def __len__(self): return len(self.seq)
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
12 def __getitem__(self, i): return self.seq[i]
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
13
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
14 class BadSeq1(Sequence):
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
15 def __init__(self): self.seq = [7, 'hello', 123]
43446
a7c48ab809ec Patch # 1145 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents: 43100
diff changeset
16 def __str__(self): return '{0} {1} {2}'.format(*self.seq)
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
17
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
18 class BadSeq2(Sequence):
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
19 def __init__(self): self.seq = ['a', 'b', 'c']
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
20 def __len__(self): return 8
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
21
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
22 class BaseTest(unittest.TestCase):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
23 # These tests are for buffers of values (bytes) and not
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
24 # specific to character interpretation, used for bytes objects
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
25 # and various string implementations
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
26
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
27 # The type to be tested
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
28 # Change in subclasses to change the behaviour of fixtesttype()
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
29 type2test = None
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
30
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
31 # Whether the "contained items" of the container are integers in
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
32 # range(0, 256) (i.e. bytes, bytearray) or strings of length 1
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
33 # (str)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
34 contains_bytes = False
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
35
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
36 # All tests pass their arguments to the testing methods
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
37 # as str objects. fixtesttype() can be used to propagate
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
38 # these arguments to the appropriate type
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
39 def fixtype(self, obj):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
40 if isinstance(obj, str):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
41 return self.__class__.type2test(obj)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
42 elif isinstance(obj, list):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
43 return [self.fixtype(x) for x in obj]
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
44 elif isinstance(obj, tuple):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
45 return tuple([self.fixtype(x) for x in obj])
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
46 elif isinstance(obj, dict):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
47 return dict([
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
48 (self.fixtype(key), self.fixtype(value))
40809
f340cb045bf9 - PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
49 for (key, value) in obj.items()
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
50 ])
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
51 else:
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
52 return obj
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
53
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
54 # check that obj.method(*args) returns result
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
55 def checkequal(self, result, obj, methodname, *args, **kwargs):
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
56 result = self.fixtype(result)
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
57 obj = self.fixtype(obj)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
58 args = self.fixtype(args)
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
59 kwargs = self.fixtype(kwargs)
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
60 realresult = getattr(obj, methodname)(*args, **kwargs)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
61 self.assertEqual(
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
62 result,
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
63 realresult
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
64 )
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
65 # if the original is returned make sure that
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
66 # this doesn't happen with subclasses
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
67 if obj is realresult:
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
68 try:
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
69 class subtype(self.__class__.type2test):
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
70 pass
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
71 except TypeError:
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
72 pass # Skip this if we can't subclass
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
73 else:
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
74 obj = subtype(obj)
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
75 realresult = getattr(obj, methodname)(*args)
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
76 self.assertIsNot(obj, realresult)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
77
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
78 # check that obj.method(*args) raises exc
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
79 def checkraises(self, exc, obj, methodname, *args):
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
80 obj = self.fixtype(obj)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
81 args = self.fixtype(args)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
82 self.assertRaises(
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
83 exc,
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
84 getattr(obj, methodname),
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
85 *args
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
86 )
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
87
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
88 # call obj.method(*args) without any checks
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
89 def checkcall(self, obj, methodname, *args):
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
90 obj = self.fixtype(obj)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
91 args = self.fixtype(args)
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
92 getattr(obj, methodname)(*args)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
93
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
94 def test_count(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
95 self.checkequal(3, 'aaa', 'count', 'a')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
96 self.checkequal(0, 'aaa', 'count', 'b')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
97 self.checkequal(3, 'aaa', 'count', 'a')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
98 self.checkequal(0, 'aaa', 'count', 'b')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
99 self.checkequal(3, 'aaa', 'count', 'a')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
100 self.checkequal(0, 'aaa', 'count', 'b')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
101 self.checkequal(0, 'aaa', 'count', 'b')
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
102 self.checkequal(2, 'aaa', 'count', 'a', 1)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
103 self.checkequal(0, 'aaa', 'count', 'a', 10)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
104 self.checkequal(1, 'aaa', 'count', 'a', -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
105 self.checkequal(3, 'aaa', 'count', 'a', -10)
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
106 self.checkequal(1, 'aaa', 'count', 'a', 0, 1)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
107 self.checkequal(3, 'aaa', 'count', 'a', 0, 10)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
108 self.checkequal(2, 'aaa', 'count', 'a', 0, -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
109 self.checkequal(0, 'aaa', 'count', 'a', 0, -10)
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
110 self.checkequal(3, 'aaa', 'count', '', 1)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
111 self.checkequal(1, 'aaa', 'count', '', 3)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
112 self.checkequal(0, 'aaa', 'count', '', 10)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
113 self.checkequal(2, 'aaa', 'count', '', -1)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
114 self.checkequal(4, 'aaa', 'count', '', -10)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
115
49310
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
116 self.checkequal(1, '', 'count', '')
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
117 self.checkequal(0, '', 'count', '', 1, 1)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
118 self.checkequal(0, '', 'count', '', sys.maxsize, 0)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
119
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
120 self.checkequal(0, '', 'count', 'xx')
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
121 self.checkequal(0, '', 'count', 'xx', 1, 1)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
122 self.checkequal(0, '', 'count', 'xx', sys.maxsize, 0)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
123
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
124 self.checkraises(TypeError, 'hello', 'count')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
125
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
126 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
127 self.checkequal(0, 'hello', 'count', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
128 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
129 self.checkraises(TypeError, 'hello', 'count', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
130
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
131 # For a variety of combinations,
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
132 # verify that str.count() matches an equivalent function
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
133 # replacing all occurrences and then differencing the string lengths
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
134 charset = ['', 'a', 'b']
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
135 digits = 7
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
136 base = len(charset)
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
137 teststrings = set()
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
138 for i in range(base ** digits):
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
139 entry = []
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
140 for j in range(digits):
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
141 i, m = divmod(i, base)
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
142 entry.append(charset[m])
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
143 teststrings.add(''.join(entry))
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
144 teststrings = [self.fixtype(ts) for ts in teststrings]
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
145 for i in teststrings:
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
146 n = len(i)
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
147 for j in teststrings:
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
148 r1 = i.count(j)
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
149 if j:
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
150 r2, rem = divmod(n - len(i.replace(j, self.fixtype(''))),
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
151 len(j))
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
152 else:
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
153 r2, rem = len(i)+1, 0
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
154 if rem or r1 != r2:
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
155 self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
156 self.assertEqual(r1, r2, '%s != %s for %s' % (r1, r2, i))
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
157
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
158 def test_find(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
159 self.checkequal(0, 'abcdefghiabc', 'find', 'abc')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
160 self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
161 self.checkequal(-1, 'abcdefghiabc', 'find', 'def', 4)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
162
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
163 self.checkequal(0, 'abc', 'find', '', 0)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
164 self.checkequal(3, 'abc', 'find', '', 3)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
165 self.checkequal(-1, 'abc', 'find', '', 4)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
166
43897
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
167 # to check the ability to pass None as defaults
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
168 self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a')
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
169 self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
170 self.checkequal(-1, 'rrarrrrrrrrra', 'find', 'a', 4, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
171 self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4, None)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
172 self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
173
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
174 self.checkraises(TypeError, 'hello', 'find')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
175
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
176 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
177 self.checkequal(-1, 'hello', 'find', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
178 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
179 self.checkraises(TypeError, 'hello', 'find', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
180
49310
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
181 self.checkequal(0, '', 'find', '')
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
182 self.checkequal(-1, '', 'find', '', 1, 1)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
183 self.checkequal(-1, '', 'find', '', sys.maxsize, 0)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
184
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
185 self.checkequal(-1, '', 'find', 'xx')
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
186 self.checkequal(-1, '', 'find', 'xx', 1, 1)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
187 self.checkequal(-1, '', 'find', 'xx', sys.maxsize, 0)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
188
58097
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
189 # issue 7458
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
190 self.checkequal(-1, 'ab', 'find', 'xxx', sys.maxsize + 1, 0)
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
191
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
192 # For a variety of combinations,
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
193 # verify that str.find() matches __contains__
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
194 # and that the found substring is really at that location
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
195 charset = ['', 'a', 'b', 'c']
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
196 digits = 5
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
197 base = len(charset)
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
198 teststrings = set()
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
199 for i in range(base ** digits):
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
200 entry = []
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
201 for j in range(digits):
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
202 i, m = divmod(i, base)
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
203 entry.append(charset[m])
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
204 teststrings.add(''.join(entry))
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
205 teststrings = [self.fixtype(ts) for ts in teststrings]
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
206 for i in teststrings:
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
207 for j in teststrings:
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
208 loc = i.find(j)
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
209 r1 = (loc != -1)
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
210 r2 = j in i
58099
cc97a96e4a09 Merged revisions 77249 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58097
diff changeset
211 self.assertEqual(r1, r2)
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
212 if loc != -1:
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
213 self.assertEqual(i[loc:loc+len(j)], j)
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
214
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
215 def test_rfind(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
216 self.checkequal(9, 'abcdefghiabc', 'rfind', 'abc')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
217 self.checkequal(12, 'abcdefghiabc', 'rfind', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
218 self.checkequal(0, 'abcdefghiabc', 'rfind', 'abcd')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
219 self.checkequal(-1, 'abcdefghiabc', 'rfind', 'abcz')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
220
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
221 self.checkequal(3, 'abc', 'rfind', '', 0)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
222 self.checkequal(3, 'abc', 'rfind', '', 3)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
223 self.checkequal(-1, 'abc', 'rfind', '', 4)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
224
43897
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
225 # to check the ability to pass None as defaults
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
226 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a')
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
227 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
228 self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', 'a', 4, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
229 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4, None)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
230 self.checkequal( 2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
231
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
232 self.checkraises(TypeError, 'hello', 'rfind')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
233
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
234 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
235 self.checkequal(-1, 'hello', 'rfind', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
236 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
237 self.checkraises(TypeError, 'hello', 'rfind', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
238
58095
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
239 # For a variety of combinations,
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
240 # verify that str.rfind() matches __contains__
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
241 # and that the found substring is really at that location
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
242 charset = ['', 'a', 'b', 'c']
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
243 digits = 5
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
244 base = len(charset)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
245 teststrings = set()
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
246 for i in range(base ** digits):
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
247 entry = []
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
248 for j in range(digits):
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
249 i, m = divmod(i, base)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
250 entry.append(charset[m])
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
251 teststrings.add(''.join(entry))
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
252 teststrings = [self.fixtype(ts) for ts in teststrings]
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
253 for i in teststrings:
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
254 for j in teststrings:
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
255 loc = i.rfind(j)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
256 r1 = (loc != -1)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
257 r2 = j in i
58099
cc97a96e4a09 Merged revisions 77249 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58097
diff changeset
258 self.assertEqual(r1, r2)
58095
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
259 if loc != -1:
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
260 self.assertEqual(i[loc:loc+len(j)], j)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
261
58097
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
262 # issue 7458
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
263 self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0)
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
264
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
265 def test_index(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
266 self.checkequal(0, 'abcdefghiabc', 'index', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
267 self.checkequal(3, 'abcdefghiabc', 'index', 'def')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
268 self.checkequal(0, 'abcdefghiabc', 'index', 'abc')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
269 self.checkequal(9, 'abcdefghiabc', 'index', 'abc', 1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
270
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
271 self.checkraises(ValueError, 'abcdefghiabc', 'index', 'hib')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
272 self.checkraises(ValueError, 'abcdefghiab', 'index', 'abc', 1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
273 self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', 8)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
274 self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
275
43897
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
276 # to check the ability to pass None as defaults
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
277 self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a')
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
278 self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
279 self.checkraises(ValueError, 'rrarrrrrrrrra', 'index', 'a', 4, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
280 self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4, None)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
281 self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a', None, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
282
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
283 self.checkraises(TypeError, 'hello', 'index')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
284
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
285 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
286 self.checkraises(ValueError, 'hello', 'index', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
287 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
288 self.checkraises(TypeError, 'hello', 'index', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
289
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
290 def test_rindex(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
291 self.checkequal(12, 'abcdefghiabc', 'rindex', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
292 self.checkequal(3, 'abcdefghiabc', 'rindex', 'def')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
293 self.checkequal(9, 'abcdefghiabc', 'rindex', 'abc')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
294 self.checkequal(0, 'abcdefghiabc', 'rindex', 'abc', 0, -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
295
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
296 self.checkraises(ValueError, 'abcdefghiabc', 'rindex', 'hib')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
297 self.checkraises(ValueError, 'defghiabc', 'rindex', 'def', 1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
298 self.checkraises(ValueError, 'defghiabc', 'rindex', 'abc', 0, -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
299 self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, 8)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
300 self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
301
43897
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
302 # to check the ability to pass None as defaults
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
303 self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a')
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
304 self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
305 self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', 'a', 4, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
306 self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4, None)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
307 self.checkequal( 2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
308
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
309 self.checkraises(TypeError, 'hello', 'rindex')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
310
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
311 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
312 self.checkraises(ValueError, 'hello', 'rindex', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
313 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
314 self.checkraises(TypeError, 'hello', 'rindex', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
315
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
316 def test_lower(self):
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
317 self.checkequal('hello', 'HeLLo', 'lower')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
318 self.checkequal('hello', 'hello', 'lower')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
319 self.checkraises(TypeError, 'hello', 'lower', 42)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
320
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
321 def test_upper(self):
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
322 self.checkequal('HELLO', 'HeLLo', 'upper')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
323 self.checkequal('HELLO', 'HELLO', 'upper')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
324 self.checkraises(TypeError, 'hello', 'upper', 42)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
325
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
326 def test_expandtabs(self):
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
327 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
328 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
329 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 4)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
330 self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi', 'expandtabs', 4)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
331 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
332 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
333 self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
334 self.checkequal(' a\n b', ' \ta\n\tb', 'expandtabs', 1)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
335
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
336 self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
337 # This test is only valid when sizeof(int) == sizeof(void*) == 4.
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
338 if sys.maxsize < (1 << 32) and struct.calcsize('P') == 4:
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
339 self.checkraises(OverflowError,
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
340 '\ta\n\tb', 'expandtabs', sys.maxsize)
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
341
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
342 def test_split(self):
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
343 # by a char
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
344 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
345 self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
346 self.checkequal(['a', 'b|c|d'], 'a|b|c|d', 'split', '|', 1)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
347 self.checkequal(['a', 'b', 'c|d'], 'a|b|c|d', 'split', '|', 2)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
348 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 3)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
349 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 4)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
350 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|',
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
351 sys.maxsize-2)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
352 self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
353 self.checkequal(['a', '', 'b||c||d'], 'a||b||c||d', 'split', '|', 2)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
354 self.checkequal(['endcase ', ''], 'endcase |', 'split', '|')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
355 self.checkequal(['', ' startcase'], '| startcase', 'split', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
356 self.checkequal(['', 'bothcase', ''], '|bothcase|', 'split', '|')
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
357 self.checkequal(['a', '', 'b\x00c\x00d'], 'a\x00\x00b\x00c\x00d', 'split', '\x00', 2)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
358
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
359 self.checkequal(['a']*20, ('a|'*20)[:-1], 'split', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
360 self.checkequal(['a']*15 +['a|a|a|a|a'],
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
361 ('a|'*20)[:-1], 'split', '|', 15)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
362
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
363 # by string
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
364 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//')
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
365 self.checkequal(['a', 'b//c//d'], 'a//b//c//d', 'split', '//', 1)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
366 self.checkequal(['a', 'b', 'c//d'], 'a//b//c//d', 'split', '//', 2)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
367 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 3)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
368 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 4)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
369 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//',
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
370 sys.maxsize-10)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
371 self.checkequal(['a//b//c//d'], 'a//b//c//d', 'split', '//', 0)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
372 self.checkequal(['a', '', 'b////c////d'], 'a////b////c////d', 'split', '//', 2)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
373 self.checkequal(['endcase ', ''], 'endcase test', 'split', 'test')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
374 self.checkequal(['', ' begincase'], 'test begincase', 'split', 'test')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
375 self.checkequal(['', ' bothcase ', ''], 'test bothcase test',
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
376 'split', 'test')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
377 self.checkequal(['a', 'bc'], 'abbbc', 'split', 'bb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
378 self.checkequal(['', ''], 'aaa', 'split', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
379 self.checkequal(['aaa'], 'aaa', 'split', 'aaa', 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
380 self.checkequal(['ab', 'ab'], 'abbaab', 'split', 'ba')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
381 self.checkequal(['aaaa'], 'aaaa', 'split', 'aab')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
382 self.checkequal([''], '', 'split', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
383 self.checkequal(['aa'], 'aa', 'split', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
384 self.checkequal(['A', 'bobb'], 'Abbobbbobb', 'split', 'bbobb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
385 self.checkequal(['A', 'B', ''], 'AbbobbBbbobb', 'split', 'bbobb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
386
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
387 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
388 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH', 19)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
389 self.checkequal(['a']*18 + ['aBLAHa'], ('aBLAH'*20)[:-4],
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
390 'split', 'BLAH', 18)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
391
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
392 # argument type
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
393 self.checkraises(TypeError, 'hello', 'split', 42, 42, 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
394
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
395 # null case
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
396 self.checkraises(ValueError, 'hello', 'split', '')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
397 self.checkraises(ValueError, 'hello', 'split', '', 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
398
31199
504943c89193 Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31021
diff changeset
399 def test_rsplit(self):
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
400 # by a char
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
401 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|')
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
402 self.checkequal(['a|b|c', 'd'], 'a|b|c|d', 'rsplit', '|', 1)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
403 self.checkequal(['a|b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 2)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
404 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 3)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
405 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 4)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
406 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|',
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
407 sys.maxsize-100)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
408 self.checkequal(['a|b|c|d'], 'a|b|c|d', 'rsplit', '|', 0)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
409 self.checkequal(['a||b||c', '', 'd'], 'a||b||c||d', 'rsplit', '|', 2)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
410 self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
411 self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
412 self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
413
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
414 self.checkequal(['a\x00\x00b', 'c', 'd'], 'a\x00\x00b\x00c\x00d', 'rsplit', '\x00', 2)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
415
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
416 self.checkequal(['a']*20, ('a|'*20)[:-1], 'rsplit', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
417 self.checkequal(['a|a|a|a|a']+['a']*15,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
418 ('a|'*20)[:-1], 'rsplit', '|', 15)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
419
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
420 # by string
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
421 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//')
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
422 self.checkequal(['a//b//c', 'd'], 'a//b//c//d', 'rsplit', '//', 1)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
423 self.checkequal(['a//b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 2)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
424 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 3)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
425 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 4)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
426 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//',
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
427 sys.maxsize-5)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
428 self.checkequal(['a//b//c//d'], 'a//b//c//d', 'rsplit', '//', 0)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
429 self.checkequal(['a////b////c', '', 'd'], 'a////b////c////d', 'rsplit', '//', 2)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
430 self.checkequal(['', ' begincase'], 'test begincase', 'rsplit', 'test')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
431 self.checkequal(['endcase ', ''], 'endcase test', 'rsplit', 'test')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
432 self.checkequal(['', ' bothcase ', ''], 'test bothcase test',
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
433 'rsplit', 'test')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
434 self.checkequal(['ab', 'c'], 'abbbc', 'rsplit', 'bb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
435 self.checkequal(['', ''], 'aaa', 'rsplit', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
436 self.checkequal(['aaa'], 'aaa', 'rsplit', 'aaa', 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
437 self.checkequal(['ab', 'ab'], 'abbaab', 'rsplit', 'ba')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
438 self.checkequal(['aaaa'], 'aaaa', 'rsplit', 'aab')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
439 self.checkequal([''], '', 'rsplit', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
440 self.checkequal(['aa'], 'aa', 'rsplit', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
441 self.checkequal(['bbob', 'A'], 'bbobbbobbA', 'rsplit', 'bbobb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
442 self.checkequal(['', 'B', 'A'], 'bbobbBbbobbA', 'rsplit', 'bbobb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
443
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
444 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
445 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH', 19)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
446 self.checkequal(['aBLAHa'] + ['a']*18, ('aBLAH'*20)[:-4],
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
447 'rsplit', 'BLAH', 18)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
448
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
449 # argument type
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
450 self.checkraises(TypeError, 'hello', 'rsplit', 42, 42, 42)
31199
504943c89193 Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31021
diff changeset
451
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
452 # null case
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
453 self.checkraises(ValueError, 'hello', 'rsplit', '')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
454 self.checkraises(ValueError, 'hello', 'rsplit', '', 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
455
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
456 def test_replace(self):
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
457 EQ = self.checkequal
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
458
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
459 # Operations on the empty string
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
460 EQ("", "", "replace", "", "")
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
461 EQ("A", "", "replace", "", "A")
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
462 EQ("", "", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
463 EQ("", "", "replace", "A", "A")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
464 EQ("", "", "replace", "", "", 100)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
465 EQ("", "", "replace", "", "", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
466
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
467 # interleave (from=="", 'to' gets inserted everywhere)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
468 EQ("A", "A", "replace", "", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
469 EQ("*A*", "A", "replace", "", "*")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
470 EQ("*1A*1", "A", "replace", "", "*1")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
471 EQ("*-#A*-#", "A", "replace", "", "*-#")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
472 EQ("*-A*-A*-", "AA", "replace", "", "*-")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
473 EQ("*-A*-A*-", "AA", "replace", "", "*-", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
474 EQ("*-A*-A*-", "AA", "replace", "", "*-", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
475 EQ("*-A*-A*-", "AA", "replace", "", "*-", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
476 EQ("*-A*-A*-", "AA", "replace", "", "*-", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
477 EQ("*-A*-A", "AA", "replace", "", "*-", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
478 EQ("*-AA", "AA", "replace", "", "*-", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
479 EQ("AA", "AA", "replace", "", "*-", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
480
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
481 # single character deletion (from=="A", to=="")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
482 EQ("", "A", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
483 EQ("", "AAA", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
484 EQ("", "AAA", "replace", "A", "", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
485 EQ("", "AAA", "replace", "A", "", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
486 EQ("", "AAA", "replace", "A", "", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
487 EQ("", "AAA", "replace", "A", "", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
488 EQ("A", "AAA", "replace", "A", "", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
489 EQ("AA", "AAA", "replace", "A", "", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
490 EQ("AAA", "AAA", "replace", "A", "", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
491 EQ("", "AAAAAAAAAA", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
492 EQ("BCD", "ABACADA", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
493 EQ("BCD", "ABACADA", "replace", "A", "", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
494 EQ("BCD", "ABACADA", "replace", "A", "", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
495 EQ("BCD", "ABACADA", "replace", "A", "", 5)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
496 EQ("BCD", "ABACADA", "replace", "A", "", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
497 EQ("BCDA", "ABACADA", "replace", "A", "", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
498 EQ("BCADA", "ABACADA", "replace", "A", "", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
499 EQ("BACADA", "ABACADA", "replace", "A", "", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
500 EQ("ABACADA", "ABACADA", "replace", "A", "", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
501 EQ("BCD", "ABCAD", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
502 EQ("BCD", "ABCADAA", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
503 EQ("BCD", "BCD", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
504 EQ("*************", "*************", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
505 EQ("^A^", "^"+"A"*1000+"^", "replace", "A", "", 999)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
506
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
507 # substring deletion (from=="the", to=="")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
508 EQ("", "the", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
509 EQ("ater", "theater", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
510 EQ("", "thethe", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
511 EQ("", "thethethethe", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
512 EQ("aaaa", "theatheatheathea", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
513 EQ("that", "that", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
514 EQ("thaet", "thaet", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
515 EQ("here and re", "here and there", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
516 EQ("here and re and re", "here and there and there",
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
517 "replace", "the", "", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
518 EQ("here and re and re", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
519 "replace", "the", "", -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
520 EQ("here and re and re", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
521 "replace", "the", "", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
522 EQ("here and re and re", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
523 "replace", "the", "", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
524 EQ("here and re and there", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
525 "replace", "the", "", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
526 EQ("here and there and there", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
527 "replace", "the", "", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
528 EQ("here and re and re", "here and there and there", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
529
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
530 EQ("abc", "abc", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
531 EQ("abcdefg", "abcdefg", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
532
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
533 # substring deletion (from=="bob", to=="")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
534 EQ("bob", "bbobob", "replace", "bob", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
535 EQ("bobXbob", "bbobobXbbobob", "replace", "bob", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
536 EQ("aaaaaaa", "aaaaaaabob", "replace", "bob", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
537 EQ("aaaaaaa", "aaaaaaa", "replace", "bob", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
538
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
539 # single character replace in place (len(from)==len(to)==1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
540 EQ("Who goes there?", "Who goes there?", "replace", "o", "o")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
541 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O")
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
542 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
543 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
544 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
545 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
546 EQ("WhO goes there?", "Who goes there?", "replace", "o", "O", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
547 EQ("Who goes there?", "Who goes there?", "replace", "o", "O", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
548
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
549 EQ("Who goes there?", "Who goes there?", "replace", "a", "q")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
550 EQ("who goes there?", "Who goes there?", "replace", "W", "w")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
551 EQ("wwho goes there?ww", "WWho goes there?WW", "replace", "W", "w")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
552 EQ("Who goes there!", "Who goes there?", "replace", "?", "!")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
553 EQ("Who goes there!!", "Who goes there??", "replace", "?", "!")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
554
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
555 EQ("Who goes there?", "Who goes there?", "replace", ".", "!")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
556
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
557 # substring replace in place (len(from)==len(to) > 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
558 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**")
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
559 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
560 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
561 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
562 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
563 EQ("Th** ** a tissue", "This is a tissue", "replace", "is", "**", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
564 EQ("Th** is a tissue", "This is a tissue", "replace", "is", "**", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
565 EQ("This is a tissue", "This is a tissue", "replace", "is", "**", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
566 EQ("cobob", "bobob", "replace", "bob", "cob")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
567 EQ("cobobXcobocob", "bobobXbobobob", "replace", "bob", "cob")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
568 EQ("bobob", "bobob", "replace", "bot", "bot")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
569
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
570 # replace single character (len(from)==1, len(to)>1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
571 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
572 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
573 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
574 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
575 EQ("ReyKKjavik", "Reykjavik", "replace", "k", "KK", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
576 EQ("Reykjavik", "Reykjavik", "replace", "k", "KK", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
577 EQ("A----B----C----", "A.B.C.", "replace", ".", "----")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
578
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
579 EQ("Reykjavik", "Reykjavik", "replace", "q", "KK")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
580
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
581 # replace substring (len(from)>1, len(to)!=len(from))
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
582 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
583 "replace", "spam", "ham")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
584 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
585 "replace", "spam", "ham", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
586 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
587 "replace", "spam", "ham", -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
588 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
589 "replace", "spam", "ham", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
590 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
591 "replace", "spam", "ham", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
592 EQ("ham, ham, eggs and spam", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
593 "replace", "spam", "ham", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
594 EQ("ham, spam, eggs and spam", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
595 "replace", "spam", "ham", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
596 EQ("spam, spam, eggs and spam", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
597 "replace", "spam", "ham", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
598
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
599 EQ("bobob", "bobobob", "replace", "bobob", "bob")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
600 EQ("bobobXbobob", "bobobobXbobobob", "replace", "bobob", "bob")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
601 EQ("BOBOBOB", "BOBOBOB", "replace", "bob", "bobby")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
602
42902
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
603 # XXX Commented out. Is there any reason to support buffer objects
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
604 # as arguments for str.replace()? GvR
43947
cbc8b3bd3157 Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents: 43897
diff changeset
605 ## ba = bytearray('a')
cbc8b3bd3157 Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents: 43897
diff changeset
606 ## bb = bytearray('b')
42902
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
607 ## EQ("bbc", "abc", "replace", ba, bb)
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
608 ## EQ("aac", "abc", "replace", bb, ba)
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
609
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
610 #
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
611 self.checkequal('one@two!three!', 'one!two!three!', 'replace', '!', '@', 1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
612 self.checkequal('onetwothree', 'one!two!three!', 'replace', '!', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
613 self.checkequal('one@two@three!', 'one!two!three!', 'replace', '!', '@', 2)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
614 self.checkequal('one@two@three@', 'one!two!three!', 'replace', '!', '@', 3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
615 self.checkequal('one@two@three@', 'one!two!three!', 'replace', '!', '@', 4)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
616 self.checkequal('one!two!three!', 'one!two!three!', 'replace', '!', '@', 0)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
617 self.checkequal('one@two@three@', 'one!two!three!', 'replace', '!', '@')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
618 self.checkequal('one!two!three!', 'one!two!three!', 'replace', 'x', '@')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
619 self.checkequal('one!two!three!', 'one!two!three!', 'replace', 'x', '@', 2)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
620 self.checkequal('-a-b-c-', 'abc', 'replace', '', '-')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
621 self.checkequal('-a-b-c', 'abc', 'replace', '', '-', 3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
622 self.checkequal('abc', 'abc', 'replace', '', '-', 0)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
623 self.checkequal('', '', 'replace', '', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
624 self.checkequal('abc', 'abc', 'replace', 'ab', '--', 0)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
625 self.checkequal('abc', 'abc', 'replace', 'xy', '--')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
626 # Next three for SF bug 422088: [OSF1 alpha] string.replace(); died with
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
627 # MemoryError due to empty result (platform malloc issue when requesting
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
628 # 0 bytes).
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
629 self.checkequal('', '123', 'replace', '123', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
630 self.checkequal('', '123123', 'replace', '123', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
631 self.checkequal('x', '123x123', 'replace', '123', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
632
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
633 self.checkraises(TypeError, 'hello', 'replace')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
634 self.checkraises(TypeError, 'hello', 'replace', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
635 self.checkraises(TypeError, 'hello', 'replace', 42, 'h')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
636 self.checkraises(TypeError, 'hello', 'replace', 'h', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
637
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
638 def test_replace_overflow(self):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
639 # Check for overflow checking on 32 bit machines
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
640 if sys.maxsize != 2147483647 or struct.calcsize("P") > 4:
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
641 return
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
642 A2_16 = "A" * (2**16)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
643 self.checkraises(OverflowError, A2_16, "replace", "", A2_16)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
644 self.checkraises(OverflowError, A2_16, "replace", "A", A2_16)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
645 self.checkraises(OverflowError, A2_16, "replace", "AA", A2_16+A2_16)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
646
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
647
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
648
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
649 class CommonTest(BaseTest):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
650 # This testcase contains test that can be used in all
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
651 # stringlike classes. Currently this is str, unicode
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
652 # UserString and the string module.
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
653
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
654 def test_hash(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
655 # SF bug 1054139: += optimization was not invalidating cached hash value
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
656 a = self.type2test('DNSSEC')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
657 b = self.type2test('')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
658 for c in a:
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
659 b += c
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
660 hash(b)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
661 self.assertEqual(hash(a), hash(b))
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
662
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
663 def test_capitalize(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
664 self.checkequal(' hello ', ' hello ', 'capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
665 self.checkequal('Hello ', 'Hello ','capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
666 self.checkequal('Hello ', 'hello ','capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
667 self.checkequal('Aaaa', 'aaaa', 'capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
668 self.checkequal('Aaaa', 'AaAa', 'capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
669
71866
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
670 # check that titlecased chars are lowered correctly
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
671 # \u1ffc is the titlecased char
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
672 self.checkequal('\u1ffc\u1ff3\u1ff3\u1ff3',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
673 '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
674 # check with cased non-letter chars
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
675 self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
676 '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
677 self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
678 '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
679 self.checkequal('\u2160\u2171\u2172',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
680 '\u2160\u2161\u2162', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
681 self.checkequal('\u2160\u2171\u2172',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
682 '\u2170\u2171\u2172', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
683 # check with Ll chars with no upper - nothing changes here
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
684 self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
685 '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
686
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
687 self.checkraises(TypeError, 'hello', 'capitalize', 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
688
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
689 def test_lower(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
690 self.checkequal('hello', 'HeLLo', 'lower')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
691 self.checkequal('hello', 'hello', 'lower')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
692 self.checkraises(TypeError, 'hello', 'lower', 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
693
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
694 def test_upper(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
695 self.checkequal('HELLO', 'HeLLo', 'upper')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
696 self.checkequal('HELLO', 'HELLO', 'upper')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
697 self.checkraises(TypeError, 'hello', 'upper', 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
698
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
699 def test_expandtabs(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
700 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
701 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
702 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 4)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
703 self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi', 'expandtabs', 4)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
704 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
705 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
706 self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
707
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
708 self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
709
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
710 def test_additional_split(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
711 self.checkequal(['this', 'is', 'the', 'split', 'function'],
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
712 'this is the split function', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
713
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
714 # by whitespace
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
715 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
716 self.checkequal(['a', 'b c d'], 'a b c d', 'split', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
717 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
718 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
719 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 4)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
720 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None,
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
721 sys.maxsize-1)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
722 self.checkequal(['a b c d'], 'a b c d', 'split', None, 0)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
723 self.checkequal(['a b c d'], ' a b c d', 'split', None, 0)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
724 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
725
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
726 self.checkequal([], ' ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
727 self.checkequal(['a'], ' a ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
728 self.checkequal(['a', 'b'], ' a b ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
729 self.checkequal(['a', 'b '], ' a b ', 'split', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
730 self.checkequal(['a', 'b c '], ' a b c ', 'split', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
731 self.checkequal(['a', 'b', 'c '], ' a b c ', 'split', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
732 self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
733 aaa = ' a '*20
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
734 self.checkequal(['a']*20, aaa, 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
735 self.checkequal(['a'] + [aaa[4:]], aaa, 'split', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
736 self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
737
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
738 # mixed use of str and unicode
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
739 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', ' ', 2)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
740
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
741 def test_additional_rsplit(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
742 self.checkequal(['this', 'is', 'the', 'rsplit', 'function'],
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
743 'this is the rsplit function', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
744
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
745 # by whitespace
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
746 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
747 self.checkequal(['a b c', 'd'], 'a b c d', 'rsplit', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
748 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
749 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
750 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 4)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
751 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None,
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
752 sys.maxsize-20)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
753 self.checkequal(['a b c d'], 'a b c d', 'rsplit', None, 0)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
754 self.checkequal(['a b c d'], 'a b c d ', 'rsplit', None, 0)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
755 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
756
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
757 self.checkequal([], ' ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
758 self.checkequal(['a'], ' a ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
759 self.checkequal(['a', 'b'], ' a b ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
760 self.checkequal([' a', 'b'], ' a b ', 'rsplit', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
761 self.checkequal([' a b','c'], ' a b c ', 'rsplit',
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
762 None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
763 self.checkequal([' a', 'b', 'c'], ' a b c ', 'rsplit',
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
764 None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
765 self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'rsplit', None, 88)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
766 aaa = ' a '*20
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
767 self.checkequal(['a']*20, aaa, 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
768 self.checkequal([aaa[:-4]] + ['a'], aaa, 'rsplit', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
769 self.checkequal([' a a'] + ['a']*18, aaa, 'rsplit', None, 18)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
770
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
771 # mixed use of str and unicode
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
772 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', ' ', 2)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
773
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
774 def test_strip(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
775 self.checkequal('hello', ' hello ', 'strip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
776 self.checkequal('hello ', ' hello ', 'lstrip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
777 self.checkequal(' hello', ' hello ', 'rstrip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
778 self.checkequal('hello', 'hello', 'strip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
779
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
780 # strip/lstrip/rstrip with None arg
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
781 self.checkequal('hello', ' hello ', 'strip', None)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
782 self.checkequal('hello ', ' hello ', 'lstrip', None)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
783 self.checkequal(' hello', ' hello ', 'rstrip', None)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
784 self.checkequal('hello', 'hello', 'strip', None)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
785
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
786 # strip/lstrip/rstrip with str arg
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
787 self.checkequal('hello', 'xyzzyhelloxyzzy', 'strip', 'xyz')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
788 self.checkequal('helloxyzzy', 'xyzzyhelloxyzzy', 'lstrip', 'xyz')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
789 self.checkequal('xyzzyhello', 'xyzzyhelloxyzzy', 'rstrip', 'xyz')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
790 self.checkequal('hello', 'hello', 'strip', 'xyz')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
791
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
792 self.checkraises(TypeError, 'hello', 'strip', 42, 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
793 self.checkraises(TypeError, 'hello', 'lstrip', 42, 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
794 self.checkraises(TypeError, 'hello', 'rstrip', 42, 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
795
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
796 def test_ljust(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
797 self.checkequal('abc ', 'abc', 'ljust', 10)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
798 self.checkequal('abc ', 'abc', 'ljust', 6)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
799 self.checkequal('abc', 'abc', 'ljust', 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
800 self.checkequal('abc', 'abc', 'ljust', 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
801 self.checkequal('abc*******', 'abc', 'ljust', 10, '*')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
802 self.checkraises(TypeError, 'abc', 'ljust')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
803
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
804 def test_rjust(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
805 self.checkequal(' abc', 'abc', 'rjust', 10)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
806 self.checkequal(' abc', 'abc', 'rjust', 6)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
807 self.checkequal('abc', 'abc', 'rjust', 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
808 self.checkequal('abc', 'abc', 'rjust', 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
809 self.checkequal('*******abc', 'abc', 'rjust', 10, '*')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
810 self.checkraises(TypeError, 'abc', 'rjust')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
811
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
812 def test_center(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
813 self.checkequal(' abc ', 'abc', 'center', 10)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
814 self.checkequal(' abc ', 'abc', 'center', 6)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
815 self.checkequal('abc', 'abc', 'center', 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
816 self.checkequal('abc', 'abc', 'center', 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
817 self.checkequal('***abc****', 'abc', 'center', 10, '*')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
818 self.checkraises(TypeError, 'abc', 'center')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
819
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
820 def test_swapcase(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
821 self.checkequal('hEllO CoMPuTErS', 'HeLLo cOmpUteRs', 'swapcase')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
822
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
823 self.checkraises(TypeError, 'hello', 'swapcase', 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
824
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
825 def test_zfill(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
826 self.checkequal('123', '123', 'zfill', 2)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
827 self.checkequal('123', '123', 'zfill', 3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
828 self.checkequal('0123', '123', 'zfill', 4)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
829 self.checkequal('+123', '+123', 'zfill', 3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
830 self.checkequal('+123', '+123', 'zfill', 4)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
831 self.checkequal('+0123', '+123', 'zfill', 5)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
832 self.checkequal('-123', '-123', 'zfill', 3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
833 self.checkequal('-123', '-123', 'zfill', 4)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
834 self.checkequal('-0123', '-123', 'zfill', 5)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
835 self.checkequal('000', '', 'zfill', 3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
836 self.checkequal('34', '34', 'zfill', 1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
837 self.checkequal('0034', '34', 'zfill', 4)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
838
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
839 self.checkraises(TypeError, '123', 'zfill')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
840
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
841 class MixinStrUnicodeUserStringTest:
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
842 # additional tests that only work for
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
843 # stringlike objects, i.e. str, unicode, UserString
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
844 # (but not the string module)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
845
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
846 def test_islower(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
847 self.checkequal(False, '', 'islower')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
848 self.checkequal(True, 'a', 'islower')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
849 self.checkequal(False, 'A', 'islower')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
850 self.checkequal(False, '\n', 'islower')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
851 self.checkequal(True, 'abc', 'islower')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
852 self.checkequal(False, 'aBc', 'islower')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
853 self.checkequal(True, 'abc\n', 'islower')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
854 self.checkraises(TypeError, 'abc', 'islower', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
855
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
856 def test_isupper(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
857 self.checkequal(False, '', 'isupper')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
858 self.checkequal(False, 'a', 'isupper')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
859 self.checkequal(True, 'A', 'isupper')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
860 self.checkequal(False, '\n', 'isupper')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
861 self.checkequal(True, 'ABC', 'isupper')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
862 self.checkequal(False, 'AbC', 'isupper')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
863 self.checkequal(True, 'ABC\n', 'isupper')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
864 self.checkraises(TypeError, 'abc', 'isupper', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
865
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
866 def test_istitle(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
867 self.checkequal(False, '', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
868 self.checkequal(False, 'a', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
869 self.checkequal(True, 'A', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
870 self.checkequal(False, '\n', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
871 self.checkequal(True, 'A Titlecased Line', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
872 self.checkequal(True, 'A\nTitlecased Line', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
873 self.checkequal(True, 'A Titlecased, Line', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
874 self.checkequal(False, 'Not a capitalized String', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
875 self.checkequal(False, 'Not\ta Titlecase String', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
876 self.checkequal(False, 'Not--a Titlecase String', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
877 self.checkequal(False, 'NOT', 'istitle')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
878 self.checkraises(TypeError, 'abc', 'istitle', 42)
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
879
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
880 def test_isspace(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
881 self.checkequal(False, '', 'isspace')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
882 self.checkequal(False, 'a', 'isspace')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
883 self.checkequal(True, ' ', 'isspace')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
884 self.checkequal(True, '\t', 'isspace')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
885 self.checkequal(True, '\r', 'isspace')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
886 self.checkequal(True, '\n', 'isspace')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
887 self.checkequal(True, ' \t\r\n', 'isspace')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
888 self.checkequal(False, ' \t\r\na', 'isspace')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
889 self.checkraises(TypeError, 'abc', 'isspace', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
890
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
891 def test_isalpha(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
892 self.checkequal(False, '', 'isalpha')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
893 self.checkequal(True, 'a', 'isalpha')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
894 self.checkequal(True, 'A', 'isalpha')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
895 self.checkequal(False, '\n', 'isalpha')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
896 self.checkequal(True, 'abc', 'isalpha')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
897 self.checkequal(False, 'aBc123', 'isalpha')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
898 self.checkequal(False, 'abc\n', 'isalpha')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
899 self.checkraises(TypeError, 'abc', 'isalpha', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
900
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
901 def test_isalnum(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
902 self.checkequal(False, '', 'isalnum')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
903 self.checkequal(True, 'a', 'isalnum')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
904 self.checkequal(True, 'A', 'isalnum')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
905 self.checkequal(False, '\n', 'isalnum')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
906 self.checkequal(True, '123abc456', 'isalnum')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
907 self.checkequal(True, 'a1b3c', 'isalnum')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
908 self.checkequal(False, 'aBc000 ', 'isalnum')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
909 self.checkequal(False, 'abc\n', 'isalnum')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
910 self.checkraises(TypeError, 'abc', 'isalnum', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
911
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
912 def test_isdigit(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
913 self.checkequal(False, '', 'isdigit')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
914 self.checkequal(False, 'a', 'isdigit')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
915 self.checkequal(True, '0', 'isdigit')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
916 self.checkequal(True, '0123456789', 'isdigit')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
917 self.checkequal(False, '0123456789a', 'isdigit')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
918
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
919 self.checkraises(TypeError, 'abc', 'isdigit', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
920
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
921 def test_title(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
922 self.checkequal(' Hello ', ' hello ', 'title')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
923 self.checkequal('Hello ', 'hello ', 'title')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
924 self.checkequal('Hello ', 'Hello ', 'title')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
925 self.checkequal('Format This As Title String', "fOrMaT thIs aS titLe String", 'title')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
926 self.checkequal('Format,This-As*Title;String', "fOrMaT,thIs-aS*titLe;String", 'title', )
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
927 self.checkequal('Getint', "getInt", 'title')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
928 self.checkraises(TypeError, 'hello', 'title', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
929
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
930 def test_splitlines(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
931 self.checkequal(['abc', 'def', '', 'ghi'], "abc\ndef\n\rghi", 'splitlines')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
932 self.checkequal(['abc', 'def', '', 'ghi'], "abc\ndef\n\r\nghi", 'splitlines')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
933 self.checkequal(['abc', 'def', 'ghi'], "abc\ndef\r\nghi", 'splitlines')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
934 self.checkequal(['abc', 'def', 'ghi'], "abc\ndef\r\nghi\n", 'splitlines')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
935 self.checkequal(['abc', 'def', 'ghi', ''], "abc\ndef\r\nghi\n\r", 'splitlines')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
936 self.checkequal(['', 'abc', 'def', 'ghi', ''], "\nabc\ndef\r\nghi\n\r", 'splitlines')
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
937 self.checkequal(['', 'abc', 'def', 'ghi', ''],
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
938 "\nabc\ndef\r\nghi\n\r", 'splitlines', False)
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
939 self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'],
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
940 "\nabc\ndef\r\nghi\n\r", 'splitlines', True)
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
941 self.checkequal(['', 'abc', 'def', 'ghi', ''], "\nabc\ndef\r\nghi\n\r",
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
942 'splitlines', keepends=False)
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
943 self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'],
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
944 "\nabc\ndef\r\nghi\n\r", 'splitlines', keepends=True)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
945
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
946 self.checkraises(TypeError, 'abc', 'splitlines', 42, 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
947
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
948 def test_startswith(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
949 self.checkequal(True, 'hello', 'startswith', 'he')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
950 self.checkequal(True, 'hello', 'startswith', 'hello')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
951 self.checkequal(False, 'hello', 'startswith', 'hello world')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
952 self.checkequal(True, 'hello', 'startswith', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
953 self.checkequal(False, 'hello', 'startswith', 'ello')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
954 self.checkequal(True, 'hello', 'startswith', 'ello', 1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
955 self.checkequal(True, 'hello', 'startswith', 'o', 4)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
956 self.checkequal(False, 'hello', 'startswith', 'o', 5)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
957 self.checkequal(True, 'hello', 'startswith', '', 5)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
958 self.checkequal(False, 'hello', 'startswith', 'lo', 6)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
959 self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
960 self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3, 7)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
961 self.checkequal(False, 'helloworld', 'startswith', 'lowo', 3, 6)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
962
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
963 # test negative indices
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
964 self.checkequal(True, 'hello', 'startswith', 'he', 0, -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
965 self.checkequal(True, 'hello', 'startswith', 'he', -53, -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
966 self.checkequal(False, 'hello', 'startswith', 'hello', 0, -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
967 self.checkequal(False, 'hello', 'startswith', 'hello world', -1, -10)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
968 self.checkequal(False, 'hello', 'startswith', 'ello', -5)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
969 self.checkequal(True, 'hello', 'startswith', 'ello', -4)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
970 self.checkequal(False, 'hello', 'startswith', 'o', -2)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
971 self.checkequal(True, 'hello', 'startswith', 'o', -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
972 self.checkequal(True, 'hello', 'startswith', '', -3, -3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
973 self.checkequal(False, 'hello', 'startswith', 'lo', -9)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
974
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
975 self.checkraises(TypeError, 'hello', 'startswith')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
976 self.checkraises(TypeError, 'hello', 'startswith', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
977
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
978 # test tuple arguments
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
979 self.checkequal(True, 'hello', 'startswith', ('he', 'ha'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
980 self.checkequal(False, 'hello', 'startswith', ('lo', 'llo'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
981 self.checkequal(True, 'hello', 'startswith', ('hellox', 'hello'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
982 self.checkequal(False, 'hello', 'startswith', ())
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
983 self.checkequal(True, 'helloworld', 'startswith', ('hellowo',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
984 'rld', 'lowo'), 3)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
985 self.checkequal(False, 'helloworld', 'startswith', ('hellowo', 'ello',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
986 'rld'), 3)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
987 self.checkequal(True, 'hello', 'startswith', ('lo', 'he'), 0, -1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
988 self.checkequal(False, 'hello', 'startswith', ('he', 'hel'), 0, 1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
989 self.checkequal(True, 'hello', 'startswith', ('he', 'hel'), 0, 2)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
990
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
991 self.checkraises(TypeError, 'hello', 'startswith', (42,))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
992
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
993 def test_endswith(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
994 self.checkequal(True, 'hello', 'endswith', 'lo')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
995 self.checkequal(False, 'hello', 'endswith', 'he')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
996 self.checkequal(True, 'hello', 'endswith', '')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
997 self.checkequal(False, 'hello', 'endswith', 'hello world')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
998 self.checkequal(False, 'helloworld', 'endswith', 'worl')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
999 self.checkequal(True, 'helloworld', 'endswith', 'worl', 3, 9)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1000 self.checkequal(True, 'helloworld', 'endswith', 'world', 3, 12)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1001 self.checkequal(True, 'helloworld', 'endswith', 'lowo', 1, 7)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1002 self.checkequal(True, 'helloworld', 'endswith', 'lowo', 2, 7)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1003 self.checkequal(True, 'helloworld', 'endswith', 'lowo', 3, 7)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1004 self.checkequal(False, 'helloworld', 'endswith', 'lowo', 4, 7)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1005 self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, 8)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1006 self.checkequal(False, 'ab', 'endswith', 'ab', 0, 1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1007 self.checkequal(False, 'ab', 'endswith', 'ab', 0, 0)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1008
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1009 # test negative indices
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1010 self.checkequal(True, 'hello', 'endswith', 'lo', -2)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1011 self.checkequal(False, 'hello', 'endswith', 'he', -2)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1012 self.checkequal(True, 'hello', 'endswith', '', -3, -3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1013 self.checkequal(False, 'hello', 'endswith', 'hello world', -10, -2)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1014 self.checkequal(False, 'helloworld', 'endswith', 'worl', -6)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1015 self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1016 self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, 9)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1017 self.checkequal(True, 'helloworld', 'endswith', 'world', -7, 12)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1018 self.checkequal(True, 'helloworld', 'endswith', 'lowo', -99, -3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1019 self.checkequal(True, 'helloworld', 'endswith', 'lowo', -8, -3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1020 self.checkequal(True, 'helloworld', 'endswith', 'lowo', -7, -3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1021 self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, -4)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1022 self.checkequal(False, 'helloworld', 'endswith', 'lowo', -8, -2)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1023
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1024 self.checkraises(TypeError, 'hello', 'endswith')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1025 self.checkraises(TypeError, 'hello', 'endswith', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1026
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1027 # test tuple arguments
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1028 self.checkequal(False, 'hello', 'endswith', ('he', 'ha'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1029 self.checkequal(True, 'hello', 'endswith', ('lo', 'llo'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1030 self.checkequal(True, 'hello', 'endswith', ('hellox', 'hello'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1031 self.checkequal(False, 'hello', 'endswith', ())
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1032 self.checkequal(True, 'helloworld', 'endswith', ('hellowo',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1033 'rld', 'lowo'), 3)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1034 self.checkequal(False, 'helloworld', 'endswith', ('hellowo', 'ello',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1035 'rld'), 3, -1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1036 self.checkequal(True, 'hello', 'endswith', ('hell', 'ell'), 0, -1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1037 self.checkequal(False, 'hello', 'endswith', ('he', 'hel'), 0, 1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1038 self.checkequal(True, 'hello', 'endswith', ('he', 'hell'), 0, 4)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1039
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1040 self.checkraises(TypeError, 'hello', 'endswith', (42,))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1041
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1042 def test___contains__(self):
58477
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1043 self.checkequal(True, '', '__contains__', '')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1044 self.checkequal(True, 'abc', '__contains__', '')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1045 self.checkequal(False, 'abc', '__contains__', '\0')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1046 self.checkequal(True, '\0abc', '__contains__', '\0')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1047 self.checkequal(True, 'abc\0', '__contains__', '\0')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1048 self.checkequal(True, '\0abc', '__contains__', 'a')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1049 self.checkequal(True, 'asdf', '__contains__', 'asdf')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1050 self.checkequal(False, 'asd', '__contains__', 'asdf')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1051 self.checkequal(False, '', '__contains__', 'asdf')
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1052
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1053 def test_subscript(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1054 self.checkequal('a', 'abc', '__getitem__', 0)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1055 self.checkequal('c', 'abc', '__getitem__', -1)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1056 self.checkequal('a', 'abc', '__getitem__', 0)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1057 self.checkequal('abc', 'abc', '__getitem__', slice(0, 3))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1058 self.checkequal('abc', 'abc', '__getitem__', slice(0, 1000))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1059 self.checkequal('a', 'abc', '__getitem__', slice(0, 1))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1060 self.checkequal('', 'abc', '__getitem__', slice(0, 0))
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1061
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1062 self.checkraises(TypeError, 'abc', '__getitem__', 'def')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1063
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1064 def test_slice(self):
43100
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1065 self.checkequal('abc', 'abc', '__getitem__', slice(0, 1000))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1066 self.checkequal('abc', 'abc', '__getitem__', slice(0, 3))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1067 self.checkequal('ab', 'abc', '__getitem__', slice(0, 2))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1068 self.checkequal('bc', 'abc', '__getitem__', slice(1, 3))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1069 self.checkequal('b', 'abc', '__getitem__', slice(1, 2))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1070 self.checkequal('', 'abc', '__getitem__', slice(2, 2))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1071 self.checkequal('', 'abc', '__getitem__', slice(1000, 1000))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1072 self.checkequal('', 'abc', '__getitem__', slice(2000, 1000))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1073 self.checkequal('', 'abc', '__getitem__', slice(2, 1))
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1074
43100
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1075 self.checkraises(TypeError, 'abc', '__getitem__', 'def')
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1076
42954
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1077 def test_extended_getslice(self):
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1078 # Test extended slicing by comparing with list slicing.
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1079 s = string.ascii_letters + string.digits
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1080 indices = (0, None, 1, 3, 41, -1, -2, -37)
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1081 for start in indices:
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1082 for stop in indices:
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1083 # Skip step 0 (invalid)
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1084 for step in indices[1:]:
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1085 L = list(s)[start:stop:step]
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1086 self.checkequal("".join(L), s, '__getitem__',
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1087 slice(start, stop, step))
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1088
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1089 def test_mul(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1090 self.checkequal('', 'abc', '__mul__', -1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1091 self.checkequal('', 'abc', '__mul__', 0)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1092 self.checkequal('abc', 'abc', '__mul__', 1)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1093 self.checkequal('abcabcabc', 'abc', '__mul__', 3)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1094 self.checkraises(TypeError, 'abc', '__mul__')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1095 self.checkraises(TypeError, 'abc', '__mul__', '')
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35758
diff changeset
1096 # XXX: on a 64-bit system, this doesn't raise an overflow error,
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35758
diff changeset
1097 # but either raises a MemoryError, or succeeds (if you have 54TiB)
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35758
diff changeset
1098 #self.checkraises(OverflowError, 10000*'abc', '__mul__', 2000000000)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1099
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1100 def test_join(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1101 # join now works with any sequence type
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1102 # moved here, because the argument order is
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1103 # different in string.join (see the test in
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1104 # test.test_string.StringTest.test_join)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1105 self.checkequal('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1106 self.checkequal('abcd', '', 'join', ('a', 'b', 'c', 'd'))
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1107 self.checkequal('bd', '', 'join', ('', 'b', '', 'd'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1108 self.checkequal('ac', '', 'join', ('a', '', 'c', ''))
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1109 self.checkequal('w x y z', ' ', 'join', Sequence())
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1110 self.checkequal('abc', 'a', 'join', ('abc',))
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1111 self.checkequal('z', 'a', 'join', UserList(['z']))
41620
6b7d1782a574 test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents: 41575
diff changeset
1112 self.checkequal('a.b.c', '.', 'join', ['a', 'b', 'c'])
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1113 self.assertRaises(TypeError, '.'.join, ['a', 'b', 3])
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1114 for i in [5, 25, 125]:
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1115 self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1116 ['a' * i] * i)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1117 self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1118 ('a' * i,) * i)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1119
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1120 #self.checkequal(str(BadSeq1()), ' ', 'join', BadSeq1())
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1121 self.checkequal('a b c', ' ', 'join', BadSeq2())
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1122
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1123 self.checkraises(TypeError, ' ', 'join')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1124 self.checkraises(TypeError, ' ', 'join', 7)
43446
a7c48ab809ec Patch # 1145 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents: 43100
diff changeset
1125 self.checkraises(TypeError, ' ', 'join', [1, 2, bytes()])
35758
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1126 try:
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1127 def f():
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1128 yield 4 + ""
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1129 self.fixtype(' ').join(f())
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
1130 except TypeError as e:
35758
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1131 if '+' not in str(e):
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1132 self.fail('join() ate exception message')
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1133 else:
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1134 self.fail('exception not raised')
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1135
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1136 def test_formatting(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1137 self.checkequal('+hello+', '+%s+', '__mod__', 'hello')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1138 self.checkequal('+10+', '+%d+', '__mod__', 10)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1139 self.checkequal('a', "%c", '__mod__', "a")
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1140 self.checkequal('a', "%c", '__mod__', "a")
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1141 self.checkequal('"', "%c", '__mod__', 34)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1142 self.checkequal('$', "%c", '__mod__', 36)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1143 self.checkequal('10', "%d", '__mod__', 10)
28478
8802de0da533 Fix PyString_Format() so that '%c' % u'a' returns u'a'
Walter Dörwald <walter@livinglogic.de>
parents: 28407
diff changeset
1144 self.checkequal('\x7f', "%c", '__mod__', 0x7f)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1145
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1146 for ordinal in (-100, 0x200000):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1147 # unicode raises ValueError, str raises OverflowError
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1148 self.checkraises((ValueError, OverflowError), '%c', '__mod__', ordinal)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1149
45504
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1150 longvalue = sys.maxsize + 10
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1151 slongvalue = str(longvalue)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1152 self.checkequal(' 42', '%3ld', '__mod__', 42)
45504
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1153 self.checkequal('42', '%d', '__mod__', 42.0)
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1154 self.checkequal(slongvalue, '%d', '__mod__', longvalue)
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1155 self.checkcall('%d', '__mod__', float(longvalue))
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1156 self.checkequal('0042.00', '%07.2f', '__mod__', 42)
30216
7ab1a41f16da SF bug #795506: Wrong handling of string format code for float values.
Raymond Hettinger <python@rcn.com>
parents: 28774
diff changeset
1157 self.checkequal('0042.00', '%07.2F', '__mod__', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1158
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1159 self.checkraises(TypeError, 'abc', '__mod__')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1160 self.checkraises(TypeError, '%(foo)s', '__mod__', 42)
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1161 self.checkraises(TypeError, '%s%s', '__mod__', (42,))
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1162 self.checkraises(TypeError, '%c', '__mod__', (None,))
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1163 self.checkraises(ValueError, '%(foo', '__mod__', {})
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1164 self.checkraises(TypeError, '%(foo)s %(bar)s', '__mod__', ('foo', 42))
45504
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1165 self.checkraises(TypeError, '%d', '__mod__', "42") # not numeric
57582
1c92fbb3baf2 Issue #7435: Remove duplicate int/long tests, and other
Mark Dickinson <dickinsm@gmail.com>
parents: 53640
diff changeset
1166 self.checkraises(TypeError, '%d', '__mod__', (42+0j)) # no int conversion provided
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1167
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1168 # argument names with properly nested brackets are supported
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1169 self.checkequal('bar', '%((foo))s', '__mod__', {'(foo)': 'bar'})
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1170
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1171 # 100 is a magic number in PyUnicode_Format, this forces a resize
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1172 self.checkequal(103*'a'+'x', '%sx', '__mod__', 103*'a')
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1173
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1174 self.checkraises(TypeError, '%*s', '__mod__', ('foo', 'bar'))
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1175 self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.))
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1176 self.checkraises(ValueError, '%10', '__mod__', (42,))
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1177
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1178 def test_floatformatting(self):
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1179 # float formatting
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
1180 for prec in range(100):
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1181 format = '%%.%if' % prec
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1182 value = 0.01
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
1183 for x in range(60):
64694
1e89b5ee02f8 Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58476
diff changeset
1184 value = value * 3.14159265359 / 3.0 * 10.0
53640
e08e80e768c1 Issue #5859: Remove use of fixed-length buffers for float formatting
Mark Dickinson <dickinsm@gmail.com>
parents: 49310
diff changeset
1185 self.checkcall(format, "__mod__", value)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1186
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1187 def test_inplace_rewrites(self):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1188 # Check that strings don't copy and modify cached single-character strings
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1189 self.checkequal('a', 'A', 'lower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1190 self.checkequal(True, 'A', 'isupper')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1191 self.checkequal('A', 'a', 'upper')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1192 self.checkequal(True, 'a', 'islower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1193
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1194 self.checkequal('a', 'A', 'replace', 'A', 'a')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1195 self.checkequal(True, 'A', 'isupper')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1196
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1197 self.checkequal('A', 'a', 'capitalize')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1198 self.checkequal(True, 'a', 'islower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1199
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1200 self.checkequal('A', 'a', 'swapcase')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1201 self.checkequal(True, 'a', 'islower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1202
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1203 self.checkequal('A', 'a', 'title')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1204 self.checkequal(True, 'a', 'islower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1205
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1206 def test_partition(self):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1207
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1208 self.checkequal(('this is the par', 'ti', 'tion method'),
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1209 'this is the partition method', 'partition', 'ti')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1210
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1211 # from raymond's original specification
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1212 S = 'http://www.python.org'
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1213 self.checkequal(('http', '://', 'www.python.org'), S, 'partition', '://')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1214 self.checkequal(('http://www.python.org', '', ''), S, 'partition', '?')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1215 self.checkequal(('', 'http://', 'www.python.org'), S, 'partition', 'http://')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1216 self.checkequal(('http://www.python.', 'org', ''), S, 'partition', 'org')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1217
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1218 self.checkraises(ValueError, S, 'partition', '')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1219 self.checkraises(TypeError, S, 'partition', None)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1220
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1221 def test_rpartition(self):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1222
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1223 self.checkequal(('this is the rparti', 'ti', 'on method'),
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1224 'this is the rpartition method', 'rpartition', 'ti')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1225
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1226 # from raymond's original specification
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1227 S = 'http://www.python.org'
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1228 self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://')
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
1229 self.checkequal(('', '', 'http://www.python.org'), S, 'rpartition', '?')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1230 self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1231 self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1232
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1233 self.checkraises(ValueError, S, 'rpartition', '')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1234 self.checkraises(TypeError, S, 'rpartition', None)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1235
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1236 def test_none_arguments(self):
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1237 # issue 11828
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1238 s = 'hello'
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1239 self.checkequal(2, s, 'find', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1240 self.checkequal(3, s, 'find', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1241 self.checkequal(2, s, 'find', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1242 self.checkequal(0, s, 'find', 'h', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1243
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1244 self.checkequal(3, s, 'rfind', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1245 self.checkequal(3, s, 'rfind', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1246 self.checkequal(2, s, 'rfind', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1247 self.checkequal(0, s, 'rfind', 'h', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1248
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1249 self.checkequal(2, s, 'index', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1250 self.checkequal(3, s, 'index', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1251 self.checkequal(2, s, 'index', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1252 self.checkequal(0, s, 'index', 'h', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1253
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1254 self.checkequal(3, s, 'rindex', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1255 self.checkequal(3, s, 'rindex', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1256 self.checkequal(2, s, 'rindex', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1257 self.checkequal(0, s, 'rindex', 'h', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1258
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1259 self.checkequal(2, s, 'count', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1260 self.checkequal(1, s, 'count', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1261 self.checkequal(1, s, 'count', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1262 self.checkequal(0, s, 'count', 'x', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1263
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1264 self.checkequal(True, s, 'endswith', 'o', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1265 self.checkequal(True, s, 'endswith', 'lo', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1266 self.checkequal(True, s, 'endswith', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1267 self.checkequal(False, s, 'endswith', 'x', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1268
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1269 self.checkequal(True, s, 'startswith', 'h', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1270 self.checkequal(True, s, 'startswith', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1271 self.checkequal(True, s, 'startswith', 'h', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1272 self.checkequal(False, s, 'startswith', 'x', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1273
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1274 def test_find_etc_raise_correct_error_messages(self):
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1275 # issue 11828
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1276 s = 'hello'
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1277 x = 'x'
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1278 self.assertRaisesRegex(TypeError, r'^find\(', s.find,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1279 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1280 self.assertRaisesRegex(TypeError, r'^rfind\(', s.rfind,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1281 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1282 self.assertRaisesRegex(TypeError, r'^index\(', s.index,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1283 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1284 self.assertRaisesRegex(TypeError, r'^rindex\(', s.rindex,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1285 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1286 self.assertRaisesRegex(TypeError, r'^count\(', s.count,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1287 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1288 self.assertRaisesRegex(TypeError, r'^startswith\(', s.startswith,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1289 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1290 self.assertRaisesRegex(TypeError, r'^endswith\(', s.endswith,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1291 x, None, None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1292
33298
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1293
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1294 class MixinStrUnicodeTest:
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1295 # Additional tests that only work with str and unicode.
33298
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1296
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1297 def test_bug1001011(self):
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1298 # Make sure join returns a NEW object for single item sequences
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1299 # involving a subclass.
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1300 # Make sure that it is of the appropriate type.
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1301 # Check the optimisation still occurs for standard objects.
33298
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1302 t = self.type2test
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1303 class subclass(t):
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1304 pass
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1305 s1 = subclass("abcd")
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1306 s2 = t().join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1307 self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1308 self.assertIs(type(s2), t)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1309
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1310 s1 = t("abcd")
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1311 s2 = t().join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1312 self.assertIs(s1, s2)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1313
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1314 # Should also test mixed-type join.
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1315 if t is str:
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1316 s1 = subclass("abcd")
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1317 s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1318 self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1319 self.assertIs(type(s2), t)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1320
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1321 s1 = t("abcd")
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1322 s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1323 self.assertIs(s1, s2)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1324
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1325 ## elif t is str8:
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1326 ## s1 = subclass("abcd")
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1327 ## s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1328 ## self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1329 ## self.assertIs(type(s2), str) # promotes!
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1330
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1331 ## s1 = t("abcd")
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1332 ## s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1333 ## self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1334 ## self.assertIs(type(s2), str) # promotes!
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1335
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1336 else:
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1337 self.fail("unexpected type for MixinStrUnicodeTest %r" % t)