diff options
author | Walter Dörwald <walter@livinglogic.de> | 2005-02-17 22:03:31 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2005-02-17 22:03:31 (GMT) |
commit | 7f791529292815252bcada54e796af72074103fb (patch) | |
tree | 91038ed914523a63735836de618c288b52950db0 /Lib/test/test_userstring.py | |
parent | 5510f65f5a033eb8d0e9d90046087047410846f9 (diff) | |
download | cpython-7f791529292815252bcada54e796af72074103fb.zip cpython-7f791529292815252bcada54e796af72074103fb.tar.gz cpython-7f791529292815252bcada54e796af72074103fb.tar.bz2 |
Add tests for the methods added by UserString.MutableString.
Diffstat (limited to 'Lib/test/test_userstring.py')
-rwxr-xr-x | Lib/test/test_userstring.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py index 6057e65..b9a5b7f 100755 --- a/Lib/test/test_userstring.py +++ b/Lib/test/test_userstring.py @@ -50,6 +50,68 @@ class MutableStringTest(UserStringTest): def test_hash(self): pass + def test_setitem(self): + s = self.type2test("foo") + self.assertRaises(IndexError, s.__setitem__, -1, "bar") + self.assertRaises(IndexError, s.__setitem__, 3, "bar") + s[0] = "bar" + self.assertEqual(s, "baroo") + s[4] = "foo" + self.assertEqual(s, "barofoo") + + def test_delitem(self): + s = self.type2test("foo") + self.assertRaises(IndexError, s.__setitem__, -1, "bar") + self.assertRaises(IndexError, s.__setitem__, 3, "bar") + del s[0] + self.assertEqual(s, "oo") + del s[1] + self.assertEqual(s, "o") + del s[0] + self.assertEqual(s, "") + + def test_setslice(self): + s = self.type2test("foo") + s[:] = "bar" + self.assertEqual(s, "bar") + s[1:2] = "foo" + self.assertEqual(s, "bfoor") + s[1:-1] = UserString("a") + self.assertEqual(s, "bar") + s[0:10] = 42 + self.assertEqual(s, "42") + + def test_delslice(self): + s = self.type2test("foobar") + del s[3:10] + self.assertEqual(s, "foo") + del s[-1:10] + self.assertEqual(s, "fo") + + def test_immutable(self): + s = self.type2test("foobar") + s2 = s.immutable() + self.assertEqual(s, s2) + self.assert_(isinstance(s2, UserString)) + + def test_iadd(self): + s = self.type2test("foo") + s += "bar" + self.assertEqual(s, "foobar") + s += UserString("baz") + self.assertEqual(s, "foobarbaz") + s += 42 + self.assertEqual(s, "foobarbaz42") + + def test_imul(self): + s = self.type2test("foo") + s *= 1 + self.assertEqual(s, "foo") + s *= 2 + self.assertEqual(s, "foofoo") + s *= -1 + self.assertEqual(s, "") + def test_main(): test_support.run_unittest(UserStringTest, MutableStringTest) |