diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-04-04 22:17:51 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-04-04 22:17:51 (GMT) |
commit | 5a29f2584396fd96796a783564bfda3045f19729 (patch) | |
tree | ade76ead115065b89d26b1f7999af1ef8ceb145b /Lib/test/test_unicode.py | |
parent | 8a4422e78d88579bd3a054999ba2ce8ac6565f57 (diff) | |
download | cpython-5a29f2584396fd96796a783564bfda3045f19729.zip cpython-5a29f2584396fd96796a783564bfda3045f19729.tar.gz cpython-5a29f2584396fd96796a783564bfda3045f19729.tar.bz2 |
Issue #21118: Add more unit tests on str.translate()
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r-- | Lib/test/test_unicode.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 003c251..58dfa20 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -251,6 +251,7 @@ class UnicodeTest(string_tests.CommonTest, {ord('a'): None, ord('b'): ''}) self.checkequalnofix('xyyx', 'xzx', 'translate', {ord('z'): 'yy'}) + # this needs maketrans() self.checkequalnofix('abababc', 'abababc', 'translate', {'b': '<i>'}) @@ -260,6 +261,25 @@ class UnicodeTest(string_tests.CommonTest, tbl = self.type2test.maketrans('abc', 'xyz', 'd') self.checkequalnofix('xyzzy', 'abdcdcbdddd', 'translate', tbl) + # various tests switching from ASCII to latin1 or the opposite; + # same length, remove a letter, or replace with a longer string. + self.assertEqual("[a]".translate(str.maketrans('a', 'X')), + "[X]") + self.assertEqual("[a]".translate(str.maketrans({'a': 'X'})), + "[X]") + self.assertEqual("[a]".translate(str.maketrans({'a': None})), + "[]") + self.assertEqual("[a]".translate(str.maketrans({'a': 'XXX'})), + "[XXX]") + self.assertEqual("[a]".translate(str.maketrans({'a': '\xe9'})), + "[\xe9]") + self.assertEqual("[a]".translate(str.maketrans({'a': '<\xe9>'})), + "[<\xe9>]") + self.assertEqual("[\xe9]".translate(str.maketrans({'\xe9': 'a'})), + "[a]") + self.assertEqual("[\xe9]".translate(str.maketrans({'\xe9': None})), + "[]") + self.assertRaises(TypeError, self.type2test.maketrans) self.assertRaises(ValueError, self.type2test.maketrans, 'abc', 'defg') self.assertRaises(TypeError, self.type2test.maketrans, 2, 'def') |