Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cf580c7e
Commit
cf580c7e
authored
Jul 17, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for the new yield support in the parser module.
(Should be merged with descr branch.)
parent
02126f20
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
1 deletion
+132
-1
Lib/test/test_parser.py
Lib/test/test_parser.py
+132
-1
No files found.
Lib/test/test_parser.py
View file @
cf580c7e
...
@@ -26,6 +26,18 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
...
@@ -26,6 +26,18 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
def
check_suite
(
self
,
s
):
def
check_suite
(
self
,
s
):
self
.
roundtrip
(
parser
.
suite
,
s
)
self
.
roundtrip
(
parser
.
suite
,
s
)
def
test_yield_statement
(
self
):
self
.
check_suite
(
"from __future__ import generators
\
n
"
"def f(): yield 1"
)
self
.
check_suite
(
"from __future__ import generators
\
n
"
"def f(): return; yield 1"
)
self
.
check_suite
(
"from __future__ import generators
\
n
"
"def f(): yield 1; return"
)
self
.
check_suite
(
"from __future__ import generators
\
n
"
"def f():
\
n
"
" for x in range(30):
\
n
"
" yield x
\
n
"
)
def
test_expressions
(
self
):
def
test_expressions
(
self
):
self
.
check_expr
(
"foo(1)"
)
self
.
check_expr
(
"foo(1)"
)
self
.
check_expr
(
"[1, 2, 3]"
)
self
.
check_expr
(
"[1, 2, 3]"
)
...
@@ -138,8 +150,127 @@ class IllegalSyntaxTestCase(unittest.TestCase):
...
@@ -138,8 +150,127 @@ class IllegalSyntaxTestCase(unittest.TestCase):
# not even remotely valid:
# not even remotely valid:
self
.
check_bad_tree
((
1
,
2
,
3
),
"<junk>"
)
self
.
check_bad_tree
((
1
,
2
,
3
),
"<junk>"
)
def
test_illegal_yield_1
(
self
):
"""Illegal yield statement: def f(): return 1; yield 1"""
tree
=
\
(
257
,
(
264
,
(
285
,
(
259
,
(
1
,
'def'
),
(
1
,
'f'
),
(
260
,
(
7
,
'('
),
(
8
,
')'
)),
(
11
,
':'
),
(
291
,
(
4
,
''
),
(
5
,
''
),
(
264
,
(
265
,
(
266
,
(
272
,
(
275
,
(
1
,
'return'
),
(
313
,
(
292
,
(
293
,
(
294
,
(
295
,
(
297
,
(
298
,
(
299
,
(
300
,
(
301
,
(
302
,
(
303
,
(
304
,
(
305
,
(
2
,
'1'
)))))))))))))))))),
(
264
,
(
265
,
(
266
,
(
272
,
(
276
,
(
1
,
'yield'
),
(
313
,
(
292
,
(
293
,
(
294
,
(
295
,
(
297
,
(
298
,
(
299
,
(
300
,
(
301
,
(
302
,
(
303
,
(
304
,
(
305
,
(
2
,
'1'
)))))))))))))))))),
(
4
,
''
))),
(
6
,
''
))))),
(
4
,
''
),
(
0
,
''
))))
self
.
check_bad_tree
(
tree
,
"def f():
\
n
return 1
\
n
yield 1"
)
def
test_illegal_yield_2
(
self
):
"""Illegal return in generator: def f(): return 1; yield 1"""
tree
=
\
(
257
,
(
264
,
(
265
,
(
266
,
(
278
,
(
1
,
'from'
),
(
281
,
(
1
,
'__future__'
)),
(
1
,
'import'
),
(
279
,
(
1
,
'generators'
)))),
(
4
,
''
))),
(
264
,
(
285
,
(
259
,
(
1
,
'def'
),
(
1
,
'f'
),
(
260
,
(
7
,
'('
),
(
8
,
')'
)),
(
11
,
':'
),
(
291
,
(
4
,
''
),
(
5
,
''
),
(
264
,
(
265
,
(
266
,
(
272
,
(
275
,
(
1
,
'return'
),
(
313
,
(
292
,
(
293
,
(
294
,
(
295
,
(
297
,
(
298
,
(
299
,
(
300
,
(
301
,
(
302
,
(
303
,
(
304
,
(
305
,
(
2
,
'1'
)))))))))))))))))),
(
264
,
(
265
,
(
266
,
(
272
,
(
276
,
(
1
,
'yield'
),
(
313
,
(
292
,
(
293
,
(
294
,
(
295
,
(
297
,
(
298
,
(
299
,
(
300
,
(
301
,
(
302
,
(
303
,
(
304
,
(
305
,
(
2
,
'1'
)))))))))))))))))),
(
4
,
''
))),
(
6
,
''
))))),
(
4
,
''
),
(
0
,
''
))))
self
.
check_bad_tree
(
tree
,
"def f():
\
n
return 1
\
n
yield 1"
)
def
test_print_chevron_comma
(
self
):
def
test_print_chevron_comma
(
self
):
"Illegal input: print >>fp,"""
"
""
Illegal input: print >>fp,"""
tree
=
\
tree
=
\
(
257
,
(
257
,
(
264
,
(
264
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment