tokenize_tests.txt 2.49 KB
Newer Older
1
# Tests for the 'tokenize' module.
2
# Large bits stolen from test_grammar.py. 
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

# Comments
"#"
#'
#"
#\
       #
    # abc
'''#
#'''

x = 1  #

# Balancing continuation

a = (3, 4,
  5, 6)
y = [3, 4,
  5]
z = {'a':5,
  'b':6}
24
x = (len(repr(y)) + 5*x - a[
25 26 27 28 29 30 31 32 33 34 35 36 37 38
   3 ]
   - x + len({
   }
    )
  )

# Backslash means line continuation:
x = 1 \
+ 1

# Backslash does not means continuation in comments :\
x = 0

# Ordinary integers
39
0xff != 255
40 41 42 43 44
0o377 != 255
2147483647   != 0o17777777777
-2147483647-1 != 0o20000000000
0o37777777777 != -1
0xffffffff != -1; 0o37777777777 != -1; -0o1234567 == 0O001234567; 0b10101 == 0B00010101
45 46

# Long integers
47 48 49 50 51 52 53 54
x = 0
x = 0
x = 0xffffffffffffffff
x = 0xffffffffffffffff
x = 0o77777777777777777
x = 0B11101010111111111
x = 123456789012345678901234567890
x = 123456789012345678901234567890
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

# Floating-point numbers
x = 3.14
x = 314.
x = 0.314
# XXX x = 000.314
x = .314
x = 3e14
x = 3E14
x = 3e-14
x = 3e+14
x = 3.e14
x = .3e14
x = 3.1e4

# String literals
x = ''; y = "";
x = '\''; y = "'";
x = '"'; y = "\"";
x = "doesn't \"shrink\" does it"
y = 'doesn\'t "shrink" does it'
x = "does \"shrink\" doesn't it"
y = 'does "shrink" doesn\'t it'
x = """
The "quick"
brown fox
jumps over
the 'lazy' dog.
"""
y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
y = '''
The "quick"
brown fox
jumps over
the 'lazy' dog.
''';
y = "\n\
The \"quick\"\n\
brown fox\n\
jumps over\n\
the 'lazy' dog.\n\
";
y = '\n\
The \"quick\"\n\
brown fox\n\
jumps over\n\
the \'lazy\' dog.\n\
';
x = r'\\' + R'\\'
x = r'\'' + ''
y = r'''
foo bar \\
baz''' + R'''
foo'''
y = r"""foo
bar \\ baz
""" + R'''spam
'''
113 114 115 116 117 118 119
x = b'abc' + B'ABC'
y = b"abc" + B"ABC"
x = br'abc' + Br'ABC' + bR'ABC' + BR'ABC'
y = br"abc" + Br"ABC" + bR"ABC" + BR"ABC"
x = br'\\' + BR'\\'
x = br'\'' + ''
y = br'''
120
foo bar \\
121
baz''' + BR'''
122
foo'''
123
y = Br"""foo
124
bar \\ baz
125
""" + bR'''spam
126
'''
127 128 129 130 131

# Indentation
if 1:
    x = 2
if 1:
132
        x = 2
133 134
if 1:
    while 0:
135 136 137
     if 0:
           x = 2
     x = 2
138
if 0:
139 140 141 142
  if 2:
   while 0:
        if 1:
          x = 2
143 144 145 146

# Operators

def d22(a, b, c=1, d=2): pass
147
def d01v(a=1, *restt, **restd): pass
148

149
(x, y) != ({'a':1}, {'b':2})
150 151

# comparison
152
if 1 < 1 > 1 == 1 >= 1 <= 1 != 1 != 1 in 1 not in 1 is 1 is not 1: pass
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

# binary
x = 1 & 1
x = 1 ^ 1
x = 1 | 1

# shift
x = 1 << 1 >> 1

# additive
x = 1 - 1 + 1 - 1 + 1

# multiplicative
x = 1 / 1 * 1 % 1

# unary
x = ~1 ^ 1 & 1 | 1 & 1 ^ -1
x = -1*1/1 + 1*1 - ---1*1

# selector
import sys, time
x = sys.modules['time'].time()
175

176 177 178
@staticmethod
def foo(): pass

179 180 181
@staticmethod
def foo(x:1)->1: pass