mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Make the it_index field in the str/unicode iterators Py_ssize_t's.
Test the new iterators on str/unicode.
This commit is contained in:
parent
bf12cdbb28
commit
49d6b07c6b
4 changed files with 31 additions and 10 deletions
|
@ -19,6 +19,14 @@ class StrTest(
|
|||
string_tests.MixinStrUnicodeUserStringTest.test_formatting(self)
|
||||
self.assertRaises(OverflowError, '%c'.__mod__, 0x1234)
|
||||
|
||||
def test_iterators(self):
|
||||
# Make sure str objects have an __iter__ method
|
||||
it = "abc".__iter__()
|
||||
self.assertEqual(it.next(), "a")
|
||||
self.assertEqual(it.next(), "b")
|
||||
self.assertEqual(it.next(), "c")
|
||||
self.assertRaises(StopIteration, it.next)
|
||||
|
||||
def test_conversion(self):
|
||||
# Make sure __str__() behaves properly
|
||||
class Foo0:
|
||||
|
|
|
@ -93,6 +93,14 @@ class UnicodeTest(
|
|||
testrepr = repr(u''.join(map(unichr, xrange(256))))
|
||||
self.assertEqual(testrepr, latin1repr)
|
||||
|
||||
def test_iterators(self):
|
||||
# Make sure unicode objects have an __iter__ method
|
||||
it = u"\u1111\u2222\u3333".__iter__()
|
||||
self.assertEqual(it.next(), u"\u1111")
|
||||
self.assertEqual(it.next(), u"\u2222")
|
||||
self.assertEqual(it.next(), u"\u3333")
|
||||
self.assertRaises(StopIteration, it.next)
|
||||
|
||||
def test_count(self):
|
||||
string_tests.CommonTest.test_count(self)
|
||||
# check mixed argument types
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue