[pypy-commit] pypy default: let host ord handle non-surrogate cases so we get proper exceptions, test
bdkearns
noreply at buildbot.pypy.org
Wed Feb 6 13:36:15 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r60902:093fe9b62735
Date: 2013-02-06 07:06 -0500
http://bitbucket.org/pypy/pypy/changeset/093fe9b62735/
Log: let host ord handle non-surrogate cases so we get proper exceptions,
test
diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py
--- a/rpython/rlib/runicode.py
+++ b/rpython/rlib/runicode.py
@@ -31,9 +31,7 @@
ch2 = ord(u[1])
if 0xD800 <= ch1 <= 0xDBFF and 0xDC00 <= ch2 <= 0xDFFF:
return (((ch1 - 0xD800) << 10) | (ch2 - 0xDC00)) + 0x10000
- if len(u) != 1:
- raise ValueError('not a surrogate')
- return ord(u[0])
+ return ord(u)
if MAXUNICODE > sys.maxunicode:
# A version of unichr which allows codes outside the BMP
diff --git a/rpython/rlib/test/test_runicode.py b/rpython/rlib/test/test_runicode.py
--- a/rpython/rlib/test/test_runicode.py
+++ b/rpython/rlib/test/test_runicode.py
@@ -5,16 +5,26 @@
from rpython.rlib import runicode
def test_unichr():
- a = runicode.UNICHR(0xffff)
- assert a == u'\uffff'
+ assert runicode.UNICHR(0xffff) == u'\uffff'
if runicode.MAXUNICODE > 0xffff:
- a = runicode.UNICHR(0x10000)
if sys.maxunicode < 0x10000:
- assert len(a) == 2 # surrogates
+ assert runicode.UNICHR(0x10000) == u'\ud800\udc00'
else:
- assert len(a) == 1
+ assert runicode.UNICHR(0x10000) == u'\U00010000'
else:
py.test.raises(ValueError, runicode.UNICHR, 0x10000)
+ py.test.raises(TypeError, runicode.UNICHR, 'abc')
+
+def test_ord():
+ assert runicode.ORD(u'\uffff') == 0xffff
+ if runicode.MAXUNICODE > 0xffff:
+ if sys.maxunicode < 0x10000:
+ assert runicode.ORD(u'\ud800\udc00') == 0x10000
+ else:
+ assert runicode.ORD(u'\U00010000') == 0x10000
+ else:
+ py.test.raises(TypeError, runicode.ORD, u'\ud800\udc00')
+ py.test.raises(TypeError, runicode.ORD, 'abc')
class UnicodeTests(object):
More information about the pypy-commit
mailing list