Commits

Anonymous committed 229e54b

LogicalLineFinder.generate_starts() starts tokenizing from module start

Comments (0)

Files changed (2)

rope/base/codeanalyze.py

                 indents = count_line_indents(self.lines.get_line(lineno))
 
     def generate_starts(self, start_line=1, end_line=None):
-        block_start = get_block_start(self.lines, start_line)
+        # XXX: `block_start` should be at a better position!
+        block_start = 1
         readline = LinesToReadline(self.lines, block_start)
         shifted = start_line - block_start + 1
         for start, end in self._logical_lines(readline):

ropetest/codeanalyzetest.py

         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
         self.assertEquals([2], list(line_finder.generate_starts()))
 
+    def test_generating_line_starts_and_unmatched_deindents(self):
+        code = 'if True:\n    if True:\n        if True:\n' \
+               '            a = 1\n    b = 1\n'
+        line_finder = LogicalLineFinder(SourceLinesAdapter(code))
+        self.assertEquals([4, 5], list(line_finder.generate_starts(4)))
+
 
 def suite():
     result = unittest.TestSuite()