Commit 702f1f4d authored by Robert Bradshaw's avatar Robert Bradshaw

Tests for conditional expressions with refernces.

parent f2c71d24
# mode: run
# tag: condexpr, cpp
cdef extern from "if_else_expr_cpp_helper.h":
cdef cppclass Holder:
int value
Holder()
Holder(int value)
cdef Holder v1
cdef Holder v2
cdef Holder& get_v1()
cdef Holder& get_v2()
cdef reset() :
v1.value = 1
v2.value = 2
def test_one_ref(bint b):
"""
>>> test_one_ref(False)
1
>>> test_one_ref(True)
100
"""
reset()
return (Holder(100) if b else get_v1()).value
def test_both_ref(bint b):
"""
>>> test_both_ref(False)
(1, 100)
>>> test_both_ref(True)
(100, 2)
"""
reset()
try:
(get_v1() if b else get_v2()).value = 100
return v1.value, v2.value
finally:
reset()
class Holder {
public:
int value;
Holder() : value(-1) { }
Holder(int value) : value(value) { }
};
Holder v1(1);
Holder v2(2);
Holder& get_v1() {
return v1;
}
Holder& get_v2() {
return v2;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment