Browse Source

More tests for test_other_methods()

tags/v0.2
Ben Kurtovic 12 years ago
parent
commit
9a87329d69
2 changed files with 42 additions and 5 deletions
  1. +4
    -3
      mwparserfromhell/string_mixin.py
  2. +38
    -2
      tests/test_string_mixin.py

+ 4
- 3
mwparserfromhell/string_mixin.py View File

@@ -179,9 +179,10 @@ class StringMixIn(object):
def isalpha(self):
return self.__unicode__().isalpha()

@inheritdoc
def isdecimal(self):
return self.__unicode__().isdecimal()
if py3k:
@inheritdoc
def isdecimal(self):
return self.__unicode__().isdecimal()

@inheritdoc
def isdigit(self):


+ 38
- 2
tests/test_string_mixin.py View File

@@ -174,7 +174,11 @@ class TestStringMixIn(unittest.TestCase):

if not py3k:
self.assertEquals(fstr, fstr.decode())
self.assertEquals("𐌲𐌿𐍄", '\\U00010332\\U0001033f\\U00010344'.decode("unicode_escape"))
actual = '\\U00010332\\U0001033f\\U00010344'
self.assertEquals("𐌲𐌿𐍄", actual.decode("unicode_escape"))
self.assertEquals("𐌲", '\\U00010332'.decode("unicode_escape"))
self.assertRaises(UnicodeError, "fo".decode, "punycode")
self.assertEquals("", "fo".decode("punycode", "ignore"))

self.assertEquals(b"fake string", fstr.encode())
self.assertEquals(b"\xF0\x90\x8C\xB2\xF0\x90\x8C\xBF\xF0\x90\x8D\x84",
@@ -187,8 +191,40 @@ class TestStringMixIn(unittest.TestCase):
self.assertTrue(fstr.endswith("ing"))
self.assertFalse(fstr.endswith("ingh"))

self.assertEquals("fake string", fstr)
self.assertEquals(" foobar", "\tfoobar".expandtabs())
self.assertEquals(" foobar", "\tfoobar".expandtabs(4))

self.assertEquals(3, fstr.find("e"))
self.assertEquals(-1, fstr.find("z"))
self.assertEquals(7, fstr.find("r", 7))
self.assertEquals(-1, fstr.find("r", 8))
self.assertEquals(7, fstr.find("r", 5, 9))
self.assertEquals(-1, fstr.find("r", 5, 7))

self.assertEquals("fake string", fstr.format())
self.assertEquals("foobarbaz", "foo{0}baz".format("bar"))
self.assertEquals("foobarbaz", "foo{abc}baz".format(abc="bar"))
self.assertEquals("foobarbazbuzz",
"foo{0}{abc}buzz".format("bar", abc="baz"))
self.assertRaises(IndexError, "{0}{1}".format, "abc")

self.assertEquals(3, fstr.index("e"))
self.assertRaises(ValueError, fstr.index, "z")
self.assertEquals(7, fstr.index("r", 7))
self.assertRaises(ValueError, fstr.index, "r", 8)
self.assertEquals(7, fstr.index("r", 5, 9))
self.assertRaises(ValueError, fstr.index, "r", 5, 7)

self.assertTrue("foobar".isalnum())
self.assertTrue("foobar123".isalnum())
self.assertFalse("foo bar".isalnum())

self.assertTrue("foobar".isalpha())
self.assertFalse("foobar123".isalpha())
self.assertFalse("foo bar".isalpha())

methods = [
"expandtabs", "find", "format", "index", "isalnum", "isalpha",
"isdecimal", "isdigit", "islower", "isnumeric", "isspace",
"istitle", "isupper", "join", "ljust", "lstrip", "partition",
"replace", "rfind", "rindex", "rjust", "rpartition", "rsplit",


Loading…
Cancel
Save