From daad5d3eda0b10bad25897e81ac743e856f4087c Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sat, 16 Aug 2008 01:52:45 -0700 Subject: [PATCH] inplace side effect tests --- tests/run/inplace.pyx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/run/inplace.pyx b/tests/run/inplace.pyx index 6d83016d..2d7c6a9c 100644 --- a/tests/run/inplace.pyx +++ b/tests/run/inplace.pyx @@ -16,6 +16,13 @@ __doc__ = u""" >>> smoketest() 10 + + >>> test_side_effects() + side effect 1 + c side effect 2 + side effect 3 + c side effect 4 + ([0, 11, 102, 3, 4], [0, 1, 2, 13, 104]) """ def f(a,b): @@ -83,3 +90,23 @@ def smoketest(): print a.buf[1] stdlib.free(buf) + +def side_effect(x): + print "side effect", x + return x + +cdef int c_side_effect(int x): + print "c side effect", x + return x + +def test_side_effects(): + a = range(5) + a[side_effect(1)] += 10 + a[c_side_effect(2)] += 100 + cdef int i + cdef int b[5] + for i from 0 <= i < 5: + b[i] = i + b[side_effect(3)] += 10 + b[c_side_effect(4)] += 100 + return a, [b[i] for i from 0 <= i < 5] -- 2.26.2