[pypy-svn] r54624 - in pypy/branch/io-improvements/pypy/rlib: . test

fijal at codespeak.net fijal at codespeak.net
Sat May 10 17:07:13 CEST 2008


Author: fijal
Date: Sat May 10 17:07:12 2008
New Revision: 54624

Modified:
   pypy/branch/io-improvements/pypy/rlib/rstring.py
   pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py
Log:
UnicodeBuilder


Modified: pypy/branch/io-improvements/pypy/rlib/rstring.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/rstring.py	(original)
+++ pypy/branch/io-improvements/pypy/rlib/rstring.py	Sat May 10 17:07:12 2008
@@ -7,16 +7,21 @@
 
 INIT_SIZE = 100 # XXX tweak
 
-class StringBuilder(object):
+class AbstractStringBuilder(object):
     def __init__(self, init_size=INIT_SIZE):
         self.l = []
 
     def append(self, s):
         self.l.append(s)
 
+class StringBuilder(AbstractStringBuilder):
     def build(self):
         return "".join(self.l)
 
+class UnicodeBuilder(AbstractStringBuilder):
+    def build(self):
+        return u''.join(self.l)
+
 class StringBuilderEntry(ExtRegistryEntry):
     _about_ = StringBuilder
 
@@ -31,3 +36,6 @@
 
     def specialize_call(self, hop):
         return hop.r_result.rtyper_new(hop)
+
+class UnicodeBuilderEntry(ExtRegistryEntry):
+    pass

Modified: pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py	(original)
+++ pypy/branch/io-improvements/pypy/rlib/test/test_rstring.py	Sat May 10 17:07:12 2008
@@ -1,6 +1,5 @@
 
-from pypy.rlib.rstring import StringBuilder
-from 
+from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
 
 def test_string_builder():
     s = StringBuilder()
@@ -8,3 +7,11 @@
     s.append("abc")
     s.append("a")
     assert s.build() == "aabca"
+
+def test_unicode_builder():
+    s = UnicodeBuilder()
+    s.append(u'a')
+    s.append(u'abc')
+    s.append(u'abcdef')
+    assert s.build() == 'aabcabcdef'
+    assert isinstance(s.build(), unicode)



More information about the Pypy-commit mailing list