diff options
author | Fred Drake <fdrake@acm.org> | 2001-07-17 03:01:29 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-07-17 03:01:29 (GMT) |
commit | cf580c7ea136fa8f73bae446a99c96b74251b2a8 (patch) | |
tree | 18c7f175835595c43d30def9dd036ddd616b7c83 /Lib | |
parent | 02126f20b627a4189f34c9758284ab367e9b7711 (diff) | |
download | cpython-cf580c7ea136fa8f73bae446a99c96b74251b2a8.zip cpython-cf580c7ea136fa8f73bae446a99c96b74251b2a8.tar.gz cpython-cf580c7ea136fa8f73bae446a99c96b74251b2a8.tar.bz2 |
Added tests for the new yield support in the parser module.
(Should be merged with descr branch.)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_parser.py | 133 |
1 files changed, 132 insertions, 1 deletions
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 5b867d7..8955bf8 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -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, |