Permalink
Browse files

fix trailing whitespace from reseting indentation

  • Loading branch information...
1 parent 26addb0 commit e69ecd40bd2832db569babe471fcba6aa7784a46 @ivanov committed Jul 11, 2011
Showing with 16 additions and 1 deletion.
  1. +1 −1 IPython/core/inputsplitter.py
  2. +15 −0 IPython/core/tests/test_inputsplitter.py
@@ -434,7 +434,7 @@ def _find_indent(self, line):
#print 'Full dedent in text',self.source # dbg
full_dedent = True
- if line[-1] == ':':
+ if line.rstrip()[-1] == ':':
indent_spaces += 4
elif dedent_re.match(line):
indent_spaces -= 4
@@ -200,6 +200,21 @@ def test_indent3(self):
isp.push("if 1:")
isp.push(" x = (1+\n 2)")
self.assertEqual(isp.indent_spaces, 4)
+
+ def test_indent4(self):
+ # In cell mode, inputs must be fed in whole blocks, so skip this test
+ if self.isp.input_mode == 'cell': return
+
+ isp = self.isp
+ # whitespace after ':' should not screw up indent level
+ isp.push('if 1: \n x=1')
+ self.assertEqual(isp.indent_spaces, 4)
+ isp.push('y=2\n')
+ self.assertEqual(isp.indent_spaces, 0)
+ isp.push('if 1:\t\n x=1')
+ self.assertEqual(isp.indent_spaces, 4)
+ isp.push('y=2\n')
+ self.assertEqual(isp.indent_spaces, 0)
def test_dedent_pass(self):
isp = self.isp # shorthand

0 comments on commit e69ecd4

Please sign in to comment.