added doctest to compile test case
authorStefan Behnel <scoder@users.berlios.de>
Wed, 28 Oct 2009 07:57:12 +0000 (08:57 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 28 Oct 2009 07:57:12 +0000 (08:57 +0100)
--HG--
rename : tests/compile/coercearraytoptr.pyx => tests/run/coercearraytoptr.pyx

tests/compile/coercearraytoptr.pyx [deleted file]
tests/run/coercearraytoptr.pyx [new file with mode: 0644]

diff --git a/tests/compile/coercearraytoptr.pyx b/tests/compile/coercearraytoptr.pyx
deleted file mode 100644 (file)
index 5c5ad65..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-cdef extern void spam(char *s)
-
-cdef struct Grail:
-    char silly[42]
-
-cdef void eggs():
-    cdef char silly[42]
-    cdef Grail grail
-    spam(silly)
-    spam(grail.silly)
-
-eggs()
diff --git a/tests/run/coercearraytoptr.pyx b/tests/run/coercearraytoptr.pyx
new file mode 100644 (file)
index 0000000..fb68076
--- /dev/null
@@ -0,0 +1,24 @@
+
+cdef char* cstring = "abcdefg"
+
+cdef void spam(char *target):
+    cdef char* s = cstring
+    while s[0]:
+        target[0] = s[0]
+        s += 1
+        target += 1
+    target[0] = c'\0'
+
+cdef struct Grail:
+    char silly[42]
+
+def eggs():
+    """
+    >>> print(str(eggs()).replace("b'", "'"))
+    ('abcdefg', 'abcdefg')
+    """
+    cdef char silly[42]
+    cdef Grail grail
+    spam(silly)
+    spam(grail.silly)
+    return silly, grail.silly