|
6 | 6 |
|
7 | 7 |
|
8 | 8 | import itertools |
| 9 | +import rlcompleter |
9 | 10 | from functools import partial |
10 | 11 | from test.support import force_not_colorized_test_class |
11 | 12 | from typing import Iterable |
|
16 | 17 | from .support import prepare_reader as default_prepare_reader |
17 | 18 |
|
18 | 19 | try: |
| 20 | + from _pyrepl._module_completer import ModuleCompleter |
19 | 21 | from _pyrepl.console import Event, Console |
| 22 | + from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig |
| 23 | + from _pyrepl.utils import wlen |
20 | 24 | from _pyrepl.windows_console import ( |
21 | 25 | WindowsConsole, |
22 | 26 | MOVE_LEFT, |
@@ -63,6 +67,45 @@ def handle_events( |
63 | 67 | prepare_reader = prepare_reader or default_prepare_reader |
64 | 68 | return handle_all_events(events, prepare_console, prepare_reader) |
65 | 69 |
|
| 70 | + def test_cursor_position_console_width_completion_suggestion(self): |
| 71 | + height, width = 25, 80 |
| 72 | + config = ReadlineConfig() |
| 73 | + namespace = {"interpreter": None, "process": None, "thread": None} |
| 74 | + config.module_completer = ModuleCompleter(namespace) |
| 75 | + code = "from concurrent.futures import \t\tt\n" |
| 76 | + con = WindowsConsole(encoding="utf-8") |
| 77 | + con.getheightwidth = MagicMock(return_value=(height, width)) |
| 78 | + con.height = height |
| 79 | + con.width = width |
| 80 | + |
| 81 | + def assert_posxy_changed_in_parallel_with_screenxy(method): |
| 82 | + def wrapper(y, oldline, newline, px_coord): |
| 83 | + newline = newline.ljust(width) |
| 84 | + posxy_before = con.posxy |
| 85 | + screen_xy_before = con.screen_xy |
| 86 | + result = method(y, oldline, newline, px_coord) |
| 87 | + posxy_after = con.posxy |
| 88 | + screen_xy_after = con.screen_xy |
| 89 | + posxy_delta = ( |
| 90 | + posxy_after[0] - posxy_before[0], |
| 91 | + posxy_after[1] - posxy_before[1],) |
| 92 | + screen_xy_delta = ( |
| 93 | + screen_xy_after[0] - screen_xy_before[0], |
| 94 | + screen_xy_after[1] - screen_xy_before[1],) |
| 95 | + self.assertEqual(posxy_delta, screen_xy_delta) |
| 96 | + return result |
| 97 | + return wrapper |
| 98 | + |
| 99 | + original_method = con._WindowsConsole__write_changed_line |
| 100 | + con._WindowsConsole__write_changed_line = ( |
| 101 | + assert_posxy_changed_in_parallel_with_screenxy(original_method) |
| 102 | + ) |
| 103 | + |
| 104 | + for c in code: |
| 105 | + con.event_queue.push(bytes(c.encode("utf-8"))) |
| 106 | + reader = ReadlineAlikeReader(console=con, config=config) |
| 107 | + reader.readline() |
| 108 | + |
66 | 109 | def handle_events_narrow(self, events): |
67 | 110 | return self.handle_events(events, width=5) |
68 | 111 |
|
|
0 commit comments