Show More
@@ -103,7 +103,13 b" ESC_PAREN = '/' # Call first argument with rest of line as arguments" | |||
|
103 | 103 | # while developing. |
|
104 | 104 | |
|
105 | 105 | # compiled regexps for autoindent management |
|
106 | dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass') | |
|
106 | dedent_re = re.compile('|'.join([ | |
|
107 | r'^\s+raise(\s.*)?$', # raise statement (+ space + other stuff, maybe) | |
|
108 | r'^\s+raise\([^\)]*\).*$', # wacky raise with immediate open paren | |
|
109 | r'^\s+return(\s.*)?$', # normal return (+ space + other stuff, maybe) | |
|
110 | r'^\s+return\([^\)]*\).*$', # wacky return with immediate open paren | |
|
111 | r'^\s+pass\s*$' # pass (optionally followed by trailing spaces) | |
|
112 | ])) | |
|
107 | 113 | ini_spaces_re = re.compile(r'^([ \t\r\f\v]+)') |
|
108 | 114 | |
|
109 | 115 | # regexp to match pure comment lines so we don't accidentally insert 'if 1:' |
@@ -192,13 +192,42 b' class InputSplitterTestCase(unittest.TestCase):' | |||
|
192 | 192 | isp.push(" x = (1+\n 2)") |
|
193 | 193 | self.assertEqual(isp.indent_spaces, 4) |
|
194 | 194 | |
|
195 | def test_dedent(self): | |
|
195 | def test_dedent_pass(self): | |
|
196 | 196 | isp = self.isp # shorthand |
|
197 | isp.push('if 1:') | |
|
197 | # should NOT cause dedent | |
|
198 | isp.push('if 1:\n passes = 5') | |
|
198 | 199 | self.assertEqual(isp.indent_spaces, 4) |
|
199 | isp.push(' pass') | |
|
200 | isp.push('if 1:\n pass') | |
|
200 | 201 | self.assertEqual(isp.indent_spaces, 0) |
|
201 | ||
|
202 | isp.push('if 1:\n pass ') | |
|
203 | self.assertEqual(isp.indent_spaces, 0) | |
|
204 | ||
|
205 | def test_dedent_raise(self): | |
|
206 | isp = self.isp # shorthand | |
|
207 | # should NOT cause dedent | |
|
208 | isp.push('if 1:\n raised = 4') | |
|
209 | self.assertEqual(isp.indent_spaces, 4) | |
|
210 | isp.push('if 1:\n raise TypeError()') | |
|
211 | self.assertEqual(isp.indent_spaces, 0) | |
|
212 | isp.push('if 1:\n raise') | |
|
213 | self.assertEqual(isp.indent_spaces, 0) | |
|
214 | isp.push('if 1:\n raise ') | |
|
215 | self.assertEqual(isp.indent_spaces, 0) | |
|
216 | ||
|
217 | def test_dedent_return(self): | |
|
218 | isp = self.isp # shorthand | |
|
219 | # should NOT cause dedent | |
|
220 | isp.push('if 1:\n returning = 4') | |
|
221 | self.assertEqual(isp.indent_spaces, 4) | |
|
222 | isp.push('if 1:\n return 5 + 493') | |
|
223 | self.assertEqual(isp.indent_spaces, 0) | |
|
224 | isp.push('if 1:\n return') | |
|
225 | self.assertEqual(isp.indent_spaces, 0) | |
|
226 | isp.push('if 1:\n return ') | |
|
227 | self.assertEqual(isp.indent_spaces, 0) | |
|
228 | isp.push('if 1:\n return(0)') | |
|
229 | self.assertEqual(isp.indent_spaces, 0) | |
|
230 | ||
|
202 | 231 | def test_push(self): |
|
203 | 232 | isp = self.isp |
|
204 | 233 | self.assertTrue(isp.push('x=1')) |
General Comments 0
You need to be logged in to leave comments.
Login now