[Python-checkins] CVS: python/dist/src/Lib/test test_parser.py,1.7,1.8

Fred L. Drake fdrake@users.sourceforge.net
2001年7月16日 20:01:31 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv1770/Lib/test
Modified Files:
	test_parser.py 
Log Message:
Added tests for the new yield support in the parser module.
(Should be merged with descr branch.)
Index: test_parser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_parser.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** test_parser.py	2001年06月04日 03:56:24	1.7
--- test_parser.py	2001年07月17日 03:01:29	1.8
***************
*** 27,30 ****
--- 27,42 ----
 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)")
***************
*** 139,144 ****
 self.check_bad_tree((1, 2, 3), "<junk>")
 
 def test_print_chevron_comma(self):
! "Illegal input: print >>fp,"""
 tree = \
 (257,
--- 151,275 ----
 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,"""
 tree = \
 (257,

AltStyle によって変換されたページ (->オリジナル) /