blob: 06c83b0a8482f9247136e3b0fc4f099e329088c1 [file] [log] [blame]
Guido van Rossum0874f7f1997-10-27 22:15:06 +00001# Tests for the 'tokenize' module.
Tim Peters3b5de4d2003-02-19 02:44:12 +00002# Large bits stolen from test_grammar.py.
Guido van Rossum0874f7f1997-10-27 22:15:06 +00003
4# Comments
5"#"
6#'
7#"
8#\
9 #
10 # abc
11'''#
12#'''
13
14x = 1 #
15
16# Balancing continuation
17
18a = (3, 4,
19 5, 6)
20y = [3, 4,
21 5]
22z = {'a':5,
23 'b':6}
Brett Cannon0b70cca2006-08-25 02:59:59 +000024x = (len(repr(y)) + 5*x - a[
Guido van Rossum0874f7f1997-10-27 22:15:06 +000025 3 ]
26 - x + len({
27 }
28 )
29 )
30
31# Backslash means line continuation:
32x = 1 \
33+ 1
34
35# Backslash does not means continuation in comments :\
36x = 0
37
38# Ordinary integers
Guido van Rossumb053cd82006-08-24 03:53:23 +0000390xff != 255
Guido van Rossumcd16bf62007-06-13 18:07:49 +0000400o377 != 255
412147483647 != 0o17777777777
42-2147483647-1 != 0o20000000000
430o37777777777 != -1
440xffffffff != -1; 0o37777777777 != -1; -0o1234567 == 0O001234567; 0b10101 == 0B00010101
Guido van Rossum0874f7f1997-10-27 22:15:06 +000045
46# Long integers
Guido van Rossumcd16bf62007-06-13 18:07:49 +000047x = 0
48x = 0
49x = 0xffffffffffffffff
50x = 0xffffffffffffffff
51x = 0o77777777777777777
52x = 0B11101010111111111
53x = 123456789012345678901234567890
54x = 123456789012345678901234567890
Guido van Rossum0874f7f1997-10-27 22:15:06 +000055
56# Floating-point numbers
57x = 3.14
58x = 314.
59x = 0.314
60# XXX x = 000.314
61x = .314
62x = 3e14
63x = 3E14
64x = 3e-14
65x = 3e+14
66x = 3.e14
67x = .3e14
68x = 3.1e4
69
70# String literals
71x = ''; y = "";
72x = '\''; y = "'";
73x = '"'; y = "\"";
74x = "doesn't \"shrink\" does it"
75y = 'doesn\'t "shrink" does it'
76x = "does \"shrink\" doesn't it"
77y = 'does "shrink" doesn\'t it'
78x = """
79The "quick"
80brown fox
81jumps over
82the 'lazy' dog.
83"""
84y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
85y = '''
86The "quick"
87brown fox
88jumps over
89the 'lazy' dog.
90''';
91y = "\n\
92The \"quick\"\n\
93brown fox\n\
94jumps over\n\
95the 'lazy' dog.\n\
96";
97y = '\n\
98The \"quick\"\n\
99brown fox\n\
100jumps over\n\
101the \'lazy\' dog.\n\
102';
103x = r'\\' + R'\\'
104x = r'\'' + ''
105y = r'''
106foo bar \\
107baz''' + R'''
108foo'''
109y = r"""foo
110bar \\ baz
111""" + R'''spam
112'''
Guido van Rossum4fe72f92007-11-12 17:40:10 +0000113x = b'abc' + B'ABC'
114y = b"abc" + B"ABC"
115x = br'abc' + Br'ABC' + bR'ABC' + BR'ABC'
116y = br"abc" + Br"ABC" + bR"ABC" + BR"ABC"
117x = br'\\' + BR'\\'
118x = br'\'' + ''
119y = br'''
Ka-Ping Yee1ff08b12001-01-15 22:04:30 +0000120foo bar \\
Guido van Rossum4fe72f92007-11-12 17:40:10 +0000121baz''' + BR'''
Ka-Ping Yee1ff08b12001-01-15 22:04:30 +0000122foo'''
Guido van Rossum4fe72f92007-11-12 17:40:10 +0000123y = Br"""foo
Ka-Ping Yee1ff08b12001-01-15 22:04:30 +0000124bar \\ baz
Guido van Rossum4fe72f92007-11-12 17:40:10 +0000125""" + bR'''spam
Ka-Ping Yee1ff08b12001-01-15 22:04:30 +0000126'''
Guido van Rossum0874f7f1997-10-27 22:15:06 +0000127
128# Indentation
129if 1:
130 x = 2
131if 1:
Tim Peters3b5de4d2003-02-19 02:44:12 +0000132 x = 2
Guido van Rossum0874f7f1997-10-27 22:15:06 +0000133if 1:
134 while 0:
Tim Peters3b5de4d2003-02-19 02:44:12 +0000135 if 0:
136 x = 2
137 x = 2
Guido van Rossum0874f7f1997-10-27 22:15:06 +0000138if 0:
Tim Peters3b5de4d2003-02-19 02:44:12 +0000139 if 2:
140 while 0:
141 if 1:
142 x = 2
Guido van Rossum0874f7f1997-10-27 22:15:06 +0000143
144# Operators
145
146def d22(a, b, c=1, d=2): pass
Jeremy Hyltona4553c02001-04-13 14:36:51 +0000147def d01v(a=1, *restt, **restd): pass
Guido van Rossum0874f7f1997-10-27 22:15:06 +0000148
Guido van Rossumb053cd82006-08-24 03:53:23 +0000149(x, y) != ({'a':1}, {'b':2})
Guido van Rossum0874f7f1997-10-27 22:15:06 +0000150
151# comparison
Guido van Rossumb053cd82006-08-24 03:53:23 +0000152if 1 < 1 > 1 == 1 >= 1 <= 1 != 1 != 1 in 1 not in 1 is 1 is not 1: pass
Guido van Rossum0874f7f1997-10-27 22:15:06 +0000153
154# binary
155x = 1 & 1
156x = 1 ^ 1
157x = 1 | 1
158
159# shift
160x = 1 << 1 >> 1
161
162# additive
163x = 1 - 1 + 1 - 1 + 1
164
165# multiplicative
166x = 1 / 1 * 1 % 1
167
168# unary
169x = ~1 ^ 1 & 1 | 1 & 1 ^ -1
170x = -1*1/1 + 1*1 - ---1*1
171
172# selector
173import sys, time
174x = sys.modules['time'].time()
Tim Peters3b5de4d2003-02-19 02:44:12 +0000175
Anthony Baxterc2a5a632004-08-02 06:10:11 +0000176@staticmethod
177def foo(): pass
178
Neal Norwitzc1505362006-12-28 06:47:50 +0000179@staticmethod
180def foo(x:1)->1: pass
181