summaryrefslogtreecommitdiff
path: root/tests/run/literals.pyx
blob: 46c53d2adb586f1e86d913ac11e93d17436cd879 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# mode: run

def foo():
    """
    >>> foo()
    """
    a = 42
    a1 = 0123
    an1 = -0123
    assert a1 == -an1
    a2 = 0xabc
    an2 = -0xabc
    assert a2 == -an2
    a3 = 0xDEF
    an3 = -0xDEF
    assert a3 == -an3
    a4 = 1234567890L
    an4 = -1234567890L
    assert a4 == -an4
    a5 = 0o123
    an5 = -0o123
    assert a5 == -an5
    assert a5 == a1
    a6 = 0b101
    an6 = -0b101
    assert a6 == -an6 == 5

    b = 42.88e17
    b0a = 1.
    b0b = .1
    b0c = 1.1
    b0d = 1.e1
    b0e = .1e1
    b0f = 1.1e1
    b0g = 1.1e-1
    b0h = 1e1

    b1 = 3j
    b2 = 3.1415J

    b3 = c'X'
    c = "spanish inquisition"
    d = "this" "parrot" "is" "resting"
    e = 'single quoted string'
    f = '"this is quoted"'
    g = '''Triple single quoted string.'''
    h = """Triple double quoted string."""
    g1 = '''Two line triple
single quoted string.'''
    h1 = """Two line triple
double quoted string."""
    i = 'This string\
 has an ignored newline.'
    j = 'One-char escapes: \'\"\\\a\b\f\n\r\t\v'
    k = b'Oct and hex escapes: \1 \12 \123 \x45 \xaf \xAF'
    l = r'''This is\
a \three \line
raw string with some backslashes.'''
    m = 'Three backslashed ordinaries: \c\g\+'
    n = '''Triple single quoted string
with ' and " quotes'''
    o = """Triple double quoted string
with ' and " quotes"""
    p = "name_like_string"
    q = "NameLikeString2"
    r = "99_percent_un_namelike"
    s = "Not an \escape"
    t = b'this' b'parrot' b'is' b'resting'
    u = u'this' u'parrot' u'is' u'resting'


def test_float(x):
    """
    >>> test_float(1./3)
    True
    """
    return x == 1./3

def test_complex(x):
    """
    >>> test_complex(1j/3)
    True
    """
    return x == 0.3333333333333333j

def test_large_int(double x):
    """
    >>> test_large_int(0)
    2e+100
    """
    a = x + 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    a += 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    return a