Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_grammar.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 3a07799deba1 |
| children | 7e006342e790 |
| rev | line source |
|---|---|
| 653 | 1 # Python test set -- part 1, grammar. |
| 2 # This just tests whether the parser accepts them all. | |
| 3 | |
| 4 from test_support import * | |
| 5 | |
| 6 print '1. Parser' | |
| 7 | |
| 8 print '1.1 Tokens' | |
| 9 | |
| 10 print '1.1.1 Backslashes' | |
| 11 | |
| 12 # Backslash means line continuation: | |
| 13 x = 1 \ | |
| 14 + 1 | |
| 15 if x <> 2: raise TestFailed, 'backslash for line continuation' | |
| 16 | |
| 17 # Backslash does not means continuation in comments :\ | |
| 18 x = 0 | |
| 19 if x <> 0: raise TestFailed, 'backslash ending comment' | |
| 20 | |
| 21 print '1.1.2 Numeric literals' | |
| 22 | |
| 23 print '1.1.2.1 Plain integers' | |
| 24 if 0xff <> 255: raise TestFailed, 'hex int' | |
| 25 if 0377 <> 255: raise TestFailed, 'octal int' | |
| 1463 | 26 if 2147483647 != 017777777777: raise TestFailed, 'large positive int' |
| 27 try: | |
| 28 from sys import maxint | |
| 29 except ImportError: | |
| 30 maxint = 2147483647 | |
| 31 if maxint == 2147483647: | |
|
1403
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
32 if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int' |
|
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
33 # XXX -2147483648 |
|
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
34 if 037777777777 != -1: raise TestFailed, 'oct -1' |
|
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
35 if 0xffffffff != -1: raise TestFailed, 'hex -1' |
|
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
36 for s in '2147483648', '040000000000', '0x100000000': |
|
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
37 try: |
|
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
38 x = eval(s) |
|
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
39 except OverflowError: |
|
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
40 continue |
|
2477
11b937ea0026
avoid math, don't abort when overflow check fails
Guido van Rossum <guido@python.org>
parents:
2102
diff
changeset
|
41 ## raise TestFailed, \ |
|
11b937ea0026
avoid math, don't abort when overflow check fails
Guido van Rossum <guido@python.org>
parents:
2102
diff
changeset
|
42 print \ |
|
1403
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1359
diff
changeset
|
43 'No OverflowError on huge integer literal ' + `s` |
| 1463 | 44 elif eval('maxint == 9223372036854775807'): |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
45 if eval('-9223372036854775807-1 != 01000000000000000000000'): |
| 1463 | 46 raise TestFailed, 'max negative int' |
| 47 if eval('01777777777777777777777') != -1: raise TestFailed, 'oct -1' | |
| 48 if eval('0xffffffffffffffff') != -1: raise TestFailed, 'hex -1' | |
| 49 for s in '9223372036854775808', '02000000000000000000000', \ | |
| 50 '0x10000000000000000': | |
| 51 try: | |
| 52 x = eval(s) | |
| 53 except OverflowError: | |
| 54 continue | |
| 55 raise TestFailed, \ | |
| 56 'No OverflowError on huge integer literal ' + `s` | |
| 57 else: | |
| 58 print 'Weird maxint value', maxint | |
| 653 | 59 |
| 60 print '1.1.2.2 Long integers' | |
| 61 x = 0L | |
| 62 x = 0l | |
| 63 x = 0xffffffffffffffffL | |
| 64 x = 0xffffffffffffffffl | |
| 65 x = 077777777777777777L | |
| 66 x = 077777777777777777l | |
| 67 x = 123456789012345678901234567890L | |
| 68 x = 123456789012345678901234567890l | |
| 69 | |
| 70 print '1.1.2.3 Floating point' | |
| 71 x = 3.14 | |
| 72 x = 314. | |
| 73 x = 0.314 | |
| 74 # XXX x = 000.314 | |
| 75 x = .314 | |
| 76 x = 3e14 | |
| 77 x = 3E14 | |
| 78 x = 3e-14 | |
| 79 x = 3e+14 | |
| 80 x = 3.e14 | |
| 81 x = .3e14 | |
| 82 x = 3.1e4 | |
| 83 | |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
84 print '1.1.3 String literals' |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
85 |
|
5325
3a07799deba1
No need to define assert, it's built in.
Guido van Rossum <guido@python.org>
parents:
2477
diff
changeset
|
86 ##def assert(s): |
|
3a07799deba1
No need to define assert, it's built in.
Guido van Rossum <guido@python.org>
parents:
2477
diff
changeset
|
87 ## if not s: raise TestFailed, 'see traceback' |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
88 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
89 x = ''; y = ""; assert(len(x) == 0 and x == y) |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
90 x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39) |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
91 x = '"'; y = "\""; assert(len(x) == 1 and x == y and ord(x) == 34) |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
92 x = "doesn't \"shrink\" does it" |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
93 y = 'doesn\'t "shrink" does it' |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
94 assert(len(x) == 24 and x == y) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
95 x = "does \"shrink\" doesn't it" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
96 y = 'does "shrink" doesn\'t it' |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
97 assert(len(x) == 24 and x == y) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
98 x = """ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
99 The "quick" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
100 brown fox |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
101 jumps over |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
102 the 'lazy' dog. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
103 """ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
104 y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n' |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
105 assert(x == y) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
106 y = ''' |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
107 The "quick" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
108 brown fox |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
109 jumps over |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
110 the 'lazy' dog. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
111 '''; assert(x == y) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
112 y = "\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
113 The \"quick\"\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
114 brown fox\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
115 jumps over\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
116 the 'lazy' dog.\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
117 "; assert(x == y) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
118 y = '\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
119 The \"quick\"\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
120 brown fox\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
121 jumps over\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
122 the \'lazy\' dog.\n\ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
123 '; assert(x == y) |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
124 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
125 |
| 653 | 126 print '1.2 Grammar' |
| 127 | |
| 128 print 'single_input' # NEWLINE | simple_stmt | compound_stmt NEWLINE | |
| 129 # XXX can't test in a script -- this rule is only used when interactive | |
| 130 | |
| 131 print 'file_input' # (NEWLINE | stmt)* ENDMARKER | |
| 132 # Being tested as this very moment this very module | |
| 133 | |
| 134 print 'expr_input' # testlist NEWLINE | |
| 135 # XXX Hard to test -- used only in calls to input() | |
| 136 | |
| 137 print 'eval_input' # testlist ENDMARKER | |
| 138 x = eval('1, 0 or 1') | |
| 139 | |
| 140 print 'funcdef' | |
| 141 ### 'def' NAME parameters ':' suite | |
| 142 ### parameters: '(' [varargslist] ')' | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
143 ### varargslist: (fpdef ['=' test] ',')* '*' NAME |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
144 ### | fpdef ['=' test] (',' fpdef ['=' test])* [','] |
| 653 | 145 ### fpdef: NAME | '(' fplist ')' |
| 146 ### fplist: fpdef (',' fpdef)* [','] | |
| 147 def f1(): pass | |
| 148 def f2(one_argument): pass | |
| 149 def f3(two, arguments): pass | |
| 150 def f4(two, (compound, (argument, list))): pass | |
| 151 def a1(one_arg,): pass | |
| 152 def a2(two, args,): pass | |
| 153 def v0(*rest): pass | |
| 154 def v1(a, *rest): pass | |
| 155 def v2(a, b, *rest): pass | |
| 156 def v3(a, (b, c), *rest): pass | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
157 def d01(a=1): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
158 d01() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
159 d01(1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
160 def d11(a, b=1): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
161 d11(1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
162 d11(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
163 def d21(a, b, c=1): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
164 d21(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
165 d21(1, 2, 3) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
166 def d02(a=1, b=2): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
167 d02() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
168 d02(1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
169 d02(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
170 def d12(a, b=1, c=2): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
171 d12(1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
172 d12(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
173 d12(1, 2, 3) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
174 def d22(a, b, c=1, d=2): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
175 d22(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
176 d22(1, 2, 3) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
177 d22(1, 2, 3, 4) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
178 def d01v(a=1, *rest): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
179 d01v() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
180 d01v(1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
181 d01v(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
182 def d11v(a, b=1, *rest): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
183 d11v(1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
184 d11v(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
185 d11v(1, 2, 3) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
186 def d21v(a, b, c=1, *rest): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
187 d21v(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
188 d21v(1, 2, 3) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
189 d21v(1, 2, 3, 4) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
190 def d02v(a=1, b=2, *rest): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
191 d02v() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
192 d02v(1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
193 d02v(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
194 d02v(1, 2, 3) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
195 def d12v(a, b=1, c=2, *rest): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
196 d12v(1) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
197 d12v(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
198 d12v(1, 2, 3) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
199 d12v(1, 2, 3, 4) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
200 def d22v(a, b, c=1, d=2, *rest): pass |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
201 d22v(1, 2) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
202 d22v(1, 2, 3) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
203 d22v(1, 2, 3, 4) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
204 d22v(1, 2, 3, 4, 5) |
| 653 | 205 |
| 206 ### stmt: simple_stmt | compound_stmt | |
| 207 # Tested below | |
| 208 | |
| 209 ### simple_stmt: small_stmt (';' small_stmt)* [';'] | |
| 210 print 'simple_stmt' | |
| 211 x = 1; pass; del x | |
| 212 | |
|
1359
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
213 ### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt |
| 653 | 214 # Tested below |
| 215 | |
| 216 print 'expr_stmt' # (exprlist '=')* exprlist | |
| 217 1 | |
| 218 1, 2, 3 | |
| 219 x = 1 | |
| 220 x = 1, 2, 3 | |
| 221 x = y = z = 1, 2, 3 | |
| 222 x, y, z = 1, 2, 3 | |
| 223 abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4) | |
| 224 # NB these variables are deleted below | |
| 225 | |
| 226 print 'print_stmt' # 'print' (test ',')* [test] | |
| 227 print 1, 2, 3 | |
| 228 print 1, 2, 3, | |
| 229 print | |
| 230 print 0 or 1, 0 or 1, | |
| 231 print 0 or 1 | |
| 232 | |
| 233 print 'del_stmt' # 'del' exprlist | |
| 234 del abc | |
| 235 del x, y, (z, xyz) | |
| 236 | |
| 237 print 'pass_stmt' # 'pass' | |
| 238 pass | |
| 239 | |
| 240 print 'flow_stmt' # break_stmt | continue_stmt | return_stmt | raise_stmt | |
| 241 # Tested below | |
| 242 | |
| 243 print 'break_stmt' # 'break' | |
| 244 while 1: break | |
| 245 | |
| 246 print 'continue_stmt' # 'continue' | |
| 247 i = 1 | |
| 248 while i: i = 0; continue | |
| 249 | |
| 250 print 'return_stmt' # 'return' [testlist] | |
| 251 def g1(): return | |
| 252 def g2(): return 1 | |
| 253 g1() | |
| 254 x = g2() | |
| 255 | |
| 256 print 'raise_stmt' # 'raise' test [',' test] | |
| 257 try: raise RuntimeError, 'just testing' | |
| 258 except RuntimeError: pass | |
| 259 try: raise KeyboardInterrupt | |
| 260 except KeyboardInterrupt: pass | |
| 261 | |
| 262 print 'import_stmt' # 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*) | |
| 263 import sys | |
|
2477
11b937ea0026
avoid math, don't abort when overflow check fails
Guido van Rossum <guido@python.org>
parents:
2102
diff
changeset
|
264 import time, sys |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
265 from time import time |
| 653 | 266 from sys import * |
|
2477
11b937ea0026
avoid math, don't abort when overflow check fails
Guido van Rossum <guido@python.org>
parents:
2102
diff
changeset
|
267 from sys import path, argv |
| 653 | 268 |
| 269 print 'global_stmt' # 'global' NAME (',' NAME)* | |
| 270 def f(): | |
| 271 global a | |
| 272 global a, b | |
| 273 global one, two, three, four, five, six, seven, eight, nine, ten | |
| 274 | |
|
1359
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
275 print 'exec_stmt' # 'exec' expr ['in' expr [',' expr]] |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
276 def f(): |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
277 z = None |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
278 del z |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
279 exec 'z=1+1\n' |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
280 if z <> 2: raise TestFailed, 'exec \'z=1+1\'\\n' |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
281 del z |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
282 exec 'z=1+1' |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
283 if z <> 2: raise TestFailed, 'exec \'z=1+1\'' |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
284 f() |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
285 g = {} |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
286 exec 'z = 1' in g |
|
2102
30821bc2dcb7
Fix exec test so presence of __builtins__ doesn't break it
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
287 if g.has_key('__builtins__'): del g['__builtins__'] |
|
1359
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
288 if g <> {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g' |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
289 g = {} |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
290 l = {} |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
291 exec 'global a; a = 1; b = 2' in g, l |
|
2102
30821bc2dcb7
Fix exec test so presence of __builtins__ doesn't break it
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
292 if g.has_key('__builtins__'): del g['__builtins__'] |
|
30821bc2dcb7
Fix exec test so presence of __builtins__ doesn't break it
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
293 if l.has_key('__builtins__'): del l['__builtins__'] |
|
1359
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
294 if (g, l) <> ({'a':1}, {'b':2}): raise TestFailed, 'exec ... in g, l' |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
295 |
|
5d74a9873589
added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents:
1097
diff
changeset
|
296 |
| 653 | 297 ### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef |
| 298 # Tested below | |
| 299 | |
| 300 print 'if_stmt' # 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] | |
| 301 if 1: pass | |
| 302 if 1: pass | |
| 303 else: pass | |
| 304 if 0: pass | |
| 305 elif 0: pass | |
| 306 if 0: pass | |
| 307 elif 0: pass | |
| 308 elif 0: pass | |
| 309 elif 0: pass | |
| 310 else: pass | |
| 311 | |
| 312 print 'while_stmt' # 'while' test ':' suite ['else' ':' suite] | |
| 313 while 0: pass | |
| 314 while 0: pass | |
| 315 else: pass | |
| 316 | |
| 317 print 'for_stmt' # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] | |
| 318 for i in 1, 2, 3: pass | |
| 319 for i, j, k in (): pass | |
| 320 else: pass | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
321 class Squares: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
322 def __init__(self, max): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
323 self.max = max |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
324 self.sofar = [] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
325 def __len__(self): return len(self.sofar) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
326 def __getitem__(self, i): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
327 if not 0 <= i < self.max: raise IndexError |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
328 n = len(self.sofar) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
329 while n <= i: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
330 self.sofar.append(n*n) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
331 n = n+1 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
332 return self.sofar[i] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
333 n = 0 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
334 for x in Squares(10): n = n+x |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
335 if n != 285: raise TestFailed, 'for over growing sequence' |
| 653 | 336 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
337 print 'try_stmt' |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
338 ### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
339 ### | 'try' ':' suite 'finally' ':' suite |
| 653 | 340 ### except_clause: 'except' [expr [',' expr]] |
|
1097
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
341 try: |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
342 1/0 |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
343 except ZeroDivisionError: |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
344 pass |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
345 else: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
346 pass |
| 653 | 347 try: 1/0 |
| 348 except EOFError: pass | |
| 349 except TypeError, msg: pass | |
| 350 except RuntimeError, msg: pass | |
| 351 except: pass | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1463
diff
changeset
|
352 else: pass |
|
1097
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
353 try: 1/0 |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
354 except (EOFError, TypeError, ZeroDivisionError): pass |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
355 try: 1/0 |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
356 except (EOFError, TypeError, ZeroDivisionError), msg: pass |
| 653 | 357 try: pass |
| 358 finally: pass | |
| 359 | |
| 360 print 'suite' # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT | |
| 361 if 1: pass | |
| 362 if 1: | |
| 363 pass | |
| 364 if 1: | |
| 365 # | |
| 366 # | |
| 367 # | |
| 368 pass | |
| 369 pass | |
| 370 # | |
| 371 pass | |
| 372 # | |
| 373 | |
| 374 print 'test' | |
| 375 ### and_test ('or' and_test)* | |
| 376 ### and_test: not_test ('and' not_test)* | |
| 377 ### not_test: 'not' not_test | comparison | |
| 378 if not 1: pass | |
| 379 if 1 and 1: pass | |
| 380 if 1 or 1: pass | |
| 381 if not not not 1: pass | |
| 382 if not 1 and 1 and 1: pass | |
| 383 if 1 and 1 or 1 and 1 and 1 or not 1 and 1: pass | |
| 384 | |
| 385 print 'comparison' | |
| 386 ### comparison: expr (comp_op expr)* | |
| 387 ### comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' | |
| 388 if 1: pass | |
| 389 x = (1 == 1) | |
| 390 if 1 == 1: pass | |
| 391 if 1 != 1: pass | |
| 392 if 1 <> 1: pass | |
| 393 if 1 < 1: pass | |
| 394 if 1 > 1: pass | |
| 395 if 1 <= 1: pass | |
| 396 if 1 >= 1: pass | |
| 397 if 1 is 1: pass | |
| 398 if 1 is not 1: pass | |
| 399 if 1 in (): pass | |
| 400 if 1 not in (): pass | |
|
1097
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
401 if 1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1: pass |
| 653 | 402 |
| 403 print 'binary mask ops' | |
| 404 x = 1 & 1 | |
| 405 x = 1 ^ 1 | |
| 406 x = 1 | 1 | |
| 407 | |
| 408 print 'shift ops' | |
| 409 x = 1 << 1 | |
| 410 x = 1 >> 1 | |
| 411 x = 1 << 1 >> 1 | |
| 412 | |
| 413 print 'additive ops' | |
| 414 x = 1 | |
| 415 x = 1 + 1 | |
| 416 x = 1 - 1 - 1 | |
| 417 x = 1 - 1 + 1 - 1 + 1 | |
| 418 | |
| 419 print 'multiplicative ops' | |
| 420 x = 1 * 1 | |
| 421 x = 1 / 1 | |
| 422 x = 1 % 1 | |
| 423 x = 1 / 1 * 1 % 1 | |
| 424 | |
| 425 print 'unary ops' | |
| 426 x = +1 | |
| 427 x = -1 | |
| 428 x = ~1 | |
| 429 x = ~1 ^ 1 & 1 | 1 & 1 ^ -1 | |
| 430 x = -1*1/1 + 1*1 - ---1*1 | |
| 431 | |
| 432 print 'selectors' | |
| 433 ### trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME | |
| 434 ### subscript: expr | [expr] ':' [expr] | |
|
1097
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
435 f1() |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
436 f2(1) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
437 f2(1,) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
438 f3(1, 2) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
439 f3(1, 2,) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
440 f4(1, (2, (3, 4))) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
441 v0() |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
442 v0(1) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
443 v0(1,) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
444 v0(1,2) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
445 v0(1,2,3,4,5,6,7,8,9,0) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
446 v1(1) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
447 v1(1,) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
448 v1(1,2) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
449 v1(1,2,3) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
450 v1(1,2,3,4,5,6,7,8,9,0) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
451 v2(1,2) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
452 v2(1,2,3) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
453 v2(1,2,3,4) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
454 v2(1,2,3,4,5,6,7,8,9,0) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
455 v3(1,(2,3)) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
456 v3(1,(2,3),4) |
|
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
457 v3(1,(2,3),4,5,6,7,8,9,0) |
| 653 | 458 import sys, time |
| 459 c = sys.path[0] | |
| 460 x = time.time() | |
| 461 x = sys.modules['time'].time() | |
| 462 a = '01234' | |
| 463 c = a[0] | |
| 464 c = a[-1] | |
| 465 s = a[0:5] | |
| 466 s = a[:5] | |
| 467 s = a[0:] | |
| 468 s = a[:] | |
| 469 s = a[-5:] | |
| 470 s = a[:-1] | |
| 471 s = a[-4:-3] | |
| 472 | |
| 473 print 'atoms' | |
| 474 ### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING | |
| 475 ### dictmaker: test ':' test (',' test ':' test)* [','] | |
| 476 | |
| 477 x = (1) | |
| 478 x = (1 or 2 or 3) | |
| 479 x = (1 or 2 or 3, 2, 3) | |
| 480 | |
| 481 x = [] | |
| 482 x = [1] | |
| 483 x = [1 or 2 or 3] | |
| 484 x = [1 or 2 or 3, 2, 3] | |
| 485 x = [] | |
| 486 | |
| 487 x = {} | |
| 488 x = {'one': 1} | |
| 489 x = {'one': 1,} | |
| 490 x = {'one' or 'two': 1 or 2} | |
| 491 x = {'one': 1, 'two': 2} | |
| 492 x = {'one': 1, 'two': 2,} | |
| 493 x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6} | |
| 494 | |
| 495 x = `x` | |
| 496 x = `1 or 2 or 3` | |
| 497 x = x | |
| 498 x = 'x' | |
| 499 x = 123 | |
| 500 | |
| 501 ### exprlist: expr (',' expr)* [','] | |
| 502 ### testlist: test (',' test)* [','] | |
| 503 # These have been exercised enough above | |
| 504 | |
|
1097
c644bc626098
Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
787
diff
changeset
|
505 print 'classdef' # 'class' NAME ['(' testlist ')'] ':' suite |
| 653 | 506 class B: pass |
| 507 class C1(B): pass | |
| 508 class C2(B): pass | |
| 509 class D(C1, C2, B): pass | |
| 510 class C: | |
| 511 def meth1(self): pass | |
| 512 def meth2(self, arg): pass | |
| 513 def meth3(self, a1, a2): pass |
