blob: 8e8ddf9e2c53a8efd52025bd5593104fc16d25dd [file] [log] [blame]
Guido van Rossuma831cac2000-03-10 23:23:21 +00001""" Test script for the Unicode implementation.
2
Guido van Rossuma831cac2000-03-10 23:23:21 +00003Written by Marc-Andre Lemburg (mal@lemburg.com).
4
5(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
6
Marc-André Lemburg36619082001-01-17 19:11:13 +00007"""#"
Tim Peters2f228e72001-05-13 00:19:31 +00008from test_support import verify, verbose, TestFailed
Andrew M. Kuchlingeddd68d2002-03-29 16:21:44 +00009import sys, string
Guido van Rossuma831cac2000-03-10 23:23:21 +000010
Finn Bock2b29cb22001-12-10 20:57:34 +000011if not sys.platform.startswith('java'):
12 # Test basic sanity of repr()
13 verify(repr(u'abc') == "u'abc'")
14 verify(repr(u'ab\\c') == "u'ab\\\\c'")
15 verify(repr(u'ab\\') == "u'ab\\\\'")
16 verify(repr(u'\\c') == "u'\\\\c'")
17 verify(repr(u'\\') == "u'\\\\'")
18 verify(repr(u'\n') == "u'\\n'")
19 verify(repr(u'\r') == "u'\\r'")
20 verify(repr(u'\t') == "u'\\t'")
21 verify(repr(u'\b') == "u'\\x08'")
22 verify(repr(u"'\"") == """u'\\'"'""")
23 verify(repr(u"'\"") == """u'\\'"'""")
24 verify(repr(u"'") == '''u"'"''')
25 verify(repr(u'"') == """u'"'""")
Marc-André Lemburgbd3be8f2002-02-07 11:33:49 +000026 latin1repr = (
27 "u'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r"
28 "\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a"
29 "\\x1b\\x1c\\x1d\\x1e\\x1f !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHI"
30 "JKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7f"
31 "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b\\x8c\\x8d"
32 "\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\x9b"
33 "\\x9c\\x9d\\x9e\\x9f\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9"
34 "\\xaa\\xab\\xac\\xad\\xae\\xaf\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7"
35 "\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5"
36 "\\xc6\\xc7\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\\xd0\\xd1\\xd2\\xd3"
37 "\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\\xe0\\xe1"
38 "\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef"
39 "\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd"
40 "\\xfe\\xff'")
41 testrepr = repr(u''.join(map(unichr, range(256))))
42 verify(testrepr == latin1repr)
Guido van Rossume4874ae2001-09-21 15:36:41 +000043
Guido van Rossuma831cac2000-03-10 23:23:21 +000044def test(method, input, output, *args):
45 if verbose:
Guido van Rossum15ffc712000-11-29 12:13:59 +000046 print '%s.%s%s =? %s... ' % (repr(input), method, args, repr(output)),
Guido van Rossuma831cac2000-03-10 23:23:21 +000047 try:
48 f = getattr(input, method)
49 value = apply(f, args)
50 except:
51 value = sys.exc_type
Guido van Rossum66503202000-04-28 20:39:58 +000052 exc = sys.exc_info()[:2]
Guido van Rossuma831cac2000-03-10 23:23:21 +000053 else:
54 exc = None
Walter Dörwald2ee4be02002-04-17 21:34:05 +000055 if value == output and type(value) is type(output):
56 # if the original is returned make sure that
57 # this doesn't happen with subclasses
58 if value is input:
59 class usub(unicode):
60 def __repr__(self):
61 return 'usub(%r)' % unicode.__repr__(self)
62 input = usub(input)
63 try:
64 f = getattr(input, method)
65 value = apply(f, args)
66 except:
67 value = sys.exc_type
68 exc = sys.exc_info()[:2]
69 if value is input:
70 if verbose:
71 print 'no'
72 print '*',f, `input`, `output`, `value`
73 return
Guido van Rossum15ffc712000-11-29 12:13:59 +000074 if value != output or type(value) is not type(output):
Guido van Rossuma831cac2000-03-10 23:23:21 +000075 if verbose:
76 print 'no'
77 print '*',f, `input`, `output`, `value`
78 if exc:
Guido van Rossum66503202000-04-28 20:39:58 +000079 print ' value == %s: %s' % (exc)
Guido van Rossuma831cac2000-03-10 23:23:21 +000080 else:
81 if verbose:
82 print 'yes'
83
84test('capitalize', u' hello ', u' hello ')
Walter Dörwald2ee4be02002-04-17 21:34:05 +000085test('capitalize', u'Hello ', u'Hello ')
Guido van Rossuma831cac2000-03-10 23:23:21 +000086test('capitalize', u'hello ', u'Hello ')
Marc-André Lemburgfde66e12001-01-29 11:14:16 +000087test('capitalize', u'aaaa', u'Aaaa')
88test('capitalize', u'AaAa', u'Aaaa')
Guido van Rossuma831cac2000-03-10 23:23:21 +000089
Marc-André Lemburg3a645e42001-01-16 11:54:12 +000090test('count', u'aaa', 3, u'a')
91test('count', u'aaa', 0, u'b')
92test('count', 'aaa', 3, u'a')
93test('count', 'aaa', 0, u'b')
94test('count', u'aaa', 3, 'a')
95test('count', u'aaa', 0, 'b')
96
Guido van Rossuma831cac2000-03-10 23:23:21 +000097test('title', u' hello ', u' Hello ')
Walter Dörwald2ee4be02002-04-17 21:34:05 +000098test('title', u'Hello ', u'Hello ')
Guido van Rossuma831cac2000-03-10 23:23:21 +000099test('title', u'hello ', u'Hello ')
100test('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String')
101test('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String')
102test('title', u"getInt", u'Getint')
103
104test('find', u'abcdefghiabc', 0, u'abc')
105test('find', u'abcdefghiabc', 9, u'abc', 1)
106test('find', u'abcdefghiabc', -1, u'def', 4)
107
108test('rfind', u'abcdefghiabc', 9, u'abc')
109
110test('lower', u'HeLLo', u'hello')
111test('lower', u'hello', u'hello')
112
113test('upper', u'HeLLo', u'HELLO')
114test('upper', u'HELLO', u'HELLO')
115
116if 0:
117 transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
118
119 test('maketrans', u'abc', transtable, u'xyz')
120 test('maketrans', u'abc', ValueError, u'xyzq')
121
122test('split', u'this is the split function',
123 [u'this', u'is', u'the', u'split', u'function'])
124test('split', u'a|b|c|d', [u'a', u'b', u'c', u'd'], u'|')
125test('split', u'a|b|c|d', [u'a', u'b', u'c|d'], u'|', 2)
126test('split', u'a b c d', [u'a', u'b c d'], None, 1)
127test('split', u'a b c d', [u'a', u'b', u'c d'], None, 2)
128test('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 3)
129test('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 4)
130test('split', u'a b c d', [u'a b c d'], None, 0)
131test('split', u'a b c d', [u'a', u'b', u'c d'], None, 2)
132test('split', u'a b c d ', [u'a', u'b', u'c', u'd'])
Guido van Rossum8b264542000-12-19 02:22:31 +0000133test('split', u'a//b//c//d', [u'a', u'b', u'c', u'd'], u'//')
134test('split', u'a//b//c//d', [u'a', u'b', u'c', u'd'], '//')
135test('split', 'a//b//c//d', [u'a', u'b', u'c', u'd'], u'//')
136test('split', u'endcase test', [u'endcase ', u''], u'test')
137test('split', u'endcase test', [u'endcase ', u''], 'test')
138test('split', 'endcase test', [u'endcase ', u''], u'test')
139
Guido van Rossuma831cac2000-03-10 23:23:21 +0000140
141# join now works with any sequence type
142class Sequence:
Guido van Rossum15ffc712000-11-29 12:13:59 +0000143 def __init__(self, seq): self.seq = seq
Guido van Rossuma831cac2000-03-10 23:23:21 +0000144 def __len__(self): return len(self.seq)
145 def __getitem__(self, i): return self.seq[i]
146
147test('join', u' ', u'a b c d', [u'a', u'b', u'c', u'd'])
Guido van Rossum15ffc712000-11-29 12:13:59 +0000148test('join', u' ', u'a b c d', ['a', 'b', u'c', u'd'])
Guido van Rossuma831cac2000-03-10 23:23:21 +0000149test('join', u'', u'abcd', (u'a', u'b', u'c', u'd'))
Guido van Rossum15ffc712000-11-29 12:13:59 +0000150test('join', u' ', u'w x y z', Sequence('wxyz'))
Guido van Rossuma831cac2000-03-10 23:23:21 +0000151test('join', u' ', TypeError, 7)
Guido van Rossum15ffc712000-11-29 12:13:59 +0000152test('join', u' ', TypeError, Sequence([7, u'hello', 123L]))
153test('join', ' ', u'a b c d', [u'a', u'b', u'c', u'd'])
154test('join', ' ', u'a b c d', ['a', 'b', u'c', u'd'])
155test('join', '', u'abcd', (u'a', u'b', u'c', u'd'))
156test('join', ' ', u'w x y z', Sequence(u'wxyz'))
157test('join', ' ', TypeError, 7)
Guido van Rossuma831cac2000-03-10 23:23:21 +0000158
159result = u''
160for i in range(10):
161 if i > 0:
162 result = result + u':'
163 result = result + u'x'*10
164test('join', u':', result, [u'x' * 10] * 10)
165test('join', u':', result, (u'x' * 10,) * 10)
166
167test('strip', u' hello ', u'hello')
168test('lstrip', u' hello ', u'hello ')
169test('rstrip', u' hello ', u' hello')
170test('strip', u'hello', u'hello')
171
172test('swapcase', u'HeLLo cOmpUteRs', u'hEllO CoMPuTErS')
173
174if 0:
175 test('translate', u'xyzabcdef', u'xyzxyz', transtable, u'def')
176
177 table = string.maketrans('a', u'A')
178 test('translate', u'abc', u'Abc', table)
179 test('translate', u'xyz', u'xyz', table)
180
181test('replace', u'one!two!three!', u'one@two!three!', u'!', u'@', 1)
Barry Warsaw51ac5802000-03-20 16:36:48 +0000182test('replace', u'one!two!three!', u'onetwothree', '!', '')
Guido van Rossuma831cac2000-03-10 23:23:21 +0000183test('replace', u'one!two!three!', u'one@two@three!', u'!', u'@', 2)
184test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 3)
185test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 4)
186test('replace', u'one!two!three!', u'one!two!three!', u'!', u'@', 0)
187test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@')
188test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@')
189test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2)
190
Guido van Rossum77f6a652002-04-03 22:41:51 +0000191test('startswith', u'hello', True, u'he')
192test('startswith', u'hello', True, u'hello')
193test('startswith', u'hello', False, u'hello world')
194test('startswith', u'hello', True, u'')
195test('startswith', u'hello', False, u'ello')
196test('startswith', u'hello', True, u'ello', 1)
197test('startswith', u'hello', True, u'o', 4)
198test('startswith', u'hello', False, u'o', 5)
199test('startswith', u'hello', True, u'', 5)
200test('startswith', u'hello', False, u'lo', 6)
201test('startswith', u'helloworld', True, u'lowo', 3)
202test('startswith', u'helloworld', True, u'lowo', 3, 7)
203test('startswith', u'helloworld', False, u'lowo', 3, 6)
Guido van Rossuma831cac2000-03-10 23:23:21 +0000204
Guido van Rossum77f6a652002-04-03 22:41:51 +0000205test('endswith', u'hello', True, u'lo')
206test('endswith', u'hello', False, u'he')
207test('endswith', u'hello', True, u'')
208test('endswith', u'hello', False, u'hello world')
209test('endswith', u'helloworld', False, u'worl')
210test('endswith', u'helloworld', True, u'worl', 3, 9)
211test('endswith', u'helloworld', True, u'world', 3, 12)
212test('endswith', u'helloworld', True, u'lowo', 1, 7)
213test('endswith', u'helloworld', True, u'lowo', 2, 7)
214test('endswith', u'helloworld', True, u'lowo', 3, 7)
215test('endswith', u'helloworld', False, u'lowo', 4, 7)
216test('endswith', u'helloworld', False, u'lowo', 3, 8)
217test('endswith', u'ab', False, u'ab', 0, 1)
218test('endswith', u'ab', False, u'ab', 0, 0)
Guido van Rossuma831cac2000-03-10 23:23:21 +0000219
220test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi')
221test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 8)
222test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 4)
223test('expandtabs', u'abc\r\nab\tdef\ng\thi', u'abc\r\nab def\ng hi', 4)
Walter Dörwald2ee4be02002-04-17 21:34:05 +0000224test('expandtabs', u'abc\r\nab\r\ndef\ng\r\nhi', u'abc\r\nab\r\ndef\ng\r\nhi', 4)
Guido van Rossuma831cac2000-03-10 23:23:21 +0000225
226if 0:
227 test('capwords', u'abc def ghi', u'Abc Def Ghi')
228 test('capwords', u'abc\tdef\nghi', u'Abc Def Ghi')
229 test('capwords', u'abc\t def \nghi', u'Abc Def Ghi')
230
Walter Dörwald068325e2002-04-15 13:36:47 +0000231test('zfill', u'123', u'123', 2)
232test('zfill', u'123', u'123', 3)
233test('zfill', u'123', u'0123', 4)
234test('zfill', u'+123', u'+123', 3)
235test('zfill', u'+123', u'+123', 4)
236test('zfill', u'+123', u'+0123', 5)
237test('zfill', u'-123', u'-123', 3)
238test('zfill', u'-123', u'-123', 4)
239test('zfill', u'-123', u'-0123', 5)
240test('zfill', u'', u'000', 3)
241test('zfill', u'34', u'34', 1)
242test('zfill', u'34', u'00034', 5)
Andrew M. Kuchlingeddd68d2002-03-29 16:21:44 +0000243
Guido van Rossuma831cac2000-03-10 23:23:21 +0000244# Comparisons:
245print 'Testing Unicode comparisons...',
Marc-André Lemburg36619082001-01-17 19:11:13 +0000246verify(u'abc' == 'abc')
247verify('abc' == u'abc')
248verify(u'abc' == u'abc')
249verify(u'abcd' > 'abc')
250verify('abcd' > u'abc')
251verify(u'abcd' > u'abc')
252verify(u'abc' < 'abcd')
253verify('abc' < u'abcd')
254verify(u'abc' < u'abcd')
Guido van Rossuma831cac2000-03-10 23:23:21 +0000255print 'done.'
256
Marc-André Lemburge5034372000-08-08 08:04:29 +0000257if 0:
258 # Move these tests to a Unicode collation module test...
Marc-André Lemburgd6d06ad2000-07-07 17:48:52 +0000259
Marc-André Lemburge5034372000-08-08 08:04:29 +0000260 print 'Testing UTF-16 code point order comparisons...',
261 #No surrogates, no fixup required.
Marc-André Lemburg36619082001-01-17 19:11:13 +0000262 verify(u'\u0061' < u'\u20ac')
Marc-André Lemburge5034372000-08-08 08:04:29 +0000263 # Non surrogate below surrogate value, no fixup required
Marc-André Lemburg36619082001-01-17 19:11:13 +0000264 verify(u'\u0061' < u'\ud800\udc02')
Marc-André Lemburgd6d06ad2000-07-07 17:48:52 +0000265
Marc-André Lemburge5034372000-08-08 08:04:29 +0000266 # Non surrogate above surrogate value, fixup required
267 def test_lecmp(s, s2):
Tim Petersd2bf3b72001-01-18 02:22:22 +0000268 verify(s < s2 , "comparison failed on %s < %s" % (s, s2))
Marc-André Lemburgd6d06ad2000-07-07 17:48:52 +0000269
Marc-André Lemburge5034372000-08-08 08:04:29 +0000270 def test_fixup(s):
Fred Drake004d5e62000-10-23 17:22:08 +0000271 s2 = u'\ud800\udc01'
272 test_lecmp(s, s2)
273 s2 = u'\ud900\udc01'
274 test_lecmp(s, s2)
275 s2 = u'\uda00\udc01'
276 test_lecmp(s, s2)
277 s2 = u'\udb00\udc01'
278 test_lecmp(s, s2)
279 s2 = u'\ud800\udd01'
280 test_lecmp(s, s2)
281 s2 = u'\ud900\udd01'
282 test_lecmp(s, s2)
283 s2 = u'\uda00\udd01'
284 test_lecmp(s, s2)
285 s2 = u'\udb00\udd01'
286 test_lecmp(s, s2)
287 s2 = u'\ud800\ude01'
288 test_lecmp(s, s2)
289 s2 = u'\ud900\ude01'
290 test_lecmp(s, s2)
291 s2 = u'\uda00\ude01'
292 test_lecmp(s, s2)
293 s2 = u'\udb00\ude01'
294 test_lecmp(s, s2)
295 s2 = u'\ud800\udfff'
296 test_lecmp(s, s2)
297 s2 = u'\ud900\udfff'
298 test_lecmp(s, s2)
299 s2 = u'\uda00\udfff'
300 test_lecmp(s, s2)
301 s2 = u'\udb00\udfff'
302 test_lecmp(s, s2)
Marc-André Lemburge5034372000-08-08 08:04:29 +0000303
304 test_fixup(u'\ue000')
305 test_fixup(u'\uff61')
306
307 # Surrogates on both sides, no fixup required
Marc-André Lemburg36619082001-01-17 19:11:13 +0000308 verify(u'\ud800\udc02' < u'\ud84d\udc56')
Marc-André Lemburge5034372000-08-08 08:04:29 +0000309 print 'done.'
Marc-André Lemburgd6d06ad2000-07-07 17:48:52 +0000310
Guido van Rossuma831cac2000-03-10 23:23:21 +0000311test('ljust', u'abc', u'abc ', 10)
312test('rjust', u'abc', u' abc', 10)
313test('center', u'abc', u' abc ', 10)
314test('ljust', u'abc', u'abc ', 6)
315test('rjust', u'abc', u' abc', 6)
316test('center', u'abc', u' abc ', 6)
317test('ljust', u'abc', u'abc', 2)
318test('rjust', u'abc', u'abc', 2)
319test('center', u'abc', u'abc', 2)
320
Guido van Rossum77f6a652002-04-03 22:41:51 +0000321test('islower', u'a', True)
322test('islower', u'A', False)
323test('islower', u'\n', False)
324test('islower', u'\u1FFc', False)
325test('islower', u'abc', True)
326test('islower', u'aBc', False)
327test('islower', u'abc\n', True)
Guido van Rossuma831cac2000-03-10 23:23:21 +0000328
Guido van Rossum77f6a652002-04-03 22:41:51 +0000329test('isupper', u'a', False)
330test('isupper', u'A', True)
331test('isupper', u'\n', False)
Marc-André Lemburgef0a0322001-02-10 14:09:31 +0000332if sys.platform[:4] != 'java':
Guido van Rossum77f6a652002-04-03 22:41:51 +0000333 test('isupper', u'\u1FFc', False)
334test('isupper', u'ABC', True)
335test('isupper', u'AbC', False)
336test('isupper', u'ABC\n', True)
Guido van Rossuma831cac2000-03-10 23:23:21 +0000337
Guido van Rossum77f6a652002-04-03 22:41:51 +0000338test('istitle', u'a', False)
339test('istitle', u'A', True)
340test('istitle', u'\n', False)
341test('istitle', u'\u1FFc', True)
342test('istitle', u'A Titlecased Line', True)
343test('istitle', u'A\nTitlecased Line', True)
344test('istitle', u'A Titlecased, Line', True)
345test('istitle', u'Greek \u1FFcitlecases ...', True)
346test('istitle', u'Not a capitalized String', False)
347test('istitle', u'Not\ta Titlecase String', False)
348test('istitle', u'Not--a Titlecase String', False)
Guido van Rossuma831cac2000-03-10 23:23:21 +0000349
Guido van Rossum77f6a652002-04-03 22:41:51 +0000350test('isalpha', u'a', True)
351test('isalpha', u'A', True)
352test('isalpha', u'\n', False)
353test('isalpha', u'\u1FFc', True)
354test('isalpha', u'abc', True)
355test('isalpha', u'aBc123', False)
356test('isalpha', u'abc\n', False)
Marc-André Lemburg9d467412000-07-05 09:46:40 +0000357
Guido van Rossum77f6a652002-04-03 22:41:51 +0000358test('isalnum', u'a', True)
359test('isalnum', u'A', True)
360test('isalnum', u'\n', False)
361test('isalnum', u'123abc456', True)
362test('isalnum', u'a1b3c', True)
363test('isalnum', u'aBc000 ', False)
364test('isalnum', u'abc\n', False)
Marc-André Lemburg9d467412000-07-05 09:46:40 +0000365
Guido van Rossuma831cac2000-03-10 23:23:21 +0000366test('splitlines', u"abc\ndef\n\rghi", [u'abc', u'def', u'', u'ghi'])
367test('splitlines', u"abc\ndef\n\r\nghi", [u'abc', u'def', u'', u'ghi'])
368test('splitlines', u"abc\ndef\r\nghi", [u'abc', u'def', u'ghi'])
369test('splitlines', u"abc\ndef\r\nghi\n", [u'abc', u'def', u'ghi'])
370test('splitlines', u"abc\ndef\r\nghi\n\r", [u'abc', u'def', u'ghi', u''])
371test('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'', u'abc', u'def', u'ghi', u''])
Guido van Rossum77f6a652002-04-03 22:41:51 +0000372test('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'\n', u'abc\n', u'def\r\n', u'ghi\n', u'\r'], True)
Guido van Rossuma831cac2000-03-10 23:23:21 +0000373
374test('translate', u"abababc", u'bbbc', {ord('a'):None})
375test('translate', u"abababc", u'iiic', {ord('a'):None, ord('b'):ord('i')})
376test('translate', u"abababc", u'iiix', {ord('a'):None, ord('b'):ord('i'), ord('c'):u'x'})
377
Guido van Rossumd4d26842000-03-13 23:21:48 +0000378# Contains:
379print 'Testing Unicode contains method...',
Marc-André Lemburg36619082001-01-17 19:11:13 +0000380verify(('a' in u'abdb') == 1)
381verify(('a' in u'bdab') == 1)
382verify(('a' in u'bdaba') == 1)
383verify(('a' in u'bdba') == 1)
384verify(('a' in u'bdba') == 1)
385verify((u'a' in u'bdba') == 1)
386verify((u'a' in u'bdb') == 0)
387verify((u'a' in 'bdb') == 0)
388verify((u'a' in 'bdba') == 1)
389verify((u'a' in ('a',1,None)) == 1)
390verify((u'a' in (1,None,'a')) == 1)
391verify((u'a' in (1,None,u'a')) == 1)
392verify(('a' in ('a',1,None)) == 1)
393verify(('a' in (1,None,'a')) == 1)
394verify(('a' in (1,None,u'a')) == 1)
395verify(('a' in ('x',1,u'y')) == 0)
396verify(('a' in ('x',1,None)) == 0)
Guido van Rossumd4d26842000-03-13 23:21:48 +0000397print 'done.'
398
Guido van Rossuma831cac2000-03-10 23:23:21 +0000399# Formatting:
400print 'Testing Unicode formatting strings...',
Marc-André Lemburg36619082001-01-17 19:11:13 +0000401verify(u"%s, %s" % (u"abc", "abc") == u'abc, abc')
402verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, 2, 3) == u'abc, abc, 1, 2.000000, 3.00')
403verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, -2, 3) == u'abc, abc, 1, -2.000000, 3.00')
404verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.5) == u'abc, abc, -1, -2.000000, 3.50')
405verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.57) == u'abc, abc, -1, -2.000000, 3.57')
406verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 1003.57) == u'abc, abc, -1, -2.000000, 1003.57')
407verify(u"%c" % (u"a",) == u'a')
408verify(u"%c" % ("a",) == u'a')
409verify(u"%c" % (34,) == u'"')
410verify(u"%c" % (36,) == u'$')
Marc-André Lemburgef0a0322001-02-10 14:09:31 +0000411if sys.platform[:4] != 'java':
412 value = u"%r, %r" % (u"abc", "abc")
413 if value != u"u'abc', 'abc'":
414 print '*** formatting failed for "%s"' % 'u"%r, %r" % (u"abc", "abc")'
Marc-André Lemburg84625732000-06-13 12:05:36 +0000415
Marc-André Lemburg36619082001-01-17 19:11:13 +0000416verify(u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"} == u'abc, def')
Marc-André Lemburg84625732000-06-13 12:05:36 +0000417try:
Marc-André Lemburg72f82132001-11-20 15:18:49 +0000418 value = u"%(x)s, %(ä)s" % {'x':u"abc", u'ä':"def"}
Marc-André Lemburg84625732000-06-13 12:05:36 +0000419except KeyError:
420 print '*** formatting failed for "%s"' % "u'abc, def'"
421else:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000422 verify(value == u'abc, def')
Marc-André Lemburg84625732000-06-13 12:05:36 +0000423
Guido van Rossum97064862000-04-10 13:52:48 +0000424# formatting jobs delegated from the string implementation:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000425verify('...%(foo)s...' % {'foo':u"abc"} == u'...abc...')
426verify('...%(foo)s...' % {'foo':"abc"} == '...abc...')
427verify('...%(foo)s...' % {u'foo':"abc"} == '...abc...')
428verify('...%(foo)s...' % {u'foo':u"abc"} == u'...abc...')
429verify('...%(foo)s...' % {u'foo':u"abc",'def':123} == u'...abc...')
430verify('...%(foo)s...' % {u'foo':u"abc",u'def':123} == u'...abc...')
431verify('...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...1...2...3...abc...')
432verify('...%%...%%s...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...%...%s...1...2...3...abc...')
433verify('...%s...' % u"abc" == u'...abc...')
Marc-André Lemburg542fe562001-05-02 14:21:53 +0000434verify('%*s' % (5,u'abc',) == u' abc')
435verify('%*s' % (-5,u'abc',) == u'abc ')
436verify('%*.*s' % (5,2,u'abc',) == u' ab')
437verify('%*.*s' % (5,3,u'abc',) == u' abc')
438verify('%i %*.*s' % (10, 5,3,u'abc',) == u'10 abc')
439verify('%i%s %*.*s' % (10, 3, 5,3,u'abc',) == u'103 abc')
Guido van Rossuma831cac2000-03-10 23:23:21 +0000440print 'done.'
441
Marc-André Lemburgb5507ec2001-10-19 12:02:29 +0000442print 'Testing builtin unicode()...',
443
444# unicode(obj) tests (this maps to PyObject_Unicode() at C level)
445
446verify(unicode(u'unicode remains unicode') == u'unicode remains unicode')
447
448class UnicodeSubclass(unicode):
449 pass
450
451verify(unicode(UnicodeSubclass('unicode subclass becomes unicode'))
452 == u'unicode subclass becomes unicode')
453
454verify(unicode('strings are converted to unicode')
455 == u'strings are converted to unicode')
456
457class UnicodeCompat:
458 def __init__(self, x):
459 self.x = x
460 def __unicode__(self):
461 return self.x
462
463verify(unicode(UnicodeCompat('__unicode__ compatible objects are recognized'))
464 == u'__unicode__ compatible objects are recognized')
465
466class StringCompat:
467 def __init__(self, x):
468 self.x = x
469 def __str__(self):
470 return self.x
471
472verify(unicode(StringCompat('__str__ compatible objects are recognized'))
473 == u'__str__ compatible objects are recognized')
474
475# unicode(obj) is compatible to str():
476
477o = StringCompat('unicode(obj) is compatible to str()')
478verify(unicode(o) == u'unicode(obj) is compatible to str()')
479verify(str(o) == 'unicode(obj) is compatible to str()')
480
481for obj in (123, 123.45, 123L):
482 verify(unicode(obj) == unicode(str(obj)))
483
484# unicode(obj, encoding, error) tests (this maps to
485# PyUnicode_FromEncodedObject() at C level)
486
Finn Bock2b29cb22001-12-10 20:57:34 +0000487if not sys.platform.startswith('java'):
488 try:
489 unicode(u'decoding unicode is not supported', 'utf-8', 'strict')
490 except TypeError:
491 pass
492 else:
493 raise TestFailed, "decoding unicode should NOT be supported"
Marc-André Lemburgb5507ec2001-10-19 12:02:29 +0000494
495verify(unicode('strings are decoded to unicode', 'utf-8', 'strict')
496 == u'strings are decoded to unicode')
497
Finn Bock2b29cb22001-12-10 20:57:34 +0000498if not sys.platform.startswith('java'):
499 verify(unicode(buffer('character buffers are decoded to unicode'),
500 'utf-8', 'strict')
501 == u'character buffers are decoded to unicode')
Marc-André Lemburgb5507ec2001-10-19 12:02:29 +0000502
503print 'done.'
504
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000505# Test builtin codecs
506print 'Testing builtin codecs...',
507
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000508# UTF-7 specific encoding tests:
509utfTests = [(u'A\u2262\u0391.', 'A+ImIDkQ.'), # RFC2152 example
510 (u'Hi Mom -\u263a-!', 'Hi Mom -+Jjo--!'), # RFC2152 example
511 (u'\u65E5\u672C\u8A9E', '+ZeVnLIqe-'), # RFC2152 example
512 (u'Item 3 is \u00a31.', 'Item 3 is +AKM-1.'), # RFC2152 example
513 (u'+', '+-'),
514 (u'+-', '+--'),
515 (u'+?', '+-?'),
516 (u'\?', '+AFw?'),
517 (u'+?', '+-?'),
518 (ur'\\?', '+AFwAXA?'),
519 (ur'\\\?', '+AFwAXABc?'),
520 (ur'++--', '+-+---')]
521
522for x,y in utfTests:
523 verify( x.encode('utf-7') == y )
524
Tim Peters527e64f2001-10-04 05:36:56 +0000525try:
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000526 unicode('+3ADYAA-', 'utf-7') # surrogates not supported
527except UnicodeError:
528 pass
529else:
530 raise TestFailed, "unicode('+3ADYAA-', 'utf-7') failed to raise an exception"
531
532verify(unicode('+3ADYAA-', 'utf-7', 'replace') == u'\ufffd')
533
Marc-André Lemburgd6d06ad2000-07-07 17:48:52 +0000534# UTF-8 specific encoding tests:
Marc-André Lemburgbd3be8f2002-02-07 11:33:49 +0000535verify(u''.encode('utf-8') == '')
Marc-André Lemburg3688a882002-02-06 18:09:02 +0000536verify(u'\u20ac'.encode('utf-8') == '\xe2\x82\xac')
537verify(u'\ud800\udc02'.encode('utf-8') == '\xf0\x90\x80\x82')
538verify(u'\ud84d\udc56'.encode('utf-8') == '\xf0\xa3\x91\x96')
539verify(u'\ud800'.encode('utf-8') == '\xed\xa0\x80')
540verify(u'\udc00'.encode('utf-8') == '\xed\xb0\x80')
541verify((u'\ud800\udc02'*1000).encode('utf-8') ==
542 '\xf0\x90\x80\x82'*1000)
Marc-André Lemburgce0b6642002-04-10 17:18:02 +0000543verify(u'\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f'
544 u'\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00'
545 u'\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c'
546 u'\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067'
547 u'\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das'
Tim Peters863ac442002-04-16 01:38:40 +0000548 u' Nunstuck git und'.encode('utf-8') ==
Marc-André Lemburgce0b6642002-04-10 17:18:02 +0000549 '\xe6\xad\xa3\xe7\xa2\xba\xe3\x81\xab\xe8\xa8\x80\xe3\x81'
550 '\x86\xe3\x81\xa8\xe7\xbf\xbb\xe8\xa8\xb3\xe3\x81\xaf\xe3'
551 '\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x81\xbe'
552 '\xe3\x81\x9b\xe3\x82\x93\xe3\x80\x82\xe4\xb8\x80\xe9\x83'
553 '\xa8\xe3\x81\xaf\xe3\x83\x89\xe3\x82\xa4\xe3\x83\x84\xe8'
554 '\xaa\x9e\xe3\x81\xa7\xe3\x81\x99\xe3\x81\x8c\xe3\x80\x81'
555 '\xe3\x81\x82\xe3\x81\xa8\xe3\x81\xaf\xe3\x81\xa7\xe3\x81'
556 '\x9f\xe3\x82\x89\xe3\x82\x81\xe3\x81\xa7\xe3\x81\x99\xe3'
557 '\x80\x82\xe5\xae\x9f\xe9\x9a\x9b\xe3\x81\xab\xe3\x81\xaf'
558 '\xe3\x80\x8cWenn ist das Nunstuck git und')
Marc-André Lemburg3688a882002-02-06 18:09:02 +0000559
Marc-André Lemburgd6d06ad2000-07-07 17:48:52 +0000560# UTF-8 specific decoding tests
Marc-André Lemburg3688a882002-02-06 18:09:02 +0000561verify(unicode('\xf0\xa3\x91\x96', 'utf-8') == u'\U00023456' )
562verify(unicode('\xf0\x90\x80\x82', 'utf-8') == u'\U00010002' )
563verify(unicode('\xe2\x82\xac', 'utf-8') == u'\u20ac' )
Marc-André Lemburgd6d06ad2000-07-07 17:48:52 +0000564
565# Other possible utf-8 test cases:
566# * strict decoding testing for all of the
567# UTF8_ERROR cases in PyUnicode_DecodeUTF8
568
Marc-André Lemburg36619082001-01-17 19:11:13 +0000569verify(unicode('hello','ascii') == u'hello')
570verify(unicode('hello','utf-8') == u'hello')
571verify(unicode('hello','utf8') == u'hello')
572verify(unicode('hello','latin-1') == u'hello')
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000573
Marc-André Lemburg6871f6a2001-09-20 12:53:16 +0000574# Error handling
Guido van Rossum97064862000-04-10 13:52:48 +0000575try:
576 u'Andr\202 x'.encode('ascii')
577 u'Andr\202 x'.encode('ascii','strict')
578except ValueError:
579 pass
580else:
Guido van Rossuma1374e42001-01-19 19:01:56 +0000581 raise TestFailed, "u'Andr\202'.encode('ascii') failed to raise an exception"
Marc-André Lemburg36619082001-01-17 19:11:13 +0000582verify(u'Andr\202 x'.encode('ascii','ignore') == "Andr x")
583verify(u'Andr\202 x'.encode('ascii','replace') == "Andr? x")
Guido van Rossum97064862000-04-10 13:52:48 +0000584
585try:
586 unicode('Andr\202 x','ascii')
587 unicode('Andr\202 x','ascii','strict')
588except ValueError:
589 pass
590else:
Guido van Rossuma1374e42001-01-19 19:01:56 +0000591 raise TestFailed, "unicode('Andr\202') failed to raise an exception"
Marc-André Lemburg36619082001-01-17 19:11:13 +0000592verify(unicode('Andr\202 x','ascii','ignore') == u"Andr x")
593verify(unicode('Andr\202 x','ascii','replace') == u'Andr\uFFFD x')
Guido van Rossum97064862000-04-10 13:52:48 +0000594
Martin v. Löwis047c05e2002-03-21 08:55:28 +0000595verify("\\N{foo}xx".decode("unicode-escape", "ignore") == u"xx")
596try:
597 "\\".decode("unicode-escape")
598except ValueError:
599 pass
600else:
601 raise TestFailed, '"\\".decode("unicode-escape") should fail'
602
Marc-André Lemburg36619082001-01-17 19:11:13 +0000603verify(u'hello'.encode('ascii') == 'hello')
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000604verify(u'hello'.encode('utf-7') == 'hello')
Marc-André Lemburg36619082001-01-17 19:11:13 +0000605verify(u'hello'.encode('utf-8') == 'hello')
606verify(u'hello'.encode('utf8') == 'hello')
607verify(u'hello'.encode('utf-16-le') == 'h\000e\000l\000l\000o\000')
608verify(u'hello'.encode('utf-16-be') == '\000h\000e\000l\000l\000o')
609verify(u'hello'.encode('latin-1') == 'hello')
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000610
Marc-André Lemburg6c6bfb72001-07-20 17:39:11 +0000611# Roundtrip safety for BMP (just the first 1024 chars)
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000612u = u''.join(map(unichr, range(1024)))
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000613for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000614 'raw_unicode_escape', 'unicode_escape', 'unicode_internal'):
Marc-André Lemburg36619082001-01-17 19:11:13 +0000615 verify(unicode(u.encode(encoding),encoding) == u)
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000616
Marc-André Lemburgbd3be8f2002-02-07 11:33:49 +0000617# Roundtrip safety for BMP (just the first 256 chars)
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000618u = u''.join(map(unichr, range(256)))
Guido van Rossum9e896b32000-04-05 20:11:21 +0000619for encoding in (
620 'latin-1',
621 ):
622 try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000623 verify(unicode(u.encode(encoding),encoding) == u)
Guido van Rossuma1374e42001-01-19 19:01:56 +0000624 except TestFailed:
Guido van Rossum9e896b32000-04-05 20:11:21 +0000625 print '*** codec "%s" failed round-trip' % encoding
626 except ValueError,why:
627 print '*** codec for "%s" failed: %s' % (encoding, why)
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000628
Marc-André Lemburgbd3be8f2002-02-07 11:33:49 +0000629# Roundtrip safety for BMP (just the first 128 chars)
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000630u = u''.join(map(unichr, range(128)))
Guido van Rossum9e896b32000-04-05 20:11:21 +0000631for encoding in (
632 'ascii',
633 ):
634 try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000635 verify(unicode(u.encode(encoding),encoding) == u)
Guido van Rossuma1374e42001-01-19 19:01:56 +0000636 except TestFailed:
Guido van Rossum9e896b32000-04-05 20:11:21 +0000637 print '*** codec "%s" failed round-trip' % encoding
638 except ValueError,why:
639 print '*** codec for "%s" failed: %s' % (encoding, why)
640
Marc-André Lemburgbd3be8f2002-02-07 11:33:49 +0000641# Roundtrip safety for non-BMP (just a few chars)
642u = u'\U00010001\U00020002\U00030003\U00040004\U00050005'
643for encoding in ('utf-8',
644 'utf-16', 'utf-16-le', 'utf-16-be',
645 #'raw_unicode_escape',
646 'unicode_escape', 'unicode_internal'):
647 verify(unicode(u.encode(encoding),encoding) == u)
648
649# UTF-8 must be roundtrip safe for all UCS-2 code points
650u = u''.join(map(unichr, range(0x10000)))
651for encoding in ('utf-8',):
652 verify(unicode(u.encode(encoding),encoding) == u)
653
Guido van Rossum9e896b32000-04-05 20:11:21 +0000654print 'done.'
655
656print 'Testing standard mapping codecs...',
657
658print '0-127...',
659s = ''.join(map(chr, range(128)))
660for encoding in (
661 'cp037', 'cp1026',
662 'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
663 'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
Fred Drake004d5e62000-10-23 17:22:08 +0000664 'cp863', 'cp865', 'cp866',
Guido van Rossum9e896b32000-04-05 20:11:21 +0000665 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
666 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6',
667 'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1',
668 'mac_cyrillic', 'mac_latin2',
669
670 'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
671 'cp1256', 'cp1257', 'cp1258',
672 'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
673
674 'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
Tim Peters2f228e72001-05-13 00:19:31 +0000675 'cp1006', 'iso8859_8',
Fred Drake004d5e62000-10-23 17:22:08 +0000676
Guido van Rossum9e896b32000-04-05 20:11:21 +0000677 ### These have undefined mappings:
678 #'cp424',
Fred Drake004d5e62000-10-23 17:22:08 +0000679
Tim Peters2f228e72001-05-13 00:19:31 +0000680 ### These fail the round-trip:
681 #'cp875'
682
Guido van Rossum9e896b32000-04-05 20:11:21 +0000683 ):
684 try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000685 verify(unicode(s,encoding).encode(encoding) == s)
Guido van Rossuma1374e42001-01-19 19:01:56 +0000686 except TestFailed:
Guido van Rossum9e896b32000-04-05 20:11:21 +0000687 print '*** codec "%s" failed round-trip' % encoding
688 except ValueError,why:
689 print '*** codec for "%s" failed: %s' % (encoding, why)
690
691print '128-255...',
692s = ''.join(map(chr, range(128,256)))
693for encoding in (
694 'cp037', 'cp1026',
695 'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
696 'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
Fred Drake004d5e62000-10-23 17:22:08 +0000697 'cp863', 'cp865', 'cp866',
Guido van Rossum9e896b32000-04-05 20:11:21 +0000698 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
Tim Petersd2bf3b72001-01-18 02:22:22 +0000699 'iso8859_2', 'iso8859_4', 'iso8859_5',
Marc-André Lemburga866df82001-01-03 21:29:14 +0000700 'iso8859_9', 'koi8_r', 'latin_1',
Guido van Rossum9e896b32000-04-05 20:11:21 +0000701 'mac_cyrillic', 'mac_latin2',
Fred Drake004d5e62000-10-23 17:22:08 +0000702
Guido van Rossum9e896b32000-04-05 20:11:21 +0000703 ### These have undefined mappings:
704 #'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
705 #'cp1256', 'cp1257', 'cp1258',
706 #'cp424', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
Tim Petersd2bf3b72001-01-18 02:22:22 +0000707 #'iso8859_3', 'iso8859_6', 'iso8859_7',
Guido van Rossum9e896b32000-04-05 20:11:21 +0000708 #'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
Fred Drake004d5e62000-10-23 17:22:08 +0000709
Guido van Rossum9e896b32000-04-05 20:11:21 +0000710 ### These fail the round-trip:
711 #'cp1006', 'cp875', 'iso8859_8',
Fred Drake004d5e62000-10-23 17:22:08 +0000712
Guido van Rossum9e896b32000-04-05 20:11:21 +0000713 ):
714 try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000715 verify(unicode(s,encoding).encode(encoding) == s)
Guido van Rossuma1374e42001-01-19 19:01:56 +0000716 except TestFailed:
Guido van Rossum9e896b32000-04-05 20:11:21 +0000717 print '*** codec "%s" failed round-trip' % encoding
718 except ValueError,why:
719 print '*** codec for "%s" failed: %s' % (encoding, why)
Guido van Rossumd8855fd2000-03-24 22:14:19 +0000720
721print 'done.'
Fred Drakee0243e22000-04-13 14:11:56 +0000722
723print 'Testing Unicode string concatenation...',
Marc-André Lemburg36619082001-01-17 19:11:13 +0000724verify((u"abc" u"def") == u"abcdef")
725verify(("abc" u"def") == u"abcdef")
726verify((u"abc" "def") == u"abcdef")
727verify((u"abc" u"def" "ghi") == u"abcdefghi")
728verify(("abc" "def" u"ghi") == u"abcdefghi")
Fred Drakee0243e22000-04-13 14:11:56 +0000729print 'done.'
Marc-André Lemburg0c4d8d02001-11-20 15:17:25 +0000730
731print 'Testing Unicode printing...',
732print u'abc'
733print u'abc', u'def'
734print u'abc', 'def'
735print 'abc', u'def'
736print u'abc\n'
737print u'abc\n',
738print u'abc\n',
739print u'def\n'
740print u'def\n'
741print 'done.'