Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / test / test_grammar.py
CommitLineData
920dae64
AT
1# Python test set -- part 1, grammar.
2# This just tests whether the parser accepts them all.
3
4# NOTE: When you run this test as a script from the command line, you
5# get warnings about certain hex/oct constants. Since those are
6# issued by the parser, you can't suppress them by adding a
7# filterwarnings() call to this module. Therefore, to shut up the
8# regression test, the filterwarnings() call has been added to
9# regrtest.py.
10
11from test.test_support import TestFailed, verify, check_syntax
12import sys
13
14print '1. Parser'
15
16print '1.1 Tokens'
17
18print '1.1.1 Backslashes'
19
20# Backslash means line continuation:
21x = 1 \
22+ 1
23if x != 2: raise TestFailed, 'backslash for line continuation'
24
25# Backslash does not means continuation in comments :\
26x = 0
27if x != 0: raise TestFailed, 'backslash ending comment'
28
29print '1.1.2 Numeric literals'
30
31print '1.1.2.1 Plain integers'
32if 0xff != 255: raise TestFailed, 'hex int'
33if 0377 != 255: raise TestFailed, 'octal int'
34if 2147483647 != 017777777777: raise TestFailed, 'large positive int'
35try:
36 from sys import maxint
37except ImportError:
38 maxint = 2147483647
39if maxint == 2147483647:
40 # The following test will start to fail in Python 2.4;
41 # change the 020000000000 to -020000000000
42 if -2147483647-1 != -020000000000: raise TestFailed, 'max negative int'
43 # XXX -2147483648
44 if 037777777777 < 0: raise TestFailed, 'large oct'
45 if 0xffffffff < 0: raise TestFailed, 'large hex'
46 for s in '2147483648', '040000000000', '0x100000000':
47 try:
48 x = eval(s)
49 except OverflowError:
50 print "OverflowError on huge integer literal " + repr(s)
51elif eval('maxint == 9223372036854775807'):
52 if eval('-9223372036854775807-1 != -01000000000000000000000'):
53 raise TestFailed, 'max negative int'
54 if eval('01777777777777777777777') < 0: raise TestFailed, 'large oct'
55 if eval('0xffffffffffffffff') < 0: raise TestFailed, 'large hex'
56 for s in '9223372036854775808', '02000000000000000000000', \
57 '0x10000000000000000':
58 try:
59 x = eval(s)
60 except OverflowError:
61 print "OverflowError on huge integer literal " + repr(s)
62else:
63 print 'Weird maxint value', maxint
64
65print '1.1.2.2 Long integers'
66x = 0L
67x = 0l
68x = 0xffffffffffffffffL
69x = 0xffffffffffffffffl
70x = 077777777777777777L
71x = 077777777777777777l
72x = 123456789012345678901234567890L
73x = 123456789012345678901234567890l
74
75print '1.1.2.3 Floating point'
76x = 3.14
77x = 314.
78x = 0.314
79# XXX x = 000.314
80x = .314
81x = 3e14
82x = 3E14
83x = 3e-14
84x = 3e+14
85x = 3.e14
86x = .3e14
87x = 3.1e4
88
89print '1.1.3 String literals'
90
91x = ''; y = ""; verify(len(x) == 0 and x == y)
92x = '\''; y = "'"; verify(len(x) == 1 and x == y and ord(x) == 39)
93x = '"'; y = "\""; verify(len(x) == 1 and x == y and ord(x) == 34)
94x = "doesn't \"shrink\" does it"
95y = 'doesn\'t "shrink" does it'
96verify(len(x) == 24 and x == y)
97x = "does \"shrink\" doesn't it"
98y = 'does "shrink" doesn\'t it'
99verify(len(x) == 24 and x == y)
100x = """
101The "quick"
102brown fox
103jumps over
104the 'lazy' dog.
105"""
106y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
107verify(x == y)
108y = '''
109The "quick"
110brown fox
111jumps over
112the 'lazy' dog.
113'''; verify(x == y)
114y = "\n\
115The \"quick\"\n\
116brown fox\n\
117jumps over\n\
118the 'lazy' dog.\n\
119"; verify(x == y)
120y = '\n\
121The \"quick\"\n\
122brown fox\n\
123jumps over\n\
124the \'lazy\' dog.\n\
125'; verify(x == y)
126
127
128print '1.2 Grammar'
129
130print 'single_input' # NEWLINE | simple_stmt | compound_stmt NEWLINE
131# XXX can't test in a script -- this rule is only used when interactive
132
133print 'file_input' # (NEWLINE | stmt)* ENDMARKER
134# Being tested as this very moment this very module
135
136print 'expr_input' # testlist NEWLINE
137# XXX Hard to test -- used only in calls to input()
138
139print 'eval_input' # testlist ENDMARKER
140x = eval('1, 0 or 1')
141
142print 'funcdef'
143### 'def' NAME parameters ':' suite
144### parameters: '(' [varargslist] ')'
145### varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' ('**'|'*' '*') NAME]
146### | ('**'|'*' '*') NAME)
147### | fpdef ['=' test] (',' fpdef ['=' test])* [',']
148### fpdef: NAME | '(' fplist ')'
149### fplist: fpdef (',' fpdef)* [',']
150### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test)
151### argument: [test '='] test # Really [keyword '='] test
152def f1(): pass
153f1()
154f1(*())
155f1(*(), **{})
156def f2(one_argument): pass
157def f3(two, arguments): pass
158def f4(two, (compound, (argument, list))): pass
159def f5((compound, first), two): pass
160verify(f2.func_code.co_varnames == ('one_argument',))
161verify(f3.func_code.co_varnames == ('two', 'arguments'))
162if sys.platform.startswith('java'):
163 verify(f4.func_code.co_varnames ==
164 ('two', '(compound, (argument, list))', 'compound', 'argument',
165 'list',))
166 verify(f5.func_code.co_varnames ==
167 ('(compound, first)', 'two', 'compound', 'first'))
168else:
169 verify(f4.func_code.co_varnames == ('two', '.2', 'compound',
170 'argument', 'list'))
171 verify(f5.func_code.co_varnames == ('.0', 'two', 'compound', 'first'))
172def a1(one_arg,): pass
173def a2(two, args,): pass
174def v0(*rest): pass
175def v1(a, *rest): pass
176def v2(a, b, *rest): pass
177def v3(a, (b, c), *rest): return a, b, c, rest
178if sys.platform.startswith('java'):
179 verify(v3.func_code.co_varnames == ('a', '(b, c)', 'rest', 'b', 'c'))
180else:
181 verify(v3.func_code.co_varnames == ('a', '.2', 'rest', 'b', 'c'))
182verify(v3(1, (2, 3), 4) == (1, 2, 3, (4,)))
183def d01(a=1): pass
184d01()
185d01(1)
186d01(*(1,))
187d01(**{'a':2})
188def d11(a, b=1): pass
189d11(1)
190d11(1, 2)
191d11(1, **{'b':2})
192def d21(a, b, c=1): pass
193d21(1, 2)
194d21(1, 2, 3)
195d21(*(1, 2, 3))
196d21(1, *(2, 3))
197d21(1, 2, *(3,))
198d21(1, 2, **{'c':3})
199def d02(a=1, b=2): pass
200d02()
201d02(1)
202d02(1, 2)
203d02(*(1, 2))
204d02(1, *(2,))
205d02(1, **{'b':2})
206d02(**{'a': 1, 'b': 2})
207def d12(a, b=1, c=2): pass
208d12(1)
209d12(1, 2)
210d12(1, 2, 3)
211def d22(a, b, c=1, d=2): pass
212d22(1, 2)
213d22(1, 2, 3)
214d22(1, 2, 3, 4)
215def d01v(a=1, *rest): pass
216d01v()
217d01v(1)
218d01v(1, 2)
219d01v(*(1, 2, 3, 4))
220d01v(*(1,))
221d01v(**{'a':2})
222def d11v(a, b=1, *rest): pass
223d11v(1)
224d11v(1, 2)
225d11v(1, 2, 3)
226def d21v(a, b, c=1, *rest): pass
227d21v(1, 2)
228d21v(1, 2, 3)
229d21v(1, 2, 3, 4)
230d21v(*(1, 2, 3, 4))
231d21v(1, 2, **{'c': 3})
232def d02v(a=1, b=2, *rest): pass
233d02v()
234d02v(1)
235d02v(1, 2)
236d02v(1, 2, 3)
237d02v(1, *(2, 3, 4))
238d02v(**{'a': 1, 'b': 2})
239def d12v(a, b=1, c=2, *rest): pass
240d12v(1)
241d12v(1, 2)
242d12v(1, 2, 3)
243d12v(1, 2, 3, 4)
244d12v(*(1, 2, 3, 4))
245d12v(1, 2, *(3, 4, 5))
246d12v(1, *(2,), **{'c': 3})
247def d22v(a, b, c=1, d=2, *rest): pass
248d22v(1, 2)
249d22v(1, 2, 3)
250d22v(1, 2, 3, 4)
251d22v(1, 2, 3, 4, 5)
252d22v(*(1, 2, 3, 4))
253d22v(1, 2, *(3, 4, 5))
254d22v(1, *(2, 3), **{'d': 4})
255
256### lambdef: 'lambda' [varargslist] ':' test
257print 'lambdef'
258l1 = lambda : 0
259verify(l1() == 0)
260l2 = lambda : a[d] # XXX just testing the expression
261l3 = lambda : [2 < x for x in [-1, 3, 0L]]
262verify(l3() == [0, 1, 0])
263l4 = lambda x = lambda y = lambda z=1 : z : y() : x()
264verify(l4() == 1)
265l5 = lambda x, y, z=2: x + y + z
266verify(l5(1, 2) == 5)
267verify(l5(1, 2, 3) == 6)
268check_syntax("lambda x: x = 2")
269
270### stmt: simple_stmt | compound_stmt
271# Tested below
272
273### simple_stmt: small_stmt (';' small_stmt)* [';']
274print 'simple_stmt'
275x = 1; pass; del x
276
277### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt
278# Tested below
279
280print 'expr_stmt' # (exprlist '=')* exprlist
2811
2821, 2, 3
283x = 1
284x = 1, 2, 3
285x = y = z = 1, 2, 3
286x, y, z = 1, 2, 3
287abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4)
288# NB these variables are deleted below
289
290check_syntax("x + 1 = 1")
291check_syntax("a + 1 = b + 2")
292
293print 'print_stmt' # 'print' (test ',')* [test]
294print 1, 2, 3
295print 1, 2, 3,
296print
297print 0 or 1, 0 or 1,
298print 0 or 1
299
300print 'extended print_stmt' # 'print' '>>' test ','
301import sys
302print >> sys.stdout, 1, 2, 3
303print >> sys.stdout, 1, 2, 3,
304print >> sys.stdout
305print >> sys.stdout, 0 or 1, 0 or 1,
306print >> sys.stdout, 0 or 1
307
308# test printing to an instance
309class Gulp:
310 def write(self, msg): pass
311
312gulp = Gulp()
313print >> gulp, 1, 2, 3
314print >> gulp, 1, 2, 3,
315print >> gulp
316print >> gulp, 0 or 1, 0 or 1,
317print >> gulp, 0 or 1
318
319# test print >> None
320def driver():
321 oldstdout = sys.stdout
322 sys.stdout = Gulp()
323 try:
324 tellme(Gulp())
325 tellme()
326 finally:
327 sys.stdout = oldstdout
328
329# we should see this once
330def tellme(file=sys.stdout):
331 print >> file, 'hello world'
332
333driver()
334
335# we should not see this at all
336def tellme(file=None):
337 print >> file, 'goodbye universe'
338
339driver()
340
341# syntax errors
342check_syntax('print ,')
343check_syntax('print >> x,')
344
345print 'del_stmt' # 'del' exprlist
346del abc
347del x, y, (z, xyz)
348
349print 'pass_stmt' # 'pass'
350pass
351
352print 'flow_stmt' # break_stmt | continue_stmt | return_stmt | raise_stmt
353# Tested below
354
355print 'break_stmt' # 'break'
356while 1: break
357
358print 'continue_stmt' # 'continue'
359i = 1
360while i: i = 0; continue
361
362msg = ""
363while not msg:
364 msg = "continue + try/except ok"
365 try:
366 continue
367 msg = "continue failed to continue inside try"
368 except:
369 msg = "continue inside try called except block"
370print msg
371
372msg = ""
373while not msg:
374 msg = "finally block not called"
375 try:
376 continue
377 finally:
378 msg = "continue + try/finally ok"
379print msg
380
381
382# This test warrants an explanation. It is a test specifically for SF bugs
383# #463359 and #462937. The bug is that a 'break' statement executed or
384# exception raised inside a try/except inside a loop, *after* a continue
385# statement has been executed in that loop, will cause the wrong number of
386# arguments to be popped off the stack and the instruction pointer reset to
387# a very small number (usually 0.) Because of this, the following test
388# *must* written as a function, and the tracking vars *must* be function
389# arguments with default values. Otherwise, the test will loop and loop.
390
391print "testing continue and break in try/except in loop"
392def test_break_continue_loop(extra_burning_oil = 1, count=0):
393 big_hippo = 2
394 while big_hippo:
395 count += 1
396 try:
397 if extra_burning_oil and big_hippo == 1:
398 extra_burning_oil -= 1
399 break
400 big_hippo -= 1
401 continue
402 except:
403 raise
404 if count > 2 or big_hippo <> 1:
405 print "continue then break in try/except in loop broken!"
406test_break_continue_loop()
407
408print 'return_stmt' # 'return' [testlist]
409def g1(): return
410def g2(): return 1
411g1()
412x = g2()
413
414print 'raise_stmt' # 'raise' test [',' test]
415try: raise RuntimeError, 'just testing'
416except RuntimeError: pass
417try: raise KeyboardInterrupt
418except KeyboardInterrupt: pass
419
420print 'import_name' # 'import' dotted_as_names
421import sys
422import time, sys
423print 'import_from' # 'from' dotted_name 'import' ('*' | '(' import_as_names ')' | import_as_names)
424from time import time
425from time import (time)
426from sys import *
427from sys import path, argv
428from sys import (path, argv)
429from sys import (path, argv,)
430
431print 'global_stmt' # 'global' NAME (',' NAME)*
432def f():
433 global a
434 global a, b
435 global one, two, three, four, five, six, seven, eight, nine, ten
436
437print 'exec_stmt' # 'exec' expr ['in' expr [',' expr]]
438def f():
439 z = None
440 del z
441 exec 'z=1+1\n'
442 if z != 2: raise TestFailed, 'exec \'z=1+1\'\\n'
443 del z
444 exec 'z=1+1'
445 if z != 2: raise TestFailed, 'exec \'z=1+1\''
446 z = None
447 del z
448 import types
449 if hasattr(types, "UnicodeType"):
450 exec r"""if 1:
451 exec u'z=1+1\n'
452 if z != 2: raise TestFailed, 'exec u\'z=1+1\'\\n'
453 del z
454 exec u'z=1+1'
455 if z != 2: raise TestFailed, 'exec u\'z=1+1\''
456"""
457f()
458g = {}
459exec 'z = 1' in g
460if g.has_key('__builtins__'): del g['__builtins__']
461if g != {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g'
462g = {}
463l = {}
464
465import warnings
466warnings.filterwarnings("ignore", "global statement", module="<string>")
467exec 'global a; a = 1; b = 2' in g, l
468if g.has_key('__builtins__'): del g['__builtins__']
469if l.has_key('__builtins__'): del l['__builtins__']
470if (g, l) != ({'a':1}, {'b':2}): raise TestFailed, 'exec ... in g (%s), l (%s)' %(g,l)
471
472
473print "assert_stmt" # assert_stmt: 'assert' test [',' test]
474assert 1
475assert 1, 1
476assert lambda x:x
477assert 1, lambda x:x+1
478
479### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
480# Tested below
481
482print 'if_stmt' # 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
483if 1: pass
484if 1: pass
485else: pass
486if 0: pass
487elif 0: pass
488if 0: pass
489elif 0: pass
490elif 0: pass
491elif 0: pass
492else: pass
493
494print 'while_stmt' # 'while' test ':' suite ['else' ':' suite]
495while 0: pass
496while 0: pass
497else: pass
498
499print 'for_stmt' # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite]
500for i in 1, 2, 3: pass
501for i, j, k in (): pass
502else: pass
503class Squares:
504 def __init__(self, max):
505 self.max = max
506 self.sofar = []
507 def __len__(self): return len(self.sofar)
508 def __getitem__(self, i):
509 if not 0 <= i < self.max: raise IndexError
510 n = len(self.sofar)
511 while n <= i:
512 self.sofar.append(n*n)
513 n = n+1
514 return self.sofar[i]
515n = 0
516for x in Squares(10): n = n+x
517if n != 285: raise TestFailed, 'for over growing sequence'
518
519print 'try_stmt'
520### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
521### | 'try' ':' suite 'finally' ':' suite
522### except_clause: 'except' [expr [',' expr]]
523try:
524 1/0
525except ZeroDivisionError:
526 pass
527else:
528 pass
529try: 1/0
530except EOFError: pass
531except TypeError, msg: pass
532except RuntimeError, msg: pass
533except: pass
534else: pass
535try: 1/0
536except (EOFError, TypeError, ZeroDivisionError): pass
537try: 1/0
538except (EOFError, TypeError, ZeroDivisionError), msg: pass
539try: pass
540finally: pass
541
542print 'suite' # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
543if 1: pass
544if 1:
545 pass
546if 1:
547 #
548 #
549 #
550 pass
551 pass
552 #
553 pass
554 #
555
556print 'test'
557### and_test ('or' and_test)*
558### and_test: not_test ('and' not_test)*
559### not_test: 'not' not_test | comparison
560if not 1: pass
561if 1 and 1: pass
562if 1 or 1: pass
563if not not not 1: pass
564if not 1 and 1 and 1: pass
565if 1 and 1 or 1 and 1 and 1 or not 1 and 1: pass
566
567print 'comparison'
568### comparison: expr (comp_op expr)*
569### comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
570if 1: pass
571x = (1 == 1)
572if 1 == 1: pass
573if 1 != 1: pass
574if 1 <> 1: pass
575if 1 < 1: pass
576if 1 > 1: pass
577if 1 <= 1: pass
578if 1 >= 1: pass
579if 1 is 1: pass
580if 1 is not 1: pass
581if 1 in (): pass
582if 1 not in (): pass
583if 1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1: pass
584
585print 'binary mask ops'
586x = 1 & 1
587x = 1 ^ 1
588x = 1 | 1
589
590print 'shift ops'
591x = 1 << 1
592x = 1 >> 1
593x = 1 << 1 >> 1
594
595print 'additive ops'
596x = 1
597x = 1 + 1
598x = 1 - 1 - 1
599x = 1 - 1 + 1 - 1 + 1
600
601print 'multiplicative ops'
602x = 1 * 1
603x = 1 / 1
604x = 1 % 1
605x = 1 / 1 * 1 % 1
606
607print 'unary ops'
608x = +1
609x = -1
610x = ~1
611x = ~1 ^ 1 & 1 | 1 & 1 ^ -1
612x = -1*1/1 + 1*1 - ---1*1
613
614print 'selectors'
615### trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME
616### subscript: expr | [expr] ':' [expr]
617f1()
618f2(1)
619f2(1,)
620f3(1, 2)
621f3(1, 2,)
622f4(1, (2, (3, 4)))
623v0()
624v0(1)
625v0(1,)
626v0(1,2)
627v0(1,2,3,4,5,6,7,8,9,0)
628v1(1)
629v1(1,)
630v1(1,2)
631v1(1,2,3)
632v1(1,2,3,4,5,6,7,8,9,0)
633v2(1,2)
634v2(1,2,3)
635v2(1,2,3,4)
636v2(1,2,3,4,5,6,7,8,9,0)
637v3(1,(2,3))
638v3(1,(2,3),4)
639v3(1,(2,3),4,5,6,7,8,9,0)
640print
641import sys, time
642c = sys.path[0]
643x = time.time()
644x = sys.modules['time'].time()
645a = '01234'
646c = a[0]
647c = a[-1]
648s = a[0:5]
649s = a[:5]
650s = a[0:]
651s = a[:]
652s = a[-5:]
653s = a[:-1]
654s = a[-4:-3]
655
656print 'atoms'
657### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING
658### dictmaker: test ':' test (',' test ':' test)* [',']
659
660x = (1)
661x = (1 or 2 or 3)
662x = (1 or 2 or 3, 2, 3)
663
664x = []
665x = [1]
666x = [1 or 2 or 3]
667x = [1 or 2 or 3, 2, 3]
668x = []
669
670x = {}
671x = {'one': 1}
672x = {'one': 1,}
673x = {'one' or 'two': 1 or 2}
674x = {'one': 1, 'two': 2}
675x = {'one': 1, 'two': 2,}
676x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6}
677
678x = `x`
679x = `1 or 2 or 3`
680x = x
681x = 'x'
682x = 123
683
684### exprlist: expr (',' expr)* [',']
685### testlist: test (',' test)* [',']
686# These have been exercised enough above
687
688print 'classdef' # 'class' NAME ['(' testlist ')'] ':' suite
689class B: pass
690class C1(B): pass
691class C2(B): pass
692class D(C1, C2, B): pass
693class C:
694 def meth1(self): pass
695 def meth2(self, arg): pass
696 def meth3(self, a1, a2): pass
697
698# list comprehension tests
699nums = [1, 2, 3, 4, 5]
700strs = ["Apple", "Banana", "Coconut"]
701spcs = [" Apple", " Banana ", "Coco nut "]
702
703print [s.strip() for s in spcs]
704print [3 * x for x in nums]
705print [x for x in nums if x > 2]
706print [(i, s) for i in nums for s in strs]
707print [(i, s) for i in nums for s in [f for f in strs if "n" in f]]
708print [(lambda a:[a**i for i in range(a+1)])(j) for j in range(5)]
709
710def test_in_func(l):
711 return [None < x < 3 for x in l if x > 2]
712
713print test_in_func(nums)
714
715def test_nested_front():
716 print [[y for y in [x, x + 1]] for x in [1,3,5]]
717
718test_nested_front()
719
720check_syntax("[i, s for i in nums for s in strs]")
721check_syntax("[x if y]")
722
723suppliers = [
724 (1, "Boeing"),
725 (2, "Ford"),
726 (3, "Macdonalds")
727]
728
729parts = [
730 (10, "Airliner"),
731 (20, "Engine"),
732 (30, "Cheeseburger")
733]
734
735suppart = [
736 (1, 10), (1, 20), (2, 20), (3, 30)
737]
738
739print [
740 (sname, pname)
741 for (sno, sname) in suppliers
742 for (pno, pname) in parts
743 for (sp_sno, sp_pno) in suppart
744 if sno == sp_sno and pno == sp_pno
745]
746
747# generator expression tests
748g = ([x for x in range(10)] for x in range(1))
749verify(g.next() == [x for x in range(10)])
750try:
751 g.next()
752 raise TestFailed, 'should produce StopIteration exception'
753except StopIteration:
754 pass
755
756a = 1
757try:
758 g = (a for d in a)
759 g.next()
760 raise TestFailed, 'should produce TypeError'
761except TypeError:
762 pass
763
764verify(list((x, y) for x in 'abcd' for y in 'abcd') == [(x, y) for x in 'abcd' for y in 'abcd'])
765verify(list((x, y) for x in 'ab' for y in 'xy') == [(x, y) for x in 'ab' for y in 'xy'])
766
767a = [x for x in range(10)]
768b = (x for x in (y for y in a))
769verify(sum(b) == sum([x for x in range(10)]))
770
771verify(sum(x**2 for x in range(10)) == sum([x**2 for x in range(10)]))
772verify(sum(x*x for x in range(10) if x%2) == sum([x*x for x in range(10) if x%2]))
773verify(sum(x for x in (y for y in range(10))) == sum([x for x in range(10)]))
774verify(sum(x for x in (y for y in (z for z in range(10)))) == sum([x for x in range(10)]))
775verify(sum(x for x in [y for y in (z for z in range(10))]) == sum([x for x in range(10)]))
776verify(sum(x for x in (y for y in (z for z in range(10) if True)) if True) == sum([x for x in range(10)]))
777verify(sum(x for x in (y for y in (z for z in range(10) if True) if False) if True) == 0)
778check_syntax("foo(x for x in range(10), 100)")
779check_syntax("foo(100, x for x in range(10))")
780
781# test for outmost iterable precomputation
782x = 10; g = (i for i in range(x)); x = 5
783verify(len(list(g)) == 10)
784
785# This should hold, since we're only precomputing outmost iterable.
786x = 10; t = False; g = ((i,j) for i in range(x) if t for j in range(x))
787x = 5; t = True;
788verify([(i,j) for i in range(10) for j in range(5)] == list(g))