From: Stefan Behnel Date: Thu, 18 Dec 2008 09:19:38 +0000 (+0100) Subject: more tests for for-loops and constant expressions X-Git-Tag: 0.11-beta~118 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1f7b40c4710e7e19e6c667aabdb844d8f9d7f3fb;p=cython.git more tests for for-loops and constant expressions --- diff --git a/tests/run/consts.pyx b/tests/run/consts.pyx index 6e1fe8df..d6c500f4 100644 --- a/tests/run/consts.pyx +++ b/tests/run/consts.pyx @@ -3,25 +3,38 @@ __doc__ = u""" True >>> add_var(10) == 1+2+10+3+4 True +>>> neg() == -1 -2 - (-3+4) +True >>> mul() == 1*60*1000 True >>> arithm() == 9*2+3*8/6-10 True +>>> parameters() == _func(-1 -2, - (-3+4), 1*2*3) +True >>> lists() == [1,2,3] + [4,5,6] True """ +def _func(a,b,c): + return a+b+c + def add(): return 1+2+3+4 def add_var(a): return 1+2 +a+ 3+4 +def neg(): + return -1 -2 - (-3+4) + def mul(): return 1*60*1000 def arithm(): return 9*2+3*8/6-10 +def parameters(): + return _func(-1 -2, - (-3+4), 1*2*3) + def lists(): return [1,2,3] + [4,5,6] diff --git a/tests/run/r_forloop.pyx b/tests/run/r_forloop.pyx index 35949e03..4f5b6523 100644 --- a/tests/run/r_forloop.pyx +++ b/tests/run/r_forloop.pyx @@ -21,6 +21,9 @@ __doc__ = u""" >>> go_c_all_exprs(3) Spam! Spam! + >>> go_c_const_exprs() + Spam! + Spam! >>> go_c_calc(2) Spam! Spam! @@ -52,6 +55,9 @@ __doc__ = u""" Spam! >>> go_dict_ret() 2 + + >>> global_result + 6 """ def go_py(): @@ -78,6 +84,11 @@ def go_c_all_exprs(x): for i in range(4*x,2*x,-3): print u"Spam!" +def go_c_const_exprs(): + cdef int i + for i in range(4*2+1,2*2,-2-1): + print u"Spam!" + def f(x): return 2*x @@ -130,3 +141,11 @@ def go_dict_ret(): for i in d: if i > 1 and i < 3: return i + +# test global scope also +global_result = None +cdef int i +for i in range(4*2+1,2*2,-2-1): + if i < 7: + global_result = i + break