summaryrefslogtreecommitdiffstats
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2007-08-28 15:28:19 (GMT)
committerThomas Wouters <thomas@python.org>2007-08-28 15:28:19 (GMT)
commit3ccec68a05abae43cf74dc7821c61ba88ab6cb46 (patch)
tree07e97200d168eec13110e16a11b974310b8b550a /Lib/test/string_tests.py
parent0f4a14b56fcbd939e60f424517db61ca6f2f3885 (diff)
downloadcpython-3ccec68a05abae43cf74dc7821c61ba88ab6cb46.zip
cpython-3ccec68a05abae43cf74dc7821c61ba88ab6cb46.tar.gz
cpython-3ccec68a05abae43cf74dc7821c61ba88ab6cb46.tar.bz2
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as is done for simple slices, in the tuple, string and unicode case. - Specialcase step-1 extended slices to optimize the common case for all involved types. - For lists, allow extended slice assignment of differing lengths as long as the step is 1. (Previously, 'l[:2:1] = []' failed even though 'l[:2] = []' and 'l[:2:None] = []' do not.) - Implement extended slicing for buffer, array, structseq, mmap and UserString.UserString. - Implement slice-object support (but not non-step-1 slice assignment) for UserString.MutableString. - Add tests for all new functionality.
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index d38e4a9..d0f8c03 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -912,7 +912,6 @@ class MixinStrUnicodeUserStringTest:
self.checkequal(u'abc', 'abc', '__getitem__', slice(0, 1000))
self.checkequal(u'a', 'abc', '__getitem__', slice(0, 1))
self.checkequal(u'', 'abc', '__getitem__', slice(0, 0))
- # FIXME What about negative indices? This is handled differently by [] and __getitem__(slice)
self.checkraises(TypeError, 'abc', '__getitem__', 'def')
@@ -926,10 +925,21 @@ class MixinStrUnicodeUserStringTest:
self.checkequal('', 'abc', '__getslice__', 1000, 1000)
self.checkequal('', 'abc', '__getslice__', 2000, 1000)
self.checkequal('', 'abc', '__getslice__', 2, 1)
- # FIXME What about negative indizes? This is handled differently by [] and __getslice__
self.checkraises(TypeError, 'abc', '__getslice__', 'def')
+ def test_extended_getslice(self):
+ # Test extended slicing by comparing with list slicing.
+ s = string.ascii_letters + string.digits
+ indices = (0, None, 1, 3, 41, -1, -2, -37)
+ for start in indices:
+ for stop in indices:
+ # Skip step 0 (invalid)
+ for step in indices[1:]:
+ L = list(s)[start:stop:step]
+ self.checkequal(u"".join(L), s, '__getitem__',
+ slice(start, stop, step))
+
def test_mul(self):
self.checkequal('', 'abc', '__mul__', -1)
self.checkequal('', 'abc', '__mul__', 0)