cimport cython.operator
from cython.operator cimport dereference as deref
+cdef out(s):
+ print s.decode('ASCII')
+
cdef extern from "cpp_operators_helper.h":
cdef cppclass TestOps:
unary *
"""
cdef TestOps* t = new TestOps()
- print +t[0]
- print -t[0]
- print ~t[0]
- print deref(t[0])
+ out(+t[0])
+ out(-t[0])
+ out(~t[0])
+ out(deref(t[0]))
del t
def test_incdec():
post --
"""
cdef TestOps* t = new TestOps()
- print cython.operator.preincrement(t[0])
- print cython.operator.predecrement(t[0])
- print cython.operator.postincrement(t[0])
- print cython.operator.postdecrement(t[0])
+ out(cython.operator.preincrement(t[0]))
+ out(cython.operator.predecrement(t[0]))
+ out(cython.operator.postincrement(t[0]))
+ out(cython.operator.postdecrement(t[0]))
del t
def test_binop():
binary >>
"""
cdef TestOps* t = new TestOps()
- print t[0] + 1
- print t[0] - 1
- print t[0] * 1
- print t[0] / 1
- print t[0] % 1
+ out(t[0] + 1)
+ out(t[0] - 1)
+ out(t[0] * 1)
+ out(t[0] / 1)
+ out(t[0] % 1)
- print t[0] & 1
- print t[0] | 1
- print t[0] ^ 1
+ out(t[0] & 1)
+ out(t[0] | 1)
+ out(t[0] ^ 1)
- print t[0] << 1
- print t[0] >> 1
+ out(t[0] << 1)
+ out(t[0] >> 1)
del t
def test_cmp():
binary <
"""
cdef TestOps* t = new TestOps()
- print t[0] == 1
- print t[0] != 1
- print t[0] >= 1
- print t[0] > 1
- print t[0] <= 1
- print t[0] < 1
+ out(t[0] == 1)
+ out(t[0] != 1)
+ out(t[0] >= 1)
+ out(t[0] > 1)
+ out(t[0] <= 1)
+ out(t[0] < 1)
del t
def test_index_call():
binary ()
"""
cdef TestOps* t = new TestOps()
- print t[0][100]
- print t[0](100)
+ out(t[0][100])
+ out(t[0](100))
del t