Mercurial > cpython-lru_cache-weakref
annotate Lib/test/string_tests.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | e98ee945e262 |
| children | 7c3b849d181a |
| 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 |
|
41589
37d82bee7a16
Fix those parts in the testsuite that assumed that sys.maxint would cause overflow on x64. Now the testsuite is well behaved on that platform.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41532
diff
changeset
|
5 import unittest, string, sys, struct |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
6 from test import test_support |
|
13527
07c31182f237
add more tests of string.join variants to run_method_tests
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13517
diff
changeset
|
7 from UserList import UserList |
|
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): |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
15 def __init__(self): self.seq = [7, 'hello', 123L] |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
16 |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
17 class BadSeq2(Sequence): |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
18 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
|
19 def __len__(self): return 8 |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
20 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
21 class CommonTest(unittest.TestCase): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
22 # This testcase contains test that can be used in all |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
23 # stringlike classes. Currently this is str, unicode |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
24 # UserString and 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
|
25 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
26 # 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
|
27 # 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
|
28 type2test = None |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
29 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
30 # 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
|
31 # 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
|
32 # 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 return dict([ |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
42 (self.fixtype(key), self.fixtype(value)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
43 for (key, value) in obj.iteritems() |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
44 ]) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
45 else: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
46 return obj |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
47 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
48 # check that object.method(*args) returns result |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
49 def checkequal(self, result, object, methodname, *args): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
50 result = self.fixtype(result) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
51 object = self.fixtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
52 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
|
53 realresult = getattr(object, methodname)(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
54 self.assertEqual( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
55 result, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
56 realresult |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
57 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
58 # 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
|
59 # this doesn't happen with subclasses |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
60 if object == realresult: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
61 class subtype(self.__class__.type2test): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
62 pass |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
63 object = subtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
64 realresult = getattr(object, methodname)(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
65 self.assert_(object is not realresult) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
66 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
67 # check that object.method(*args) raises exc |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
68 def checkraises(self, exc, object, methodname, *args): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
69 object = self.fixtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
70 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
|
71 self.assertRaises( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
72 exc, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
73 getattr(object, methodname), |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
74 *args |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
75 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
76 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
77 # call object.method(*args) without any checks |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
78 def checkcall(self, object, methodname, *args): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
79 object = self.fixtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
80 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
|
81 getattr(object, methodname)(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
82 |
|
33833
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
83 def test_hash(self): |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
84 # SF bug 1054139: += optimization was not invalidating cached hash value |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
85 a = self.type2test('DNSSEC') |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
86 b = self.type2test('') |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
87 for c in a: |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
88 b += c |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
89 hash(b) |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
90 self.assertEqual(hash(a), hash(b)) |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
91 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
92 def test_capitalize(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
93 self.checkequal(' hello ', ' hello ', 'capitalize') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
94 self.checkequal('Hello ', 'Hello ','capitalize') |
|
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('Hello ', 'hello ','capitalize') |
|
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('Aaaa', 'aaaa', 'capitalize') |
|
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('Aaaa', 'AaAa', 'capitalize') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
98 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
99 self.checkraises(TypeError, 'hello', 'capitalize', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
100 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 self.checkequal(0, 'aaa', 'count', 'b') |
|
38492
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
109 self.checkequal(2, 'aaa', 'count', 'a', 1) |
|
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
110 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
|
111 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
|
112 self.checkequal(3, 'aaa', 'count', 'a', -10) |
|
38492
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
113 self.checkequal(1, 'aaa', 'count', 'a', 0, 1) |
|
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
114 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
|
115 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
|
116 self.checkequal(0, 'aaa', 'count', 'a', 0, -10) |
|
38492
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
117 self.checkequal(3, 'aaa', 'count', '', 1) |
|
38516
2fe3233bd426
changed count to return 0 for slices outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38514
diff
changeset
|
118 self.checkequal(1, 'aaa', 'count', '', 3) |
|
2fe3233bd426
changed count to return 0 for slices outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38514
diff
changeset
|
119 self.checkequal(0, 'aaa', 'count', '', 10) |
|
38492
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
120 self.checkequal(2, 'aaa', 'count', '', -1) |
|
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
121 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
|
122 |
|
49308
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
123 self.checkequal(1, '', 'count', '') |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
124 self.checkequal(0, '', 'count', '', 1, 1) |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
125 self.checkequal(0, '', 'count', '', sys.maxint, 0) |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
126 |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
127 self.checkequal(0, '', 'count', 'xx') |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
128 self.checkequal(0, '', 'count', 'xx', 1, 1) |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
129 self.checkequal(0, '', 'count', 'xx', sys.maxint, 0) |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
130 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
131 self.checkraises(TypeError, 'hello', 'count') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
132 self.checkraises(TypeError, 'hello', 'count', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
133 |
|
34621
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
134 # For a variety of combinations, |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
135 # verify that str.count() matches an equivalent function |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
136 # 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
|
137 charset = ['', 'a', 'b'] |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
138 digits = 7 |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
139 base = len(charset) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
140 teststrings = set() |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
141 for i in xrange(base ** digits): |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
142 entry = [] |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
143 for j in xrange(digits): |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
144 i, m = divmod(i, base) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
145 entry.append(charset[m]) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
146 teststrings.add(''.join(entry)) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
147 teststrings = list(teststrings) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
148 for i in teststrings: |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
149 i = self.fixtype(i) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
150 n = len(i) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
151 for j in teststrings: |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
152 r1 = i.count(j) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
153 if j: |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
154 r2, rem = divmod(n - len(i.replace(j, '')), len(j)) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
155 else: |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
156 r2, rem = len(i)+1, 0 |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
157 if rem or r1 != r2: |
|
39302
041eb6231cdc
Bug #1515471: string.replace() accepts character buffers again.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38709
diff
changeset
|
158 self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i)) |
|
041eb6231cdc
Bug #1515471: string.replace() accepts character buffers again.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38709
diff
changeset
|
159 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
|
160 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 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
|
165 |
|
38514
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
166 self.checkequal(0, 'abc', 'find', '', 0) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
167 self.checkequal(3, 'abc', 'find', '', 3) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
168 self.checkequal(-1, 'abc', 'find', '', 4) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
169 |
|
43886
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
170 # to check the ability to pass None as defaults |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
171 self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a') |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
172 self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
173 self.checkequal(-1, 'rrarrrrrrrrra', 'find', 'a', 4, 6) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
174 self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4, None) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
175 self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
176 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
177 self.checkraises(TypeError, 'hello', 'find') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
178 self.checkraises(TypeError, 'hello', 'find', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
179 |
|
49308
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
180 self.checkequal(0, '', 'find', '') |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
181 self.checkequal(-1, '', 'find', '', 1, 1) |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
182 self.checkequal(-1, '', 'find', '', sys.maxint, 0) |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
183 |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
184 self.checkequal(-1, '', 'find', 'xx') |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
185 self.checkequal(-1, '', 'find', 'xx', 1, 1) |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
186 self.checkequal(-1, '', 'find', 'xx', sys.maxint, 0) |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48935
diff
changeset
|
187 |
|
34620
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
188 # For a variety of combinations, |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
189 # 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
|
190 # 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
|
191 charset = ['', 'a', 'b', 'c'] |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
192 digits = 5 |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
193 base = len(charset) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
194 teststrings = set() |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
195 for i in xrange(base ** digits): |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
196 entry = [] |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
197 for j in xrange(digits): |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
198 i, m = divmod(i, base) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
199 entry.append(charset[m]) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
200 teststrings.add(''.join(entry)) |
|
34621
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
201 teststrings = list(teststrings) |
|
34620
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
202 for i in teststrings: |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
203 i = self.fixtype(i) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
204 for j in teststrings: |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
205 loc = i.find(j) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
206 r1 = (loc != -1) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
207 r2 = j in i |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
208 if r1 != r2: |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
209 self.assertEqual(r1, r2) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
210 if loc != -1: |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
211 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
|
212 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 |
|
38514
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
219 self.checkequal(3, 'abc', 'rfind', '', 0) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
220 self.checkequal(3, 'abc', 'rfind', '', 3) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
221 self.checkequal(-1, 'abc', 'rfind', '', 4) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
222 |
|
43886
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
223 # to check the ability to pass None as defaults |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
224 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a') |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
225 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
226 self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', 'a', 4, 6) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
227 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4, None) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
228 self.checkequal( 2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
229 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
230 self.checkraises(TypeError, 'hello', 'rfind') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
231 self.checkraises(TypeError, 'hello', 'rfind', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
232 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 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
|
243 |
|
43886
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
244 # to check the ability to pass None as defaults |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
245 self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a') |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
246 self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
247 self.checkraises(ValueError, 'rrarrrrrrrrra', 'index', 'a', 4, 6) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
248 self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4, None) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
249 self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a', None, 6) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
250 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
251 self.checkraises(TypeError, 'hello', 'index') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
252 self.checkraises(TypeError, 'hello', 'index', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
253 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 |
|
43886
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
266 # to check the ability to pass None as defaults |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
267 self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a') |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
268 self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
269 self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', 'a', 4, 6) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
270 self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4, None) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
271 self.checkequal( 2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6) |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
42951
diff
changeset
|
272 |
|
28009
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(TypeError, 'hello', 'rindex') |
|
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(TypeError, 'hello', 'rindex', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
275 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
276 def test_lower(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
277 self.checkequal('hello', 'HeLLo', 'lower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
278 self.checkequal('hello', 'hello', 'lower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
279 self.checkraises(TypeError, 'hello', 'lower', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
280 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
281 def test_upper(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
282 self.checkequal('HELLO', 'HeLLo', 'upper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
283 self.checkequal('HELLO', 'HELLO', 'upper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
284 self.checkraises(TypeError, 'hello', 'upper', 42) |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
285 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
286 def test_expandtabs(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
287 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
288 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
289 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
290 self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi', 'expandtabs', 4) |
|
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('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs') |
|
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('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8) |
|
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('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4) |
|
42024
b94f284805be
Fix a bug when there was a newline in the string expandtabs was called on.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41589
diff
changeset
|
294 self.checkequal(' a\n b', ' \ta\n\tb', 'expandtabs', 1) |
|
28009
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(TypeError, 'hello', 'expandtabs', 42, 42) |
|
42024
b94f284805be
Fix a bug when there was a newline in the string expandtabs was called on.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41589
diff
changeset
|
297 # This test is only valid when sizeof(int) == sizeof(void*) == 4. |
|
b94f284805be
Fix a bug when there was a newline in the string expandtabs was called on.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41589
diff
changeset
|
298 if sys.maxint < (1 << 32) and struct.calcsize('P') == 4: |
|
b94f284805be
Fix a bug when there was a newline in the string expandtabs was called on.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41589
diff
changeset
|
299 self.checkraises(OverflowError, |
|
b94f284805be
Fix a bug when there was a newline in the string expandtabs was called on.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41589
diff
changeset
|
300 '\ta\n\tb', 'expandtabs', sys.maxint) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
301 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
302 def test_split(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
303 self.checkequal(['this', 'is', 'the', 'split', 'function'], |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
304 'this is the split function', 'split') |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
305 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
306 # by whitespace |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
307 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'split') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
308 self.checkequal(['a', 'b c d'], 'a b c d', 'split', None, 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
309 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
310 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
311 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 4) |
| 38356 | 312 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, |
| 313 sys.maxint-1) | |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
314 self.checkequal(['a b c d'], 'a b c d', 'split', None, 0) |
|
38373
4bfeab230e38
Test for more edge strip cases; leading and trailing separator gets removed
Andrew Dalke <dalke@dalkescientific.com>
parents:
38361
diff
changeset
|
315 self.checkequal(['a b c d'], ' a b c d', 'split', None, 0) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
316 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
317 |
|
38340
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
318 self.checkequal([], ' ', 'split') |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
319 self.checkequal(['a'], ' a ', 'split') |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
320 self.checkequal(['a', 'b'], ' a b ', 'split') |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
321 self.checkequal(['a', 'b '], ' a b ', 'split', None, 1) |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
322 self.checkequal(['a', 'b c '], ' a b c ', 'split', None, 1) |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
323 self.checkequal(['a', 'b', 'c '], ' a b c ', 'split', None, 2) |
|
38342
5382aaf3a0da
Added split whitespace checks for characters other than space.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38340
diff
changeset
|
324 self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'split') |
| 38356 | 325 aaa = ' a '*20 |
| 326 self.checkequal(['a']*20, aaa, 'split') | |
| 327 self.checkequal(['a'] + [aaa[4:]], aaa, 'split', None, 1) | |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
328 self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19) |
|
38340
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
329 |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
330 # by a char |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
331 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|') |
| 38356 | 332 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
|
333 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
|
334 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
|
335 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
|
336 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 4) |
| 38356 | 337 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', |
| 338 sys.maxint-2) | |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
339 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
|
340 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
|
341 self.checkequal(['endcase ', ''], 'endcase |', 'split', '|') |
| 38356 | 342 self.checkequal(['', ' startcase'], '| startcase', 'split', '|') |
| 343 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
|
344 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
|
345 |
| 38356 | 346 self.checkequal(['a']*20, ('a|'*20)[:-1], 'split', '|') |
| 347 self.checkequal(['a']*15 +['a|a|a|a|a'], | |
| 348 ('a|'*20)[:-1], 'split', '|', 15) | |
| 349 | |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
350 # 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
|
351 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
|
352 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
|
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(['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
|
355 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 4) |
| 38356 | 356 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', |
| 357 sys.maxint-10) | |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
358 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
|
359 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
|
360 self.checkequal(['endcase ', ''], 'endcase test', 'split', 'test') |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
361 self.checkequal(['', ' begincase'], 'test begincase', 'split', 'test') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
362 self.checkequal(['', ' bothcase ', ''], 'test bothcase test', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
363 'split', 'test') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
364 self.checkequal(['a', 'bc'], 'abbbc', 'split', 'bb') |
| 38356 | 365 self.checkequal(['', ''], 'aaa', 'split', 'aaa') |
| 366 self.checkequal(['aaa'], 'aaa', 'split', 'aaa', 0) | |
| 367 self.checkequal(['ab', 'ab'], 'abbaab', 'split', 'ba') | |
| 368 self.checkequal(['aaaa'], 'aaaa', 'split', 'aab') | |
| 369 self.checkequal([''], '', 'split', 'aaa') | |
| 370 self.checkequal(['aa'], 'aa', 'split', 'aaa') | |
|
38357
be7415b0a318
Test cases for off-by-one errors in string split with multicharacter pattern.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38356
diff
changeset
|
371 self.checkequal(['A', 'bobb'], 'Abbobbbobb', 'split', 'bbobb') |
|
be7415b0a318
Test cases for off-by-one errors in string split with multicharacter pattern.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38356
diff
changeset
|
372 self.checkequal(['A', 'B', ''], 'AbbobbBbbobb', 'split', 'bbobb') |
| 38356 | 373 |
| 374 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH') | |
| 375 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH', 19) | |
| 376 self.checkequal(['a']*18 + ['aBLAHa'], ('aBLAH'*20)[:-4], | |
| 377 '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
|
378 |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
379 # mixed use of str and unicode |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
380 self.checkequal([u'a', u'b', u'c d'], 'a b c d', 'split', u' ', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
381 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
382 # 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
|
383 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
|
384 |
| 38356 | 385 # null case |
| 386 self.checkraises(ValueError, 'hello', 'split', '') | |
| 387 self.checkraises(ValueError, 'hello', 'split', '', 0) | |
| 388 | |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
389 def test_rsplit(self): |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
390 self.checkequal(['this', 'is', 'the', 'rsplit', 'function'], |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
391 'this is the rsplit function', 'rsplit') |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
392 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
393 # by whitespace |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
394 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'rsplit') |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
395 self.checkequal(['a b c', 'd'], 'a b c d', 'rsplit', None, 1) |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
396 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2) |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
397 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 3) |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
398 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 4) |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
399 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
400 sys.maxint-20) |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
401 self.checkequal(['a b c d'], 'a b c d', 'rsplit', None, 0) |
|
38373
4bfeab230e38
Test for more edge strip cases; leading and trailing separator gets removed
Andrew Dalke <dalke@dalkescientific.com>
parents:
38361
diff
changeset
|
402 self.checkequal(['a b c d'], 'a b c d ', 'rsplit', None, 0) |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
403 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
404 |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
405 self.checkequal([], ' ', 'rsplit') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
406 self.checkequal(['a'], ' a ', 'rsplit') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
407 self.checkequal(['a', 'b'], ' a b ', 'rsplit') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
408 self.checkequal([' a', 'b'], ' a b ', 'rsplit', None, 1) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
409 self.checkequal([' a b','c'], ' a b c ', 'rsplit', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
410 None, 1) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
411 self.checkequal([' a', 'b', 'c'], ' a b c ', 'rsplit', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
412 None, 2) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
413 self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'rsplit', None, 88) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
414 aaa = ' a '*20 |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
415 self.checkequal(['a']*20, aaa, 'rsplit') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
416 self.checkequal([aaa[:-4]] + ['a'], aaa, 'rsplit', None, 1) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
417 self.checkequal([' a a'] + ['a']*18, aaa, 'rsplit', None, 18) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
418 |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
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 a char |
|
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) |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
426 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
427 sys.maxint-100) |
|
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'], '| begincase', 'rsplit', '|') |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
431 self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
432 self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
433 |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
434 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
|
435 |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
436 self.checkequal(['a']*20, ('a|'*20)[:-1], 'rsplit', '|') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
437 self.checkequal(['a|a|a|a|a']+['a']*15, |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
438 ('a|'*20)[:-1], 'rsplit', '|', 15) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
439 |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
440 # by string |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
441 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
|
442 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
|
443 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
|
444 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
|
445 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 4) |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
446 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
447 sys.maxint-5) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
448 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
|
449 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
|
450 self.checkequal(['', ' begincase'], 'test begincase', 'rsplit', 'test') |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
451 self.checkequal(['endcase ', ''], 'endcase test', 'rsplit', 'test') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
452 self.checkequal(['', ' bothcase ', ''], 'test bothcase test', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
453 'rsplit', 'test') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
454 self.checkequal(['ab', 'c'], 'abbbc', 'rsplit', 'bb') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
455 self.checkequal(['', ''], 'aaa', 'rsplit', 'aaa') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
456 self.checkequal(['aaa'], 'aaa', 'rsplit', 'aaa', 0) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
457 self.checkequal(['ab', 'ab'], 'abbaab', 'rsplit', 'ba') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
458 self.checkequal(['aaaa'], 'aaaa', 'rsplit', 'aab') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
459 self.checkequal([''], '', 'rsplit', 'aaa') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
460 self.checkequal(['aa'], 'aa', 'rsplit', 'aaa') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
461 self.checkequal(['bbob', 'A'], 'bbobbbobbA', 'rsplit', 'bbobb') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
462 self.checkequal(['', 'B', 'A'], 'bbobbBbbobbA', 'rsplit', 'bbobb') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
463 |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
464 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
465 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH', 19) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
466 self.checkequal(['aBLAHa'] + ['a']*18, ('aBLAH'*20)[:-4], |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
467 'rsplit', 'BLAH', 18) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
468 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
469 # mixed use of str and unicode |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
470 self.checkequal([u'a b', u'c', u'd'], 'a b c d', 'rsplit', u' ', 2) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
471 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
472 # argument type |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
473 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
|
474 |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
475 # null case |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
476 self.checkraises(ValueError, 'hello', 'rsplit', '') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
477 self.checkraises(ValueError, 'hello', 'rsplit', '', 0) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
478 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
479 def test_strip(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
480 self.checkequal('hello', ' hello ', 'strip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
481 self.checkequal('hello ', ' hello ', 'lstrip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
482 self.checkequal(' hello', ' hello ', 'rstrip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
483 self.checkequal('hello', 'hello', 'strip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
484 |
|
28575
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
485 # strip/lstrip/rstrip with None arg |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
486 self.checkequal('hello', ' hello ', 'strip', None) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
487 self.checkequal('hello ', ' hello ', 'lstrip', None) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
488 self.checkequal(' hello', ' hello ', 'rstrip', None) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
489 self.checkequal('hello', 'hello', 'strip', None) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
490 |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
491 # strip/lstrip/rstrip with str arg |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
492 self.checkequal('hello', 'xyzzyhelloxyzzy', 'strip', 'xyz') |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
493 self.checkequal('helloxyzzy', 'xyzzyhelloxyzzy', 'lstrip', 'xyz') |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
494 self.checkequal('xyzzyhello', 'xyzzyhelloxyzzy', 'rstrip', 'xyz') |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
495 self.checkequal('hello', 'hello', 'strip', 'xyz') |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
496 |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
497 # strip/lstrip/rstrip with unicode arg |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
498 if test_support.have_unicode: |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
499 self.checkequal(unicode('hello', 'ascii'), 'xyzzyhelloxyzzy', |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
500 'strip', unicode('xyz', 'ascii')) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
501 self.checkequal(unicode('helloxyzzy', 'ascii'), 'xyzzyhelloxyzzy', |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
502 'lstrip', unicode('xyz', 'ascii')) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
503 self.checkequal(unicode('xyzzyhello', 'ascii'), 'xyzzyhelloxyzzy', |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
504 'rstrip', unicode('xyz', 'ascii')) |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45500
diff
changeset
|
505 # XXX |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45500
diff
changeset
|
506 #self.checkequal(unicode('hello', 'ascii'), 'hello', |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45500
diff
changeset
|
507 # 'strip', unicode('xyz', 'ascii')) |
|
28575
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
508 |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
509 self.checkraises(TypeError, 'hello', 'strip', 42, 42) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
510 self.checkraises(TypeError, 'hello', 'lstrip', 42, 42) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
511 self.checkraises(TypeError, 'hello', 'rstrip', 42, 42) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
512 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
513 def test_ljust(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
514 self.checkequal('abc ', 'abc', 'ljust', 10) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
515 self.checkequal('abc ', 'abc', 'ljust', 6) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
516 self.checkequal('abc', 'abc', 'ljust', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
517 self.checkequal('abc', 'abc', 'ljust', 2) |
|
31021
21a10c3600b5
Add optional fillchar argument to ljust(), rjust(), and center() string methods.
Raymond Hettinger <python@rcn.com>
parents:
30216
diff
changeset
|
518 self.checkequal('abc*******', 'abc', 'ljust', 10, '*') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
519 self.checkraises(TypeError, 'abc', 'ljust') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
520 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
521 def test_rjust(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
522 self.checkequal(' abc', 'abc', 'rjust', 10) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
523 self.checkequal(' abc', 'abc', 'rjust', 6) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
524 self.checkequal('abc', 'abc', 'rjust', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
525 self.checkequal('abc', 'abc', 'rjust', 2) |
|
31021
21a10c3600b5
Add optional fillchar argument to ljust(), rjust(), and center() string methods.
Raymond Hettinger <python@rcn.com>
parents:
30216
diff
changeset
|
526 self.checkequal('*******abc', 'abc', 'rjust', 10, '*') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
527 self.checkraises(TypeError, 'abc', 'rjust') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
528 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
529 def test_center(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
530 self.checkequal(' abc ', 'abc', 'center', 10) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
531 self.checkequal(' abc ', 'abc', 'center', 6) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
532 self.checkequal('abc', 'abc', 'center', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
533 self.checkequal('abc', 'abc', 'center', 2) |
|
31021
21a10c3600b5
Add optional fillchar argument to ljust(), rjust(), and center() string methods.
Raymond Hettinger <python@rcn.com>
parents:
30216
diff
changeset
|
534 self.checkequal('***abc****', 'abc', 'center', 10, '*') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
535 self.checkraises(TypeError, 'abc', 'center') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
536 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
537 def test_swapcase(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
538 self.checkequal('hEllO CoMPuTErS', 'HeLLo cOmpUteRs', 'swapcase') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
539 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
540 self.checkraises(TypeError, 'hello', 'swapcase', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
541 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
542 def test_replace(self): |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
543 EQ = self.checkequal |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
544 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
545 # Operations on the empty string |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
546 EQ("", "", "replace", "", "") |
|
38539
b9b036f02207
Re-enable a new empty-string test added during the NFS sprint,
Tim Peters <tim.peters@gmail.com>
parents:
38516
diff
changeset
|
547 EQ("A", "", "replace", "", "A") |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
548 EQ("", "", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
549 EQ("", "", "replace", "A", "A") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
550 EQ("", "", "replace", "", "", 100) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
551 EQ("", "", "replace", "", "", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
552 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
553 # interleave (from=="", 'to' gets inserted everywhere) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
554 EQ("A", "A", "replace", "", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
555 EQ("*A*", "A", "replace", "", "*") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
556 EQ("*1A*1", "A", "replace", "", "*1") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
557 EQ("*-#A*-#", "A", "replace", "", "*-#") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
558 EQ("*-A*-A*-", "AA", "replace", "", "*-") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
559 EQ("*-A*-A*-", "AA", "replace", "", "*-", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
560 EQ("*-A*-A*-", "AA", "replace", "", "*-", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
561 EQ("*-A*-A*-", "AA", "replace", "", "*-", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
562 EQ("*-A*-A*-", "AA", "replace", "", "*-", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
563 EQ("*-A*-A", "AA", "replace", "", "*-", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
564 EQ("*-AA", "AA", "replace", "", "*-", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
565 EQ("AA", "AA", "replace", "", "*-", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
566 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
567 # single character deletion (from=="A", to=="") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
568 EQ("", "A", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
569 EQ("", "AAA", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
570 EQ("", "AAA", "replace", "A", "", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
571 EQ("", "AAA", "replace", "A", "", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
572 EQ("", "AAA", "replace", "A", "", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
573 EQ("", "AAA", "replace", "A", "", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
574 EQ("A", "AAA", "replace", "A", "", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
575 EQ("AA", "AAA", "replace", "A", "", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
576 EQ("AAA", "AAA", "replace", "A", "", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
577 EQ("", "AAAAAAAAAA", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
578 EQ("BCD", "ABACADA", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
579 EQ("BCD", "ABACADA", "replace", "A", "", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
580 EQ("BCD", "ABACADA", "replace", "A", "", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
581 EQ("BCD", "ABACADA", "replace", "A", "", 5) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
582 EQ("BCD", "ABACADA", "replace", "A", "", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
583 EQ("BCDA", "ABACADA", "replace", "A", "", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
584 EQ("BCADA", "ABACADA", "replace", "A", "", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
585 EQ("BACADA", "ABACADA", "replace", "A", "", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
586 EQ("ABACADA", "ABACADA", "replace", "A", "", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
587 EQ("BCD", "ABCAD", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
588 EQ("BCD", "ABCADAA", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
589 EQ("BCD", "BCD", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
590 EQ("*************", "*************", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
591 EQ("^A^", "^"+"A"*1000+"^", "replace", "A", "", 999) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
592 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
593 # substring deletion (from=="the", to=="") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
594 EQ("", "the", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
595 EQ("ater", "theater", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
596 EQ("", "thethe", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
597 EQ("", "thethethethe", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
598 EQ("aaaa", "theatheatheathea", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
599 EQ("that", "that", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
600 EQ("thaet", "thaet", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
601 EQ("here and re", "here and there", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
602 EQ("here and re and re", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
603 "replace", "the", "", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
604 EQ("here and re and re", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
605 "replace", "the", "", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
606 EQ("here and re and re", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
607 "replace", "the", "", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
608 EQ("here and re and re", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
609 "replace", "the", "", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
610 EQ("here and re and there", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
611 "replace", "the", "", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
612 EQ("here and there and there", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
613 "replace", "the", "", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
614 EQ("here and re and re", "here and there and there", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
615 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
616 EQ("abc", "abc", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
617 EQ("abcdefg", "abcdefg", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
618 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
619 # substring deletion (from=="bob", to=="") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
620 EQ("bob", "bbobob", "replace", "bob", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
621 EQ("bobXbob", "bbobobXbbobob", "replace", "bob", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
622 EQ("aaaaaaa", "aaaaaaabob", "replace", "bob", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
623 EQ("aaaaaaa", "aaaaaaa", "replace", "bob", "") |
|
38280
32ba3a0c6040
We can't leave the checked-in tests broken.
Tim Peters <tim.peters@gmail.com>
parents:
38279
diff
changeset
|
624 |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
625 # single character replace in place (len(from)==len(to)==1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
626 EQ("Who goes there?", "Who goes there?", "replace", "o", "o") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
627 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
628 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
629 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
630 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
631 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
632 EQ("WhO goes there?", "Who goes there?", "replace", "o", "O", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
633 EQ("Who goes there?", "Who goes there?", "replace", "o", "O", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
634 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
635 EQ("Who goes there?", "Who goes there?", "replace", "a", "q") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
636 EQ("who goes there?", "Who goes there?", "replace", "W", "w") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
637 EQ("wwho goes there?ww", "WWho goes there?WW", "replace", "W", "w") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
638 EQ("Who goes there!", "Who goes there?", "replace", "?", "!") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
639 EQ("Who goes there!!", "Who goes there??", "replace", "?", "!") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
640 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
641 EQ("Who goes there?", "Who goes there?", "replace", ".", "!") |
|
38280
32ba3a0c6040
We can't leave the checked-in tests broken.
Tim Peters <tim.peters@gmail.com>
parents:
38279
diff
changeset
|
642 |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
643 # substring replace in place (len(from)==len(to) > 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
644 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
645 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
646 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
647 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
648 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
649 EQ("Th** ** a tissue", "This is a tissue", "replace", "is", "**", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
650 EQ("Th** is a tissue", "This is a tissue", "replace", "is", "**", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
651 EQ("This is a tissue", "This is a tissue", "replace", "is", "**", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
652 EQ("cobob", "bobob", "replace", "bob", "cob") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
653 EQ("cobobXcobocob", "bobobXbobobob", "replace", "bob", "cob") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
654 EQ("bobob", "bobob", "replace", "bot", "bot") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
655 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
656 # replace single character (len(from)==1, len(to)>1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
657 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
658 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
659 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
660 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
661 EQ("ReyKKjavik", "Reykjavik", "replace", "k", "KK", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
662 EQ("Reykjavik", "Reykjavik", "replace", "k", "KK", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
663 EQ("A----B----C----", "A.B.C.", "replace", ".", "----") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
664 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
665 EQ("Reykjavik", "Reykjavik", "replace", "q", "KK") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
666 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
667 # replace substring (len(from)>1, len(to)!=len(from)) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
668 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
669 "replace", "spam", "ham") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
670 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
671 "replace", "spam", "ham", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
672 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
673 "replace", "spam", "ham", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
674 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
675 "replace", "spam", "ham", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
676 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
677 "replace", "spam", "ham", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
678 EQ("ham, ham, eggs and spam", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
679 "replace", "spam", "ham", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
680 EQ("ham, spam, eggs and spam", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
681 "replace", "spam", "ham", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
682 EQ("spam, spam, eggs and spam", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
683 "replace", "spam", "ham", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
684 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
685 EQ("bobob", "bobobob", "replace", "bobob", "bob") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
686 EQ("bobobXbobob", "bobobobXbobobob", "replace", "bobob", "bob") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
687 EQ("BOBOBOB", "BOBOBOB", "replace", "bob", "bobby") |
|
38280
32ba3a0c6040
We can't leave the checked-in tests broken.
Tim Peters <tim.peters@gmail.com>
parents:
38279
diff
changeset
|
688 |
|
39302
041eb6231cdc
Bug #1515471: string.replace() accepts character buffers again.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38709
diff
changeset
|
689 ba = buffer('a') |
|
041eb6231cdc
Bug #1515471: string.replace() accepts character buffers again.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38709
diff
changeset
|
690 bb = buffer('b') |
|
041eb6231cdc
Bug #1515471: string.replace() accepts character buffers again.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38709
diff
changeset
|
691 EQ("bbc", "abc", "replace", ba, bb) |
|
041eb6231cdc
Bug #1515471: string.replace() accepts character buffers again.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38709
diff
changeset
|
692 EQ("aac", "abc", "replace", bb, ba) |
|
041eb6231cdc
Bug #1515471: string.replace() accepts character buffers again.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38709
diff
changeset
|
693 |
|
38280
32ba3a0c6040
We can't leave the checked-in tests broken.
Tim Peters <tim.peters@gmail.com>
parents:
38279
diff
changeset
|
694 # |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
695 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
|
696 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
|
697 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
|
698 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
|
699 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
|
700 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
|
701 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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 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
|
709 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
|
710 # 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
|
711 # 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
|
712 # 0 bytes). |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
713 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
|
714 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
|
715 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
|
716 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
717 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
|
718 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
|
719 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
|
720 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
|
721 |
|
38299
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
722 def test_replace_overflow(self): |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
723 # Check for overflow checking on 32 bit machines |
|
41589
37d82bee7a16
Fix those parts in the testsuite that assumed that sys.maxint would cause overflow on x64. Now the testsuite is well behaved on that platform.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41532
diff
changeset
|
724 if sys.maxint != 2147483647 or struct.calcsize("P") > 4: |
|
38299
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
725 return |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
726 A2_16 = "A" * (2**16) |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
727 self.checkraises(OverflowError, A2_16, "replace", "", A2_16) |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
728 self.checkraises(OverflowError, A2_16, "replace", "A", A2_16) |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
729 self.checkraises(OverflowError, A2_16, "replace", "AA", A2_16+A2_16) |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
730 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
731 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
|
732 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
|
733 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
|
734 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
|
735 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
|
736 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
|
737 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
|
738 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
|
739 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
|
740 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
|
741 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
|
742 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
|
743 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
|
744 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
745 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
|
746 |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45500
diff
changeset
|
747 # XXX alias for py3k forward compatibility |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45500
diff
changeset
|
748 BaseTest = CommonTest |
|
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45500
diff
changeset
|
749 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
750 class MixinStrUnicodeUserStringTest: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
751 # 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
|
752 # 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
|
753 # (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
|
754 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
755 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
|
756 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
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 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
|
763 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
|
764 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
765 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
|
766 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
|
767 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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 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
|
773 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
|
774 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
775 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
|
776 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
|
777 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
|
778 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
|
779 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
|
780 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
|
781 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
|
782 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
|
783 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
|
784 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
|
785 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
|
786 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
|
787 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
|
788 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
789 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
|
790 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
|
791 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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 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
|
799 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
800 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 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
|
806 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
|
807 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
|
808 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
|
809 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
810 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
|
811 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
|
812 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
|
813 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
|
814 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
|
815 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
|
816 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
|
817 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
|
818 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
|
819 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
|
820 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
821 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
|
822 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
|
823 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
|
824 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
|
825 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
|
826 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
|
827 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
828 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
|
829 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
830 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
|
831 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
|
832 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
|
833 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
|
834 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
|
835 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
|
836 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
|
837 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
|
838 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
839 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
|
840 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
|
841 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
|
842 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
|
843 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
|
844 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
|
845 self.checkequal(['', 'abc', 'def', 'ghi', ''], "\nabc\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
|
846 self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'], "\nabc\ndef\r\nghi\n\r", 'splitlines', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
847 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
848 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
|
849 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
850 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
|
851 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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 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
|
858 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
|
859 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
|
860 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
|
861 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
|
862 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
|
863 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
|
864 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
865 # 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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 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
|
871 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
|
872 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
|
873 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
|
874 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
|
875 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
|
876 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
877 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
|
878 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
|
879 |
|
38697
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
880 # test tuple arguments |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
881 self.checkequal(True, 'hello', 'startswith', ('he', 'ha')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
882 self.checkequal(False, 'hello', 'startswith', ('lo', 'llo')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
883 self.checkequal(True, 'hello', 'startswith', ('hellox', 'hello')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
884 self.checkequal(False, 'hello', 'startswith', ()) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
885 self.checkequal(True, 'helloworld', 'startswith', ('hellowo', |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
886 'rld', 'lowo'), 3) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
887 self.checkequal(False, 'helloworld', 'startswith', ('hellowo', 'ello', |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
888 'rld'), 3) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
889 self.checkequal(True, 'hello', 'startswith', ('lo', 'he'), 0, -1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
890 self.checkequal(False, 'hello', 'startswith', ('he', 'hel'), 0, 1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
891 self.checkequal(True, 'hello', 'startswith', ('he', 'hel'), 0, 2) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
892 |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
893 self.checkraises(TypeError, 'hello', 'startswith', (42,)) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
894 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
895 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
|
896 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
|
897 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
|
898 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
|
899 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
|
900 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
|
901 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
|
902 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
|
903 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
|
904 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
|
905 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
|
906 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
|
907 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
|
908 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
|
909 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
|
910 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
911 # 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
|
912 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
|
913 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
|
914 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
|
915 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
|
916 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
|
917 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
|
918 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
|
919 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
|
920 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
|
921 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
|
922 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
|
923 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
|
924 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
|
925 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
926 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
|
927 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
|
928 |
|
38697
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
929 # test tuple arguments |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
930 self.checkequal(False, 'hello', 'endswith', ('he', 'ha')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
931 self.checkequal(True, 'hello', 'endswith', ('lo', 'llo')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
932 self.checkequal(True, 'hello', 'endswith', ('hellox', 'hello')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
933 self.checkequal(False, 'hello', 'endswith', ()) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
934 self.checkequal(True, 'helloworld', 'endswith', ('hellowo', |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
935 'rld', 'lowo'), 3) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
936 self.checkequal(False, 'helloworld', 'endswith', ('hellowo', 'ello', |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
937 'rld'), 3, -1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
938 self.checkequal(True, 'hello', 'endswith', ('hell', 'ell'), 0, -1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
939 self.checkequal(False, 'hello', 'endswith', ('he', 'hel'), 0, 1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
940 self.checkequal(True, 'hello', 'endswith', ('he', 'hell'), 0, 4) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
941 |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
942 self.checkraises(TypeError, 'hello', 'endswith', (42,)) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
943 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
944 def test___contains__(self): |
|
58475
e98ee945e262
Merged revisions 77729 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49308
diff
changeset
|
945 self.checkequal(True, '', '__contains__', '') |
|
e98ee945e262
Merged revisions 77729 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49308
diff
changeset
|
946 self.checkequal(True, 'abc', '__contains__', '') |
|
e98ee945e262
Merged revisions 77729 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49308
diff
changeset
|
947 self.checkequal(False, 'abc', '__contains__', '\0') |
|
e98ee945e262
Merged revisions 77729 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49308
diff
changeset
|
948 self.checkequal(True, '\0abc', '__contains__', '\0') |
|
e98ee945e262
Merged revisions 77729 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49308
diff
changeset
|
949 self.checkequal(True, 'abc\0', '__contains__', '\0') |
|
e98ee945e262
Merged revisions 77729 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49308
diff
changeset
|
950 self.checkequal(True, '\0abc', '__contains__', 'a') |
|
e98ee945e262
Merged revisions 77729 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49308
diff
changeset
|
951 self.checkequal(True, 'asdf', '__contains__', 'asdf') |
|
e98ee945e262
Merged revisions 77729 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49308
diff
changeset
|
952 self.checkequal(False, 'asd', '__contains__', 'asdf') |
|
e98ee945e262
Merged revisions 77729 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49308
diff
changeset
|
953 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
|
954 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
955 def test_subscript(self): |
|
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(u'a', 'abc', '__getitem__', 0) |
|
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(u'c', 'abc', '__getitem__', -1) |
|
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(u'a', 'abc', '__getitem__', 0L) |
|
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(u'abc', 'abc', '__getitem__', slice(0, 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(u'abc', 'abc', '__getitem__', slice(0, 1000)) |
|
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(u'a', 'abc', '__getitem__', slice(0, 1)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
962 self.checkequal(u'', 'abc', '__getitem__', slice(0, 0)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
963 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
964 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
|
965 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
966 def test_slice(self): |
|
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('abc', 'abc', '__getslice__', 0, 1000) |
|
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('abc', 'abc', '__getslice__', 0, 3) |
|
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('ab', 'abc', '__getslice__', 0, 2) |
|
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('bc', 'abc', '__getslice__', 1, 3) |
|
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('b', 'abc', '__getslice__', 1, 2) |
|
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('', 'abc', '__getslice__', 2, 2) |
|
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('', 'abc', '__getslice__', 1000, 1000) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
974 self.checkequal('', 'abc', '__getslice__', 2000, 1000) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
975 self.checkequal('', 'abc', '__getslice__', 2, 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
976 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
977 self.checkraises(TypeError, 'abc', '__getslice__', 'def') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
978 |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
979 def test_extended_getslice(self): |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
980 # Test extended slicing by comparing with list slicing. |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
981 s = string.ascii_letters + string.digits |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
982 indices = (0, None, 1, 3, 41, -1, -2, -37) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
983 for start in indices: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
984 for stop in indices: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
985 # Skip step 0 (invalid) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
986 for step in indices[1:]: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
987 L = list(s)[start:stop:step] |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
988 self.checkequal(u"".join(L), s, '__getitem__', |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
989 slice(start, stop, step)) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
42024
diff
changeset
|
990 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
991 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
|
992 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
|
993 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
|
994 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
|
995 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
|
996 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
|
997 self.checkraises(TypeError, 'abc', '__mul__', '') |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35758
diff
changeset
|
998 # 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
|
999 # 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
|
1000 #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
|
1001 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1002 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
|
1003 # 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
|
1004 # 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
|
1005 # 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
|
1006 # 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
|
1007 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
|
1008 self.checkequal('abcd', '', 'join', ('a', 'b', 'c', 'd')) |
|
38709
67450db26f81
Apply perky's fix for #1503157: "/".join([u"", u""]) raising OverflowError.
Georg Brandl <georg@python.org>
parents:
38697
diff
changeset
|
1009 self.checkequal('bd', '', 'join', ('', 'b', '', 'd')) |
|
67450db26f81
Apply perky's fix for #1503157: "/".join([u"", u""]) raising OverflowError.
Georg Brandl <georg@python.org>
parents:
38697
diff
changeset
|
1010 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
|
1011 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
|
1012 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
|
1013 self.checkequal('z', 'a', 'join', UserList(['z'])) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1014 if test_support.have_unicode: |
|
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(unicode('a.b.c'), unicode('.'), 'join', ['a', 'b', 'c']) |
|
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(unicode('a.b.c'), '.', 'join', [unicode('a'), 'b', 'c']) |
|
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(unicode('a.b.c'), '.', 'join', ['a', unicode('b'), 'c']) |
|
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(unicode('a.b.c'), '.', 'join', ['a', 'b', unicode('c')]) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1019 self.checkraises(TypeError, '.', 'join', ['a', unicode('b'), 3]) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1020 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
|
1021 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
|
1022 ['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
|
1023 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
|
1024 ('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
|
1025 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1026 self.checkraises(TypeError, ' ', 'join', BadSeq1()) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1027 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
|
1028 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1029 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
|
1030 self.checkraises(TypeError, ' ', 'join', 7) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1031 self.checkraises(TypeError, ' ', 'join', Sequence([7, 'hello', 123L])) |
| 35758 | 1032 try: |
| 1033 def f(): | |
| 1034 yield 4 + "" | |
| 1035 self.fixtype(' ').join(f()) | |
| 1036 except TypeError, e: | |
| 1037 if '+' not in str(e): | |
| 1038 self.fail('join() ate exception message') | |
| 1039 else: | |
| 1040 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
|
1041 |
|
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_formatting(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1043 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
|
1044 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
|
1045 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
|
1046 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
|
1047 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
|
1048 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
|
1049 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
|
1050 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
|
1051 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1052 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
|
1053 # 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
|
1054 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
|
1055 |
|
45500
c03aff6d07f5
Issue 1742669. Now %d accepts very big float numbers.
Facundo Batista <facundobatista@gmail.com>
parents:
43886
diff
changeset
|
1056 longvalue = sys.maxint + 10L |
|
c03aff6d07f5
Issue 1742669. Now %d accepts very big float numbers.
Facundo Batista <facundobatista@gmail.com>
parents:
43886
diff
changeset
|
1057 slongvalue = str(longvalue) |
|
c03aff6d07f5
Issue 1742669. Now %d accepts very big float numbers.
Facundo Batista <facundobatista@gmail.com>
parents:
43886
diff
changeset
|
1058 if slongvalue[-1] in ("L","l"): slongvalue = slongvalue[:-1] |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1059 self.checkequal(' 42', '%3ld', '__mod__', 42) |
|
45500
c03aff6d07f5
Issue 1742669. Now %d accepts very big float numbers.
Facundo Batista <facundobatista@gmail.com>
parents:
43886
diff
changeset
|
1060 self.checkequal('42', '%d', '__mod__', 42L) |
|
c03aff6d07f5
Issue 1742669. Now %d accepts very big float numbers.
Facundo Batista <facundobatista@gmail.com>
parents:
43886
diff
changeset
|
1061 self.checkequal('42', '%d', '__mod__', 42.0) |
|
c03aff6d07f5
Issue 1742669. Now %d accepts very big float numbers.
Facundo Batista <facundobatista@gmail.com>
parents:
43886
diff
changeset
|
1062 self.checkequal(slongvalue, '%d', '__mod__', longvalue) |
|
c03aff6d07f5
Issue 1742669. Now %d accepts very big float numbers.
Facundo Batista <facundobatista@gmail.com>
parents:
43886
diff
changeset
|
1063 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
|
1064 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
|
1065 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
|
1066 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1067 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
|
1068 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
|
1069 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
|
1070 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
|
1071 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
|
1072 self.checkraises(TypeError, '%(foo)s %(bar)s', '__mod__', ('foo', 42)) |
|
45500
c03aff6d07f5
Issue 1742669. Now %d accepts very big float numbers.
Facundo Batista <facundobatista@gmail.com>
parents:
43886
diff
changeset
|
1073 self.checkraises(TypeError, '%d', '__mod__', "42") # not numeric |
|
c03aff6d07f5
Issue 1742669. Now %d accepts very big float numbers.
Facundo Batista <facundobatista@gmail.com>
parents:
43886
diff
changeset
|
1074 self.checkraises(TypeError, '%d', '__mod__', (42+0j)) # no int/long 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
|
1075 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1076 # 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
|
1077 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
|
1078 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1079 # 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
|
1080 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
|
1081 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1082 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
|
1083 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
|
1084 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
|
1085 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1086 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
|
1087 # float formatting |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1088 for prec in xrange(100): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1089 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
|
1090 value = 0.01 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1091 for x in xrange(60): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1092 value = value * 3.141592655 / 3.0 * 10.0 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1093 # The formatfloat() code in stringobject.c and |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1094 # unicodeobject.c uses a 120 byte buffer and switches from |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1095 # 'f' formatting to 'g' at precision 50, so we expect |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1096 # OverflowErrors for the ranges x < 50 and prec >= 67. |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1097 if x < 50 and prec >= 67: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1098 self.checkraises(OverflowError, format, "__mod__", value) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1099 else: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1100 self.checkcall(format, "__mod__", value) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1101 |
|
38296
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1102 def test_inplace_rewrites(self): |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1103 # Check that strings don't copy and modify cached single-character strings |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1104 self.checkequal('a', 'A', 'lower') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1105 self.checkequal(True, 'A', 'isupper') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1106 self.checkequal('A', 'a', 'upper') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1107 self.checkequal(True, 'a', 'islower') |
|
38327
e9eb526b7111
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
38299
diff
changeset
|
1108 |
|
38296
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1109 self.checkequal('a', 'A', 'replace', 'A', 'a') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1110 self.checkequal(True, 'A', 'isupper') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1111 |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1112 self.checkequal('A', 'a', 'capitalize') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1113 self.checkequal(True, 'a', 'islower') |
|
38327
e9eb526b7111
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
38299
diff
changeset
|
1114 |
|
38296
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1115 self.checkequal('A', 'a', 'swapcase') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1116 self.checkequal(True, 'a', 'islower') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1117 |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1118 self.checkequal('A', 'a', 'title') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1119 self.checkequal(True, 'a', 'islower') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1120 |
|
38335
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1121 def test_partition(self): |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1122 |
|
38391
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1123 self.checkequal(('this is the par', 'ti', 'tion method'), |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1124 'this is the partition method', 'partition', 'ti') |
|
38335
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1125 |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1126 # from raymond's original specification |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1127 S = 'http://www.python.org' |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1128 self.checkequal(('http', '://', 'www.python.org'), S, 'partition', '://') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1129 self.checkequal(('http://www.python.org', '', ''), S, 'partition', '?') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1130 self.checkequal(('', 'http://', 'www.python.org'), S, 'partition', 'http://') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1131 self.checkequal(('http://www.python.', 'org', ''), S, 'partition', 'org') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1132 |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1133 self.checkraises(ValueError, S, 'partition', '') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1134 self.checkraises(TypeError, S, 'partition', None) |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1135 |
|
48935
b5365f34640f
Issue #3751: str.rpartition would perform a left-partition when called with
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46107
diff
changeset
|
1136 # mixed use of str and unicode |
|
b5365f34640f
Issue #3751: str.rpartition would perform a left-partition when called with
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46107
diff
changeset
|
1137 self.assertEqual('a/b/c'.partition(u'/'), ('a', '/', 'b/c')) |
|
b5365f34640f
Issue #3751: str.rpartition would perform a left-partition when called with
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46107
diff
changeset
|
1138 |
|
38391
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1139 def test_rpartition(self): |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1140 |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1141 self.checkequal(('this is the rparti', 'ti', 'on method'), |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1142 'this is the rpartition method', 'rpartition', 'ti') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1143 |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1144 # from raymond's original specification |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1145 S = 'http://www.python.org' |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1146 self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://') |
|
39734
cfb77fff0240
Fix endcase for str.rpartition()
Raymond Hettinger <python@rcn.com>
parents:
39302
diff
changeset
|
1147 self.checkequal(('', '', 'http://www.python.org'), S, 'rpartition', '?') |
|
38391
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1148 self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1149 self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1150 |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1151 self.checkraises(ValueError, S, 'rpartition', '') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1152 self.checkraises(TypeError, S, 'rpartition', None) |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1153 |
|
48935
b5365f34640f
Issue #3751: str.rpartition would perform a left-partition when called with
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46107
diff
changeset
|
1154 # mixed use of str and unicode |
|
b5365f34640f
Issue #3751: str.rpartition would perform a left-partition when called with
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46107
diff
changeset
|
1155 self.assertEqual('a/b/c'.rpartition(u'/'), ('a/b', '/', 'c')) |
|
33298
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1156 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1157 class MixinStrStringUserStringTest: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1158 # Additional tests for 8bit strings, i.e. str, UserString and |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1159 # 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
|
1160 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1161 def test_maketrans(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1162 self.assertEqual( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1163 ''.join(map(chr, xrange(256))).replace('abc', 'xyz'), |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1164 string.maketrans('abc', 'xyz') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1165 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1166 self.assertRaises(ValueError, string.maketrans, 'abc', 'xyzw') |
|
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 def test_translate(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1169 table = string.maketrans('abc', 'xyz') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1170 self.checkequal('xyzxyz', 'xyzabcdef', 'translate', table, 'def') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1171 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1172 table = string.maketrans('a', 'A') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1173 self.checkequal('Abc', 'abc', 'translate', table) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1174 self.checkequal('xyz', 'xyz', 'translate', table) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1175 self.checkequal('yz', 'xyz', 'translate', table, 'x') |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41440
diff
changeset
|
1176 self.checkequal('yx', 'zyzzx', 'translate', None, 'z') |
|
41440
cedc8d7d1c7f
SF 1193128: Let str.translate(None) be an identity transformation
Raymond Hettinger <python@rcn.com>
parents:
39734
diff
changeset
|
1177 self.checkequal('zyzzx', 'zyzzx', 'translate', None, '') |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41440
diff
changeset
|
1178 self.checkequal('zyzzx', 'zyzzx', 'translate', None) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1179 self.checkraises(ValueError, 'xyz', 'translate', 'too short', 'strip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1180 self.checkraises(ValueError, 'xyz', 'translate', 'too short') |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1181 |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1182 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1183 class MixinStrUserStringTest: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1184 # Additional tests that only work with |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1185 # 8bit compatible object, i.e. str and UserString |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1186 |
|
35287
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1187 if test_support.have_unicode: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1188 def test_encoding_decoding(self): |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1189 codecs = [('rot13', 'uryyb jbeyq'), |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1190 ('base64', 'aGVsbG8gd29ybGQ=\n'), |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1191 ('hex', '68656c6c6f20776f726c64'), |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1192 ('uu', 'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')] |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1193 for encoding, data in codecs: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1194 self.checkequal(data, 'hello world', 'encode', encoding) |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1195 self.checkequal('hello world', data, 'decode', encoding) |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1196 # zlib is optional, so we make the test optional too... |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1197 try: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1198 import zlib |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1199 except ImportError: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1200 pass |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1201 else: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1202 data = 'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]' |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1203 self.checkequal(data, 'hello world', 'encode', 'zlib') |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1204 self.checkequal('hello world', data, 'decode', 'zlib') |
|
28407
632a6cae0be6
Add two tests for simple error cases.
Walter Dörwald <walter@livinglogic.de>
parents:
28033
diff
changeset
|
1205 |
|
35287
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1206 self.checkraises(TypeError, 'xyz', 'decode', 42) |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1207 self.checkraises(TypeError, 'xyz', 'encode', 42) |
|
33298
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1208 |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1209 |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1210 class MixinStrUnicodeTest: |
|
33305
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1211 # 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
|
1212 |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1213 def test_bug1001011(self): |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1214 # 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
|
1215 # involving a subclass. |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1216 # Make sure that it is of the appropriate type. |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1217 # 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
|
1218 t = self.type2test |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1219 class subclass(t): |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1220 pass |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1221 s1 = subclass("abcd") |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1222 s2 = t().join([s1]) |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1223 self.assert_(s1 is not s2) |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1224 self.assert_(type(s2) is t) |
|
33305
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1225 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1226 s1 = t("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1227 s2 = t().join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1228 self.assert_(s1 is s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1229 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1230 # Should also test mixed-type join. |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1231 if t is unicode: |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1232 s1 = subclass("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1233 s2 = "".join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1234 self.assert_(s1 is not s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1235 self.assert_(type(s2) is t) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1236 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1237 s1 = t("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1238 s2 = "".join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1239 self.assert_(s1 is s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1240 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1241 elif t is str: |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1242 s1 = subclass("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1243 s2 = u"".join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1244 self.assert_(s1 is not s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1245 self.assert_(type(s2) is unicode) # promotes! |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1246 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1247 s1 = t("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1248 s2 = u"".join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1249 self.assert_(s1 is not s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1250 self.assert_(type(s2) is unicode) # promotes! |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1251 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1252 else: |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1253 self.fail("unexpected type for MixinStrUnicodeTest %r" % t) |
