Anonymous avatar Anonymous committed b18fba8

codeanalyze: find_parens_start_from_inside() ignores strs

Comments (0)

Files changed (2)

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 = ('=', '-=', '+=', '*=', '/=', '%=', '**=',

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):
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.