Commits

Anonymous committed b18fba8

codeanalyze: find_parens_start_from_inside() ignores strs

  • Participants
  • Parent commits 806b93c

Comments (0)

Files changed (2)

File rope/base/codeanalyze.py

             offset -= 1
         return offset
 
+    def find_parens_start_from_inside(self, offset, stop_searching=0):
+        opens = 1
+        while offset > stop_searching:
+            if self.source[offset] == '(':
+                break
+            if self.source[offset] != ',':
+                offset = self._find_primary_start(offset)
+            offset -= 1
+        return max(stop_searching, offset)
+
     def is_assigned_here(self, offset):
         operation = self.get_assignment_type(offset)
         operations = ('=', '-=', '+=', '*=', '/=', '%=', '**=',

File ropetest/codeanalyzetest.py

         index = code.rindex('p')
         self.assertTrue(word_finder.is_function_keyword_parameter(index))
 
+    def test_find_parens_start(self):
+        code = 'f(p)\n'
+        finder = WordRangeFinder(code)
+        self.assertEquals(1, finder.find_parens_start_from_inside(2))
+
+    def test_find_parens_start_with_multiple_entries(self):
+        code = 'myfunc(p1, p2, p3\n'
+        finder = WordRangeFinder(code)
+        self.assertEquals(code.index('('),
+                          finder.find_parens_start_from_inside(len(code) - 1))
+
+    def test_find_parens_start_with_nested_parens(self):
+        code = 'myfunc(p1, (p2, p3), p4\n'
+        finder = WordRangeFinder(code)
+        self.assertEquals(code.index('('),
+                          finder.find_parens_start_from_inside(len(code) - 1))
+
+    def test_find_parens_start_with_parens_in_strs(self):
+        code = 'myfunc(p1, "(", p4\n'
+        finder = WordRangeFinder(code)
+        self.assertEquals(code.index('('),
+                          finder.find_parens_start_from_inside(len(code) - 1))
+
+    def test_find_parens_start_with_parens_in_strs_in_multiple_lines(self):
+        code = 'myfunc  (\np1\n , \n "(" \n, \np4\n'
+        finder = WordRangeFinder(code)
+        self.assertEquals(code.index('('),
+                          finder.find_parens_start_from_inside(len(code) - 1))
+
 
 class ScopeNameFinderTest(unittest.TestCase):