summaryrefslogtreecommitdiff
path: root/tests/run/ifelseexpr_T267.pyx
blob: 973c1979a1407f0e35377553c009aaabb4b84c5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# mode: run
# tag: condexpr
# ticket: t267

cimport cython

def ident(x): return x

def constants(x):
    """
    >>> constants(4)
    1
    >>> constants(5)
    10
    """
    a = 1 if x < 5 else 10
    return a

def temps(x):
    """
    >>> temps(4)
    1
    >>> temps(5)
    10
    """
    return ident(1) if ident(x) < ident(5) else ident(10)


def nested(x):
    """
    >>> nested(1)
    1
    >>> nested(2)
    2
    >>> nested(3)
    3
    """
    a = 1 if x == 1 else (2 if x == 2 else 3)
    return a


@cython.test_fail_if_path_exists('//CondExprNode')
def const_true(a,b):
    """
    >>> const_true(1,2)
    1
    """
    return a if 1 == 1 else b

@cython.test_fail_if_path_exists('//CondExprNode')
def const_false(a,b):
    """
    >>> const_false(1,2)
    2
    """
    return a if 1 != 1 else b