[pypy-svn] r75425 - in pypy/trunk/pypy/rlib: . test

arigo at codespeak.net arigo at codespeak.net
Wed Jun 16 16:39:00 CEST 2010


Author: arigo
Date: Wed Jun 16 16:38:59 2010
New Revision: 75425

Modified:
   pypy/trunk/pypy/rlib/runicode.py
   pypy/trunk/pypy/rlib/test/test_runicode.py
Log:
Test and fix.


Modified: pypy/trunk/pypy/rlib/runicode.py
==============================================================================
--- pypy/trunk/pypy/rlib/runicode.py	(original)
+++ pypy/trunk/pypy/rlib/runicode.py	Wed Jun 16 16:38:59 2010
@@ -17,7 +17,7 @@
     # Note that Python3 uses a similar implementation.
     def UNICHR(c):
         assert not we_are_translated()
-        if c < sys.maxunicode or c > MAXUNICODE:
+        if c <= sys.maxunicode or c > MAXUNICODE:
             return unichr(c)
         else:
             c -= 0x10000

Modified: pypy/trunk/pypy/rlib/test/test_runicode.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_runicode.py	(original)
+++ pypy/trunk/pypy/rlib/test/test_runicode.py	Wed Jun 16 16:38:59 2010
@@ -2,6 +2,16 @@
 import sys, random
 from pypy.rlib import runicode
 
+def test_unichr():
+    a = runicode.UNICHR(0xffff)
+    assert a == u'\uffff'
+    a = runicode.UNICHR(0x10000)
+    if sys.maxunicode < 0x10000:
+        assert len(a) == 2      # surrogates
+    else:
+        assert len(a) == 1
+
+
 class UnicodeTests(object):
     def typeequals(self, x, y):
         assert x == y



More information about the Pypy-commit mailing list