[pypy-svn] r48716 - in pypy/branch/ropes-unicode/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Nov 15 18:44:19 CET 2007


Author: cfbolz
Date: Thu Nov 15 18:44:18 2007
New Revision: 48716

Modified:
   pypy/branch/ropes-unicode/pypy/objspace/std/rope.py
   pypy/branch/ropes-unicode/pypy/objspace/std/test/test_rope.py
Log:
some tests for unicode support in ropes


Modified: pypy/branch/ropes-unicode/pypy/objspace/std/rope.py
==============================================================================
--- pypy/branch/ropes-unicode/pypy/objspace/std/rope.py	(original)
+++ pypy/branch/ropes-unicode/pypy/objspace/std/rope.py	Thu Nov 15 18:44:18 2007
@@ -220,7 +220,7 @@
     def getunichar(self, index):
         return self.u[index]
 
-    def getbyte(self, index):
+    def getint(self, index):
         return ord(self.u[index])
 
     def getslice(self, start, stop):

Modified: pypy/branch/ropes-unicode/pypy/objspace/std/test/test_rope.py
==============================================================================
--- pypy/branch/ropes-unicode/pypy/objspace/std/test/test_rope.py	(original)
+++ pypy/branch/ropes-unicode/pypy/objspace/std/test/test_rope.py	Thu Nov 15 18:44:18 2007
@@ -1,8 +1,9 @@
 import py
-import random
+import random, sys
 from pypy.objspace.std.rope import *
 
-def make_random_string(operations=10, slicing=True, print_seed=True):
+def make_random_string(operations=10, slicing=True, print_seed=True,
+                       unicode=False):
     seed = random.randrange(10000)
     if print_seed:
         print seed
@@ -14,14 +15,20 @@
     else:
         choice = [0, 1]
     for i in range(operations):
-        a = (chr(random.randrange(ord('a'), ord('z') + 1)) *
-                random.randrange(500))
+        if not unicode:
+            a = (chr(random.randrange(ord('a'), ord('z') + 1)) *
+                    random.randrange(500))
+            node = LiteralStringNode(a)
+        else:
+            a = (unichr(random.randrange(sys.maxunicode)) *
+                        random.randrange(500))
+            node = LiteralUnicodeNode(a)
         c = random.choice(choice)
         if c == 0:
-            curr = curr + LiteralStringNode(a)
+            curr = curr + node
             st = st + a
         elif c == 1:
-            curr = LiteralStringNode(a) + curr
+            curr = node + curr
             st = a + st
         else:
             if len(st) < 10:
@@ -82,6 +89,14 @@
             assert s.getchar(i) == result[i]
             assert s.getint(i) == ord(result[i])
 
+def test_getitem_unicode():
+    s1, result = make_random_string(200, unicode=True)
+    s2 = s1.rebalance()
+    for i in range(len(result)):
+        for s in [s1, s2]:
+            assert s.getunichar(i) == result[i]
+            assert s.getint(i) == ord(result[i])
+
 def test_getslice():
     result = "".join([c * 32 for c in "a", "bc", "d", "ef"])
     s1 = (LiteralStringNode("a" * 32) + LiteralStringNode("bc" * 32) +



More information about the Pypy-commit mailing list