[pypy-commit] cffi default: Add a test

arigo noreply at buildbot.pypy.org
Sat Jul 7 14:27:28 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r590:1a023858061f
Date: 2012-07-07 14:27 +0200
http://bitbucket.org/cffi/cffi/changeset/1a023858061f/

Log:	Add a test

diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -1356,3 +1356,24 @@
     assert (p < s) is (p <= s) is (s > p) is (s >= p)
     assert (p > s) is (p >= s) is (s < p) is (s <= p)
     assert (p < s) ^ (p > s)
+
+def test_buffer():
+    BChar = new_primitive_type("char")
+    BCharArray = new_array_type(new_pointer_type(BChar), None)
+    c = newp(BCharArray, "hi there")
+    buf = buffer(c)
+    assert str(buf) == "hi there\x00"
+    assert len(buf) == len("hi there\x00")
+    assert buf[0] == 'h'
+    assert buf[2] == ' '
+    assert list(buf) == ['h', 'i', ' ', 't', 'h', 'e', 'r', 'e', '\x00']
+    buf[2] = '-'
+    assert c[2] == '-'
+    assert str(buf) == "hi-there\x00"
+    buf[:2] = 'HI'
+    assert str(c) == 'HI-there'
+    assert buf[:4:2] == 'H-'
+    if '__pypy__' not in sys.builtin_module_names:
+        # XXX pypy doesn't support the following assignment so far
+        buf[:4:2] = 'XY'
+        assert str(c) == 'XIYthere'


More information about the pypy-commit mailing list