summaryrefslogtreecommitdiffstats
path: root/regress
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2021-05-13 08:49:58 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2021-05-13 08:49:58 +0100
commit022d0210c5afa4e516183bf19715316ccca5d240 (patch)
treec4245f692cfed0bf1bd38db6c612ac9f07569058 /regress
parentf03b27c72be01ad1934079d1b6907f94efff9dea (diff)
More accurate vi(1) word navigation in copy mode and on the status line. This
changes the meaning of the word-separators option - setting it to the empty string is equivalent to the previous behavior. From Will Noble in GitHub issue 2693.
Diffstat (limited to 'regress')
-rw-r--r--regress/copy-mode-test-emacs.sh116
-rw-r--r--regress/copy-mode-test-vi.sh115
-rw-r--r--regress/copy-mode-test.txt5
3 files changed, 236 insertions, 0 deletions
diff --git a/regress/copy-mode-test-emacs.sh b/regress/copy-mode-test-emacs.sh
new file mode 100644
index 00000000..63293963
--- /dev/null
+++ b/regress/copy-mode-test-emacs.sh
@@ -0,0 +1,116 @@
+#!/bin/sh
+
+PATH=/bin:/usr/bin
+TERM=screen
+
+[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
+TMUX="$TEST_TMUX -f/dev/null -Ltest"
+$TMUX kill-server 2>/dev/null
+
+$TMUX new -d -x40 -y10 \
+ "cat copy-mode-test.txt; printf '\e[9;15H'; cat" || exit 1
+$TMUX set -g window-size manual || exit 1
+
+# Enter copy mode and go to the first column of the first row.
+$TMUX set-window-option -g mode-keys emacs
+$TMUX set-window-option -g word-separators ""
+$TMUX copy-mode
+$TMUX send-keys -X history-top
+$TMUX send-keys -X start-of-line
+
+# Test that `previous-word` and `previous-space`
+# do not go past the start of text.
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X previous-space
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer 2>/dev/null)" = "" ] || exit 1
+
+# Test that `next-word-end` does not skip single-letter words.
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "A" ] || exit 1
+
+# Test that `next-word-end` wraps around indented line breaks.
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-word
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "$(echo -e "words\n Indented")" ] || exit 1
+
+# Test that `next-word` wraps around un-indented line breaks.
+$TMUX send-keys -X next-word
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "$(echo -e "line\n")" ] || exit 1
+
+# Test that `next-word-end` treats periods as letters.
+$TMUX send-keys -X next-word
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "line..." ] || exit 1
+
+# Test that `previous-word` and `next-word` treat periods as letters.
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "$(echo -e "line...\n")" ] || exit 1
+
+# Test that `previous-space` and `next-space` treat periods as letters.
+$TMUX send-keys -X previous-space
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-space
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "$(echo -e "line...\n")" ] || exit 1
+
+# Test that `next-word` and `next-word-end` treat other symbols as letters.
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "... @nd then \$ym_bols[]{}" ] || exit 1
+
+# Test that `previous-word` treats other symbols as letters
+# and `next-word` wraps around for indented symbols
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "$(echo -e "\$ym_bols[]{}\n ")" ] || exit 1
+
+# Test that `next-word-end` treats digits as letters
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = " 500xyz" ] || exit 1
+
+# Test that `previous-word` treats digits as letters
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "500xyz" ] || exit 1
+
+# Test that `next-word` and `next-word-end` stop at the end of text.
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-space
+$TMUX send-keys -X next-space-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "500xyz" ] || exit 1
+
+$TMUX kill-server 2>/dev/null
+exit 0
diff --git a/regress/copy-mode-test-vi.sh b/regress/copy-mode-test-vi.sh
new file mode 100644
index 00000000..0eca3fa6
--- /dev/null
+++ b/regress/copy-mode-test-vi.sh
@@ -0,0 +1,115 @@
+#!/bin/sh
+
+PATH=/bin:/usr/bin
+TERM=screen
+
+[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
+TMUX="$TEST_TMUX -f/dev/null -Ltest"
+$TMUX kill-server 2>/dev/null
+
+$TMUX new -d -x40 -y10 \
+ "cat copy-mode-test.txt; printf '\e[9;15H'; cat" || exit 1
+$TMUX set -g window-size manual || exit 1
+
+# Enter copy mode and go to the first column of the first row.
+$TMUX set-window-option -g mode-keys vi
+$TMUX copy-mode
+$TMUX send-keys -X history-top
+$TMUX send-keys -X start-of-line
+
+# Test that `previous-word` and `previous-space`
+# do not go past the start of text.
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X previous-space
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "A" ] || exit 1
+
+# Test that `next-word-end` skips single-letter words
+# and `previous-word` does not skip multi-letter words.
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "line" ] || exit 1
+
+# Test that `next-word-end` wraps around indented line breaks.
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-word
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "$(echo -e "words\n Indented")" ] || exit 1
+
+# Test that `next-word` wraps around un-indented line breaks.
+$TMUX send-keys -X next-word
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "$(echo -e "line\nA")" ] || exit 1
+
+# Test that `next-word-end` does not treat periods as letters.
+$TMUX send-keys -X next-word
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "line" ] || exit 1
+
+# Test that `next-space-end` treats periods as letters.
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-space-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "line..." ] || exit 1
+
+# Test that `previous-space` and `next-space` treat periods as letters.
+$TMUX send-keys -X previous-space
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-space
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "$(echo -e "line...\n.")" ] || exit 1
+
+# Test that `next-word` and `next-word-end` do not treat other symbols as letters.
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "... @nd then" ] || exit 1
+
+# Test that `next-space` wraps around for indented symbols
+$TMUX send-keys -X next-space
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-space
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "$(echo -e "\$ym_bols[]{}\n ?")" ] || exit 1
+
+# Test that `next-word-end` treats digits as letters
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "? 500xyz" ] || exit 1
+
+# Test that `previous-word` treats digits as letters
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X previous-word
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "500xyz" ] || exit 1
+
+# Test that `next-word`, `next-word-end`,
+# `next-space`, and `next-space-end` stop at the end of text.
+$TMUX send-keys -X begin-selection
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-word-end
+$TMUX send-keys -X next-word
+$TMUX send-keys -X next-space
+$TMUX send-keys -X next-space-end
+$TMUX send-keys -X copy-selection
+[ "$($TMUX show-buffer)" = "500xyz" ] || exit 1
+
+$TMUX kill-server 2>/dev/null
+exit 0
diff --git a/regress/copy-mode-test.txt b/regress/copy-mode-test.txt
new file mode 100644
index 00000000..a804f1f8
--- /dev/null
+++ b/regress/copy-mode-test.txt
@@ -0,0 +1,5 @@
+A line of words
+ Indented line
+Another line...
+... @nd then $ym_bols[]{}
+ ?? 500xyz