##// END OF EJS Templates
`yield`, `break`, and `continue` automatically dedent...
Aaron Meurer -
Show More
@@ -115,7 +115,11 b" dedent_re = re.compile('|'.join(["
115 115 r'^\s+raise\([^\)]*\).*$', # wacky raise with immediate open paren
116 116 r'^\s+return(\s.*)?$', # normal return (+ space + other stuff, maybe)
117 117 r'^\s+return\([^\)]*\).*$', # wacky return with immediate open paren
118 r'^\s+pass\s*$' # pass (optionally followed by trailing spaces)
118 r'^\s+yield(\s.*)?$', # normal yield (+ space + other stuff, maybe)
119 r'^\s+yield\([^\)]*\).*$', # wacky yield with immediate open paren
120 r'^\s+pass\s*$', # pass (optionally followed by trailing spaces)
121 r'^\s+break\s*$', # break (optionally followed by trailing spaces)
122 r'^\s+continue\s*$', # continue (optionally followed by trailing spaces)
119 123 ]))
120 124 ini_spaces_re = re.compile(r'^([ \t\r\f\v]+)')
121 125
@@ -227,6 +227,26 b' class InputSplitterTestCase(unittest.TestCase):'
227 227 isp.push('if 1:\n pass ')
228 228 self.assertEqual(isp.indent_spaces, 0)
229 229
230 def test_dedent_break(self):
231 isp = self.isp # shorthand
232 # should NOT cause dedent
233 isp.push('while 1:\n breaks = 5')
234 self.assertEqual(isp.indent_spaces, 4)
235 isp.push('while 1:\n break')
236 self.assertEqual(isp.indent_spaces, 0)
237 isp.push('while 1:\n break ')
238 self.assertEqual(isp.indent_spaces, 0)
239
240 def test_dedent_continue(self):
241 isp = self.isp # shorthand
242 # should NOT cause dedent
243 isp.push('while 1:\n continues = 5')
244 self.assertEqual(isp.indent_spaces, 4)
245 isp.push('while 1:\n continue')
246 self.assertEqual(isp.indent_spaces, 0)
247 isp.push('while 1:\n continue ')
248 self.assertEqual(isp.indent_spaces, 0)
249
230 250 def test_dedent_raise(self):
231 251 isp = self.isp # shorthand
232 252 # should NOT cause dedent
@@ -253,6 +273,20 b' class InputSplitterTestCase(unittest.TestCase):'
253 273 isp.push('if 1:\n return(0)')
254 274 self.assertEqual(isp.indent_spaces, 0)
255 275
276 def test_dedent_yield(self):
277 isp = self.isp # shorthand
278 # should NOT cause dedent
279 isp.push('if 1:\n yielding = 4')
280 self.assertEqual(isp.indent_spaces, 4)
281 isp.push('if 1:\n yield 5 + 493')
282 self.assertEqual(isp.indent_spaces, 0)
283 isp.push('if 1:\n yield')
284 self.assertEqual(isp.indent_spaces, 0)
285 isp.push('if 1:\n yield ')
286 self.assertEqual(isp.indent_spaces, 0)
287 isp.push('if 1:\n yield(0)')
288 self.assertEqual(isp.indent_spaces, 0)
289
256 290 def test_push(self):
257 291 isp = self.isp
258 292 self.assertTrue(isp.push('x=1'))
General Comments 0
You need to be logged in to leave comments. Login now