diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-07-10 17:08:42 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-07-10 17:08:42 (GMT) |
commit | f82b04ecbb0b27635501c1b119c674c11bb0cd4e (patch) | |
tree | 039fe560dc551c0df22bcd3f0f6d0af8111239fa /Lib/test/test_userstring.py | |
parent | fd54757336de0d3494e38228acfd0c1d1b9db1b8 (diff) | |
download | cpython-f82b04ecbb0b27635501c1b119c674c11bb0cd4e.zip cpython-f82b04ecbb0b27635501c1b119c674c11bb0cd4e.tar.gz cpython-f82b04ecbb0b27635501c1b119c674c11bb0cd4e.tar.bz2 |
factor out test definitions to string_tests module
test_string and test_userstring run same tests for string methods
Diffstat (limited to 'Lib/test/test_userstring.py')
-rwxr-xr-x | Lib/test/test_userstring.py | 186 |
1 files changed, 2 insertions, 184 deletions
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py index c12f1e2..a47bfdd 100755 --- a/Lib/test/test_userstring.py +++ b/Lib/test/test_userstring.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import sys, string from test_support import verbose +import string_tests # UserString is a wrapper around the native builtin string type. # UserString instances should behave similar to builtin string objects. # The test cases were in part derived from 'test_string.py'. @@ -41,187 +42,4 @@ def test(methodname, input, *args): if verbose: print 'yes' -test('capitalize', ' hello ') -test('capitalize', 'hello ') - -test('center', 'foo', 0) -test('center', 'foo', 3) -test('center', 'foo', 16) - -test('ljust', 'foo', 0) -test('ljust', 'foo', 3) -test('ljust', 'foo', 16) - -test('rjust', 'foo', 0) -test('rjust', 'foo', 3) -test('rjust', 'foo', 16) - -test('count', 'abcabcabc', 'abc') -test('count', 'abcabcabc', 'abc', 1) -test('count', 'abcabcabc', 'abc', -1) -test('count', 'abcabcabc', 'abc', 7) -test('count', 'abcabcabc', 'abc', 0, 3) -test('count', 'abcabcabc', 'abc', 0, 333) - -test('find', 'abcdefghiabc', 'abc') -test('find', 'abcdefghiabc', 'abc', 1) -test('find', 'abcdefghiabc', 'def', 4) -test('rfind', 'abcdefghiabc', 'abc') - -test('index', 'abcabcabc', 'abc') -test('index', 'abcabcabc', 'abc', 1) -test('index', 'abcabcabc', 'abc', -1) -test('index', 'abcabcabc', 'abc', 7) -test('index', 'abcabcabc', 'abc', 0, 3) -test('index', 'abcabcabc', 'abc', 0, 333) - -test('rindex', 'abcabcabc', 'abc') -test('rindex', 'abcabcabc', 'abc', 1) -test('rindex', 'abcabcabc', 'abc', -1) -test('rindex', 'abcabcabc', 'abc', 7) -test('rindex', 'abcabcabc', 'abc', 0, 3) -test('rindex', 'abcabcabc', 'abc', 0, 333) - - -test('lower', 'HeLLo') -test('lower', 'hello') -test('upper', 'HeLLo') -test('upper', 'HELLO') - -test('title', ' hello ') -test('title', 'hello ') -test('title', "fOrMaT thIs aS titLe String") -test('title', "fOrMaT,thIs-aS*titLe;String") -test('title', "getInt") - -test('expandtabs', 'abc\rab\tdef\ng\thi') -test('expandtabs', 'abc\rab\tdef\ng\thi', 8) -test('expandtabs', 'abc\rab\tdef\ng\thi', 4) -test('expandtabs', 'abc\r\nab\tdef\ng\thi', 4) - -test('islower', 'a') -test('islower', 'A') -test('islower', '\n') -test('islower', 'abc') -test('islower', 'aBc') -test('islower', 'abc\n') - -test('isupper', 'a') -test('isupper', 'A') -test('isupper', '\n') -test('isupper', 'ABC') -test('isupper', 'AbC') -test('isupper', 'ABC\n') - -test('isdigit', ' 0123456789') -test('isdigit', '56789') -test('isdigit', '567.89') -test('isdigit', '0123456789abc') - -test('isspace', '') -test('isspace', ' ') -test('isspace', ' \t') -test('isspace', ' \t\f\n') - -test('istitle', 'a') -test('istitle', 'A') -test('istitle', '\n') -test('istitle', 'A Titlecased Line') -test('istitle', 'A\nTitlecased Line') -test('istitle', 'A Titlecased, Line') -test('istitle', 'Not a capitalized String') -test('istitle', 'Not\ta Titlecase String') -test('istitle', 'Not--a Titlecase String') - -test('splitlines', "abc\ndef\n\rghi") -test('splitlines', "abc\ndef\n\r\nghi") -test('splitlines', "abc\ndef\r\nghi") -test('splitlines', "abc\ndef\r\nghi\n") -test('splitlines', "abc\ndef\r\nghi\n\r") -test('splitlines', "\nabc\ndef\r\nghi\n\r") -test('splitlines', "\nabc\ndef\r\nghi\n\r") -test('splitlines', "\nabc\ndef\r\nghi\n\r") - -test('split', 'this is the split function') -test('split', 'a|b|c|d', '|') -test('split', 'a|b|c|d', '|', 2) -test('split', 'a b c d', None, 1) -test('split', 'a b c d', None, 2) -test('split', 'a b c d', None, 3) -test('split', 'a b c d', None, 4) -test('split', 'a b c d', None, 0) -test('split', 'a b c d', None, 2) -test('split', 'a b c d ') - -# join now works with any sequence type -class Sequence: - def __init__(self): self.seq = 'wxyz' - def __len__(self): return len(self.seq) - def __getitem__(self, i): return self.seq[i] - -test('join', '', ('a', 'b', 'c', 'd')) -test('join', '', Sequence()) -test('join', '', 7) - -class BadSeq(Sequence): - def __init__(self): self.seq = [7, 'hello', 123L] - -test('join', '', BadSeq()) - -test('strip', ' hello ') -test('lstrip', ' hello ') -test('rstrip', ' hello ') -test('strip', 'hello') - -test('swapcase', 'HeLLo cOmpUteRs') -transtable = string.maketrans("abc", "xyz") -test('translate', 'xyzabcdef', transtable, 'def') - -transtable = string.maketrans('a', 'A') -test('translate', 'abc', transtable) -test('translate', 'xyz', transtable) - -test('replace', 'one!two!three!', '!', '@', 1) -test('replace', 'one!two!three!', '!', '') -test('replace', 'one!two!three!', '!', '@', 2) -test('replace', 'one!two!three!', '!', '@', 3) -test('replace', 'one!two!three!', '!', '@', 4) -test('replace', 'one!two!three!', '!', '@', 0) -test('replace', 'one!two!three!', '!', '@') -test('replace', 'one!two!three!', 'x', '@') -test('replace', 'one!two!three!', 'x', '@', 2) - -test('startswith', 'hello', 'he') -test('startswith', 'hello', 'hello') -test('startswith', 'hello', 'hello world') -test('startswith', 'hello', '') -test('startswith', 'hello', 'ello') -test('startswith', 'hello', 'ello', 1) -test('startswith', 'hello', 'o', 4) -test('startswith', 'hello', 'o', 5) -test('startswith', 'hello', '', 5) -test('startswith', 'hello', 'lo', 6) -test('startswith', 'helloworld', 'lowo', 3) -test('startswith', 'helloworld', 'lowo', 3, 7) -test('startswith', 'helloworld', 'lowo', 3, 6) - -test('endswith', 'hello', 'lo') -test('endswith', 'hello', 'he') -test('endswith', 'hello', '') -test('endswith', 'hello', 'hello world') -test('endswith', 'helloworld', 'worl') -test('endswith', 'helloworld', 'worl', 3, 9) -test('endswith', 'helloworld', 'world', 3, 12) -test('endswith', 'helloworld', 'lowo', 1, 7) -test('endswith', 'helloworld', 'lowo', 2, 7) -test('endswith', 'helloworld', 'lowo', 3, 7) -test('endswith', 'helloworld', 'lowo', 4, 7) -test('endswith', 'helloworld', 'lowo', 3, 8) -test('endswith', 'ab', 'ab', 0, 1) -test('endswith', 'ab', 'ab', 0, 0) - -# TODO: test cases for: int, long, float, complex, +, * and cmp -s = "" -for builtin_method in dir(s): - if not tested_methods.has_key(builtin_method): - print "no regression test case for method '"+builtin_method+"'" +string_tests.run_method_tests(test) |