blob: 48836683045ee83a9b2c07166ea98f491b24ff69 [file] [log] [blame]
Guido van Rossum0874f7f1997-10-27 22:15:06 +00001# Tests for the 'tokenize' module.
2# Large bits stolen from test_grammar.py.
3
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}
24x = (len(`y`) + 5*x - a[
25 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
390xff <> 255
400377 <> 255
412147483647 != 017777777777
42-2147483647-1 != 020000000000
43037777777777 != -1
440xffffffff != -1
45
46# Long integers
47x = 0L
48x = 0l
49x = 0xffffffffffffffffL
50x = 0xffffffffffffffffl
51x = 077777777777777777L
52x = 077777777777777777l
53x = 123456789012345678901234567890L
54x = 123456789012345678901234567890l
55
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'''
113
114# Indentation
115if 1:
116 x = 2
117if 1:
118 x = 2
119if 1:
120 while 0:
121 if 0:
122 x = 2
123 x = 2
124if 0:
125 if 2:
126 while 0:
127 if 1:
128 x = 2
129
130# Operators
131
132def d22(a, b, c=1, d=2): pass
133def d01v(a=1, *rest, **rest): pass
134
135(x, y) <> ({'a':1}, {'b':2})
136
137# comparison
138if 1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1: pass
139
140# binary
141x = 1 & 1
142x = 1 ^ 1
143x = 1 | 1
144
145# shift
146x = 1 << 1 >> 1
147
148# additive
149x = 1 - 1 + 1 - 1 + 1
150
151# multiplicative
152x = 1 / 1 * 1 % 1
153
154# unary
155x = ~1 ^ 1 & 1 | 1 & 1 ^ -1
156x = -1*1/1 + 1*1 - ---1*1
157
158# selector
159import sys, time
160x = sys.modules['time'].time()
161