mirror of
https://github.com/tmux/tmux.git
synced 2026-10-12 21:54:23 +00:00
Add array test.
This commit is contained in:
@@ -3,12 +3,14 @@
|
|||||||
# Tests of array options in the options engine (options_array_* in options.c
|
# Tests of array options in the options engine (options_array_* in options.c
|
||||||
# and the array handling in cmd-set-option.c / cmd-show-options.c).
|
# and the array handling in cmd-set-option.c / cmd-show-options.c).
|
||||||
#
|
#
|
||||||
# Array options are indexed by integer. This exercises: setting a whole array
|
# Array options are keyed by string, with numeric-looking keys kept compatible
|
||||||
# from a separator-delimited string; per-index set with option[N]; -a append
|
# with the old numeric forms. This exercises: setting a whole array from a
|
||||||
# (which lands at the next free index); show ordering by ascending index and
|
# separator-delimited string; per-key set with option[key]; -a append (which
|
||||||
# preservation of gaps; per-index unset with -u; show -v of a single index and
|
# lands at the next free numeric key); show ordering by numeric keys first in
|
||||||
# of a missing index; and per-option separators (user-keys splits only on
|
# ascending order followed by string keys in strcmp order; preservation of gaps;
|
||||||
# comma, update-environment on space or comma).
|
# per-key unset with -u; show -v of a single key and of a missing key; and
|
||||||
|
# per-option separators (user-keys splits only on comma, update-environment on
|
||||||
|
# space or comma).
|
||||||
#
|
#
|
||||||
# update-environment (session), status-format (session), user-keys (server)
|
# update-environment (session), status-format (session), user-keys (server)
|
||||||
# and command-alias (server) are used as representative array options.
|
# and command-alias (server) are used as representative array options.
|
||||||
@@ -87,41 +89,59 @@ $TMUX new-session -d -s main -x 80 -y 24 || exit 1
|
|||||||
# --- whole-array assignment splits on the separator -----------------------
|
# --- whole-array assignment splits on the separator -----------------------
|
||||||
#
|
#
|
||||||
# update-environment has the default " ," separator, so a single string value
|
# update-environment has the default " ," separator, so a single string value
|
||||||
# is split into consecutive indices starting at 0.
|
# is split into consecutive numeric keys starting at 0.
|
||||||
check_ok set -g update-environment "AAA BBB,CCC"
|
check_ok set -g update-environment "AAA BBB,CCC"
|
||||||
check_array "-g update-environment" "update-environment[0] AAA
|
check_array "-g update-environment" "update-environment[0] AAA
|
||||||
update-environment[1] BBB
|
update-environment[1] BBB
|
||||||
update-environment[2] CCC"
|
update-environment[2] CCC"
|
||||||
|
|
||||||
# --- -a append goes to the next free index --------------------------------
|
# --- -a append goes to the next free numeric key --------------------------
|
||||||
check_ok set -ga update-environment "DDD"
|
check_ok set -ga update-environment "DDD"
|
||||||
check_array "-g update-environment" "update-environment[0] AAA
|
check_array "-g update-environment" "update-environment[0] AAA
|
||||||
update-environment[1] BBB
|
update-environment[1] BBB
|
||||||
update-environment[2] CCC
|
update-environment[2] CCC
|
||||||
update-environment[3] DDD"
|
update-environment[3] DDD"
|
||||||
|
|
||||||
# --- per-index unset leaves a gap; show preserves order and gaps ----------
|
# --- per-key unset leaves a gap; show preserves order and gaps ------------
|
||||||
check_ok set -gu update-environment[1]
|
check_ok set -gu update-environment[1]
|
||||||
check_array "-g update-environment" "update-environment[0] AAA
|
check_array "-g update-environment" "update-environment[0] AAA
|
||||||
update-environment[2] CCC
|
update-environment[2] CCC
|
||||||
update-environment[3] DDD"
|
update-environment[3] DDD"
|
||||||
# show -v of an existing index returns its value; a missing index is empty.
|
# show -v of an existing key returns its value; a missing key is empty.
|
||||||
check_value "-gv update-environment[0]" "AAA"
|
check_value "-gv update-environment[0]" "AAA"
|
||||||
check_value "-gv update-environment[1]" ""
|
check_value "-gv update-environment[1]" ""
|
||||||
|
check_ok set -g update-environment[notify] "EEE"
|
||||||
|
check_ok set -ga update-environment "FFF"
|
||||||
|
check_array "-g update-environment" "update-environment[0] AAA
|
||||||
|
update-environment[1] FFF
|
||||||
|
update-environment[2] CCC
|
||||||
|
update-environment[3] DDD
|
||||||
|
update-environment[notify] EEE"
|
||||||
|
|
||||||
# --- explicit indexed set, including out-of-order and gaps ----------------
|
# --- explicit keyed set, including out-of-order and gaps ------------------
|
||||||
#
|
#
|
||||||
# status-format is a session array; assigning an empty string first clears its
|
# status-format is a session array; assigning an empty string first clears its
|
||||||
# multi-index default, then set specific indices out of order and confirm show
|
# multi-index default, then set specific keys out of order and confirm show
|
||||||
# sorts by ascending index and keeps the gap at [1].
|
# sorts by ascending numeric key and keeps the gap at [1].
|
||||||
check_ok set -g status-format ""
|
check_ok set -g status-format ""
|
||||||
check_array "-g status-format" "status-format"
|
check_array "-g status-format" "status-format"
|
||||||
check_ok set -g status-format[5] "five"
|
check_ok set -g status-format[5] "five"
|
||||||
check_ok set -g status-format[0] "zero"
|
check_ok set -g status-format[0] "zero"
|
||||||
check_ok set -g status-format[2] "two"
|
check_ok set -g status-format[2] "two"
|
||||||
|
check_ok set -g status-format[01] "one"
|
||||||
|
check_ok set -g status-format[zoom] "zoom"
|
||||||
|
check_ok set -g status-format[foo-bar] "foo-bar"
|
||||||
|
check_ok set -g status-format[xterm-256color] "xterm"
|
||||||
check_array "-g status-format" "status-format[0] zero
|
check_array "-g status-format" "status-format[0] zero
|
||||||
|
status-format[1] one
|
||||||
status-format[2] two
|
status-format[2] two
|
||||||
status-format[5] five"
|
status-format[5] five
|
||||||
|
status-format[foo-bar] foo-bar
|
||||||
|
status-format[xterm-256color] xterm
|
||||||
|
status-format[zoom] zoom"
|
||||||
|
check_value "-gv status-format[01]" "one"
|
||||||
|
check_ok set -gu status-format[zoom]
|
||||||
|
check_value "-gv status-format[zoom]" ""
|
||||||
|
|
||||||
# --- comma-only separator (user-keys) -------------------------------------
|
# --- comma-only separator (user-keys) -------------------------------------
|
||||||
#
|
#
|
||||||
@@ -133,11 +153,15 @@ user-keys[1] "Two Three"'
|
|||||||
|
|
||||||
# --- command-type array (a hook) ------------------------------------------
|
# --- command-type array (a hook) ------------------------------------------
|
||||||
#
|
#
|
||||||
# Hooks are command arrays: an indexed value is parsed as a command when set
|
# Hooks are command arrays: a keyed value is parsed as a command when set
|
||||||
# and re-printed from the parsed command list; a syntax error is reported.
|
# and re-printed from the parsed command list; a syntax error is reported.
|
||||||
check_ok set -g alert-bell[0] "display-message hi"
|
check_ok set -g alert-bell[0] "display-message hi"
|
||||||
check_value "-gv alert-bell[0]" "display-message hi"
|
check_value "-gv alert-bell[0]" "display-message hi"
|
||||||
check_fail "syntax error" set -g alert-bell[0] "if -x {"
|
check_fail "syntax error" set -g alert-bell[0] "if -x {"
|
||||||
|
check_ok set-hook -g window-renamed[notify] "display-message renamed"
|
||||||
|
check_value "-gv window-renamed[notify]" "display-message renamed"
|
||||||
|
check_ok set-hook -gu window-renamed[notify]
|
||||||
|
check_value "-gv window-renamed[notify]" ""
|
||||||
|
|
||||||
# --- colour-type array ----------------------------------------------------
|
# --- colour-type array ----------------------------------------------------
|
||||||
#
|
#
|
||||||
@@ -146,11 +170,11 @@ check_ok set -w pane-colours[0] red
|
|||||||
check_value "-wv pane-colours[0]" "red"
|
check_value "-wv pane-colours[0]" "red"
|
||||||
check_fail "bad colour: xxxyyy" set -w pane-colours[1] xxxyyy
|
check_fail "bad colour: xxxyyy" set -w pane-colours[1] xxxyyy
|
||||||
|
|
||||||
# --- -o refuses to overwrite an already-set index -------------------------
|
# --- -o refuses to overwrite an already-set key ---------------------------
|
||||||
check_ok set -g command-alias[9] "x=list-keys"
|
check_ok set -g command-alias[9] "x=list-keys"
|
||||||
check_fail "already set: command-alias[9]" set -go command-alias[9] "y=list-keys"
|
check_fail "already set: command-alias[9]" set -go command-alias[9] "y=list-keys"
|
||||||
|
|
||||||
# --- non-array option rejects index syntax --------------------------------
|
# --- non-array option rejects key syntax ----------------------------------
|
||||||
#
|
#
|
||||||
# status-left is a plain string; indexing it is an error.
|
# status-left is a plain string; indexing it is an error.
|
||||||
check_fail "not an array: status-left[0]" set -g status-left[0] "x"
|
check_fail "not an array: status-left[0]" set -g status-left[0] "x"
|
||||||
|
|||||||
Reference in New Issue
Block a user