From 6003edfb4229d20d0ddb14ee9697a993d4961d64 Mon Sep 17 00:00:00 2001 From: Michael Forster Date: Sun, 3 Jul 2022 05:38:16 +0200 Subject: [PATCH] Add test for the default cursor selection mode Also add documentation for the tests --- tests/pexpects/cursor_selection.py | 36 ++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/pexpects/cursor_selection.py b/tests/pexpects/cursor_selection.py index 507d15517..2476916c9 100644 --- a/tests/pexpects/cursor_selection.py +++ b/tests/pexpects/cursor_selection.py @@ -1,21 +1,29 @@ #!/usr/bin/env python3 from pexpect_helper import SpawnedProc -home, end = "\x01", "\x05" -left, right ="\x02", "\x06" -select, dump = "\x00", "!" - sp = SpawnedProc() sendline, expect_prompt, expect_str = sp.sendline, sp.expect_prompt, sp.expect_str expect_prompt() +# Set up key bindings + +# Movement keys from the default key bindings +home, end = "\x01", "\x05" # Ctrl-A, Ctrl-E +left, right ="\x02", "\x06" # Ctrl-B, Ctrl-F + +# Additional keys to start selecting and dump the current selection +select, dump = "\x00", "!" # Ctrl-Space, "!" + sendline("bind -k nul begin-selection") expect_prompt() sendline("bind ! 'echo -n \"<$(commandline --current-selection)>\"'") expect_prompt() +# Test inclusive mode + sendline("set fish_cursor_selection_mode inclusive") +# at the beginning of the line sendline("echo" + home + select + dump) expect_str("") sendline("echo" + home + select + right + dump) @@ -23,6 +31,7 @@ expect_str("") sendline("echo" + home + right + select + left + dump) expect_str("") +# in the middle of the line sendline("echo" + home + right + select + dump) expect_str("") sendline("echo" + home + right + select + right + dump) @@ -30,6 +39,7 @@ expect_str("") sendline("echo" + home + right + right + select + left + dump) expect_str("") +# at the end of the line sendline("echo" + end + select + dump) expect_str("<>") sendline("echo" + end + select + left + dump) @@ -37,8 +47,11 @@ expect_str("") sendline("echo" + end + left + select + right + dump) expect_str("") +# Test exclusive mode + sendline("set fish_cursor_selection_mode exclusive") +# at the beginning of the line sendline("echo" + home + select + dump) expect_str("<>") sendline("echo" + home + select + right + dump) @@ -46,6 +59,7 @@ expect_str("") sendline("echo" + home + right + select + left + dump) expect_str("") +# in the middle of the line sendline("echo" + home + right + select + dump) expect_str("<>") sendline("echo" + home + right + select + right + dump) @@ -53,9 +67,23 @@ expect_str("") sendline("echo" + home + right + right + select + left + dump) expect_str("") +# at the end of the line sendline("echo" + end + select + dump) expect_str("<>") sendline("echo" + end + select + left + dump) expect_str("") sendline("echo" + end + left + select + right + dump) expect_str("") + +# Test default setting. +# We only test that the correct implementation is chosen and rely on the detailed tests from above. + +# without a configured selection mode +sendline("set -u fish_cursor_selection_mode") +sendline("echo" + home + right + select + right + dump) +expect_str("") + +# with an unknown setting +sendline("set fish_cursor_selection_mode unknown") +sendline("echo" + home + right + select + right + dump) +expect_str("")