Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
cf580c7e
Kaydet (Commit)
cf580c7e
authored
Tem 17, 2001
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added tests for the new yield support in the parser module.
(Should be merged with descr branch.)
üst
02126f20
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
1 deletion
+132
-1
test_parser.py
Lib/test/test_parser.py
+132
-1
No files found.
Lib/test/test_parser.py
Dosyayı görüntüle @
cf580c7e
...
...
@@ -26,6 +26,18 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
def
check_suite
(
self
,
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
):
self
.
check_expr
(
"foo(1)"
)
self
.
check_expr
(
"[1, 2, 3]"
)
...
...
@@ -138,8 +150,127 @@ class IllegalSyntaxTestCase(unittest.TestCase):
# not even remotely valid:
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
):
"Illegal input: print >>fp,"""
"
""
Illegal input: print >>fp,"""
tree
=
\
(
257
,
(
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