4 files changed
@@ -38,13 +38,13 @@ def current_dict(cursor_offset, line): | |||
| 38 | 38 | return None | |
| 39 | 39 | ||
| 40 | 40 | def current_string(cursor_offset, line): | |
| 41 | - """If inside a string, return the string (excluding quotes) | ||
| 41 | + """If inside a string of nonzero length, return the string (excluding quotes) | ||
| 42 | 42 | ||
| 43 | 43 | Weaker than bpython.Repl's current_string, because that checks that a string is a string | |
| 44 | 44 | based on previous lines in the buffer""" | |
| 45 | - for m in re.finditer('''(?P<open>(?:""")|"|(?:''\')|')(?:((?P<closed>.*?)(?P=open))|(?P<unclosed>.*))''', line): | ||
| 45 | + for m in re.finditer('''(?P<open>(?:""")|"|(?:''\')|')(?:((?P<closed>.+?)(?P=open))|(?P<unclosed>.+))''', line): | ||
| 46 | 46 | i = 3 if m.group(3) else 4 | |
| 47 | - if m.start(i) < cursor_offset and m.end(i) >= cursor_offset: | ||
| 47 | + if m.start(i) <= cursor_offset and m.end(i) >= cursor_offset: | ||
| 48 | 48 | return m.start(i), m.end(i), m.group(i) | |
| 49 | 49 | return None | |
| 50 | 50 | ||
@@ -8,6 +8,8 @@ | |||
| 8 | 8 | def skip(f): | |
| 9 | 9 | return lambda self: None | |
| 10 | 10 | ||
| 11 | + py3 = (sys.version_info[0] == 3) | ||
| 12 | + | ||
| 11 | 13 | from bpython import config, repl, cli, autocomplete | |
| 12 | 14 | ||
| 13 | 15 | def setup_config(conf): | |
@@ -399,7 +401,10 @@ def setUp(self): | |||
| 399 | 401 | # 3 Types of tab complete | |
| 400 | 402 | def test_simple_tab_complete(self): | |
| 401 | 403 | self.repl.matches_iter = MagicMock() | |
| 402 | - self.repl.matches_iter.__nonzero__.return_value = False | ||
| 404 | + if py3: | ||
| 405 | + self.repl.matches_iter.__bool__.return_value = False | ||
| 406 | + else: | ||
| 407 | + self.repl.matches_iter.__nonzero__.return_value = False | ||
| 403 | 408 | self.repl.complete = Mock() | |
| 404 | 409 | self.repl.print_line = Mock() | |
| 405 | 410 | self.repl.matches_iter.is_cseq.return_value = False | |
0 commit comments