[pypy-svn] r49196 - in pypy/dist/pypy/rpython: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Nov 29 01:59:01 CET 2007


Author: cfbolz
Date: Thu Nov 29 01:59:00 2007
New Revision: 49196

Modified:
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/test/test_runicode.py
Log:
make sure that unicode(u'...') is not trying to make sure the argument is ascii.


Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Thu Nov 29 01:59:00 2007
@@ -252,6 +252,9 @@
             return hop.inputconst(hop.r_result, hop.s_result.const)
         repr = hop.args_r[0].repr
         v_str = hop.inputarg(repr, 0)
+        if repr == self.repr: # the argument is a unicode string already
+            hop.exception_cannot_occur()
+            return v_str
         hop.exception_is_here()
         return hop.gendirectcall(self.ll.ll_str2unicode, v_str)
 

Modified: pypy/dist/pypy/rpython/test/test_runicode.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_runicode.py	(original)
+++ pypy/dist/pypy/rpython/test/test_runicode.py	Thu Nov 29 01:59:00 2007
@@ -46,6 +46,20 @@
 
         assert self.ll_to_string(self.interpret(f, [])) == 'xxx'
 
+    def test_unicode_of_unicode(self):
+        def f(x):
+            return len(unicode(unichr(x) * 3))
+        assert self.interpret(f, [ord('a')]) == 3
+        assert self.interpret(f, [128]) == 3
+        assert self.interpret(f, [1000]) == 3
+
+    def test_unicode_of_unichar(self):
+        def f(x):
+            return len(unicode(unichr(x)))
+        assert self.interpret(f, [ord('a')]) == 1
+        assert self.interpret(f, [128]) == 1
+        assert self.interpret(f, [1000]) == 1
+
     def test_conversion_errors(self):
         py.test.skip("do we want this test to pass?")
         def f(x):



More information about the Pypy-commit mailing list