summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fs.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/fs.py b/test/fs.py
index 473036ec..bd5ab501 100644
--- a/test/fs.py
+++ b/test/fs.py
@@ -1095,6 +1095,42 @@ def cut_writes(binary):
assert (screen['cols'], screen['rows']) == (132, 40), (screen['cols'], screen['rows'])
+def find_on_screen(client, word):
+ """Where `word` is drawn, as (col, row), off /screen: what a mousein
+ line clicks."""
+ screen = client.screen()
+ cols = screen['cols']
+ for row in range(screen['rows']):
+ line = ''.join(cell[0] or ' ' for cell in screen['cells'][row * cols:(row + 1) * cols])
+ at = line.find(word)
+ if at >= 0:
+ return at, row
+ raise AssertionError((word, 'not on the screen'))
+
+
+def keys_and_mouse(binary):
+ """kbdin and mousein: a script types and clicks as the user does, each
+ write done before it is answered, so no sleep or poll between a write
+ and the read that checks it; where to click is read off /screen."""
+ with tempfile.TemporaryDirectory(prefix='pardes-kbd-') as directory:
+ root = Path(directory)
+ (root / 'target.txt').write_bytes(b'hello-target\n')
+ with session(binary, root, 'kbd') as (client, _):
+ serial = new_pane(client, b'see \n')
+ client.write('/focus', f'{serial}\n'.encode())
+ client.write('/kbdin', 'Atarget.txt\x1b'.encode())
+ assert client.read(f'/pane/{serial}/body') == b'see target.txt\n'
+ col, row = find_on_screen(client, 'target.txt')
+ client.write('/mousein', f'm {col + 2} {row} 4\nm {col + 2} {row} 0\n'.encode())
+ opened = newest(client)
+ assert opened != serial and client.read('/index').splitlines()[-1].endswith(b'target.txt 1'), client.read('/index')
+ assert client.read(f'/pane/{opened}/body') == b'hello-target\n'
+ # Undone from the keyboard, as the user would: u in normal mode.
+ client.write('/focus', f'{serial}\n'.encode())
+ client.write('/kbdin', b'u')
+ assert client.read(f'/pane/{serial}/body') == b'see \n'
+
+
def edit_commands(binary):
"""Edit's `< | >` run off the loop and answer the write that ran them
once applied; a failing one changes nothing and fails the write in its
@@ -1207,6 +1243,7 @@ def edit_commands(binary):
def test(binary, quic=False):
started = time.monotonic()
+ keys_and_mouse(binary)
cut_writes(binary)
edit_commands(binary)
odd_paths(binary)