blob: 88e34aa4ed010068cdee0c82961af8c53287c643 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
#!/usr/bin/env bats
load '../vendor/bats-support/load'
load '../vendor/bats-assert/load'
TOGGLE_TERM_SCRIPT_PATH="$BATS_TEST_DIRNAME/../scripts/toggle-term.sh"
PLUGIN_SCRIPT_PATH="$BATS_TEST_DIRNAME/../plugin.tmux"
setup() {
export TMUX_SOCKET="test$$"
export TMUX_CONFIG_PATH="$TMUX_CONFIG_PATH"
export TEST_SESSION="test-$BATS_TEST_NUMBER-$$"
tmux_start_server
}
teardown() {
tmux_kill_server
}
tmux_start_server() {
tmux -f "$TMUX_CONFIG_PATH" -L "$TMUX_SOCKET" new-session -d -s "$TEST_SESSION" 'sleep 1000'
}
tmux_kill_server() {
tmux -f "$TMUX_CONFIG_PATH" -L "$TMUX_SOCKET" kill-server || true
}
tmux_pane_count() {
num_panes=$(tmux -f "$TMUX_CONFIG_PATH" -L "$TMUX_SOCKET" list-panes | wc -l | sed 's/^[[:space:]]*//g')
echo "$num_panes"
}
tmux_active_panes() {
active_panes=$(tmux -f "$TMUX_CONFIG_PATH" -L "$TMUX_SOCKET" list-panes -F '#{pane_active}' | tr '\n' '-' | sed 's/-$//g')
echo "$active_panes"
}
tmux_is_zoomed() {
is_zoomed=$(tmux -f "$TMUX_CONFIG_PATH" -L "$TMUX_SOCKET" list-panes -F '#{window_zoomed_flag}')
if echo "$is_zoomed" | grep -q 1; then
echo 'true'
else
echo 'false'
fi
}
tmux_set_option() {
option="$1"
value="$2"
tmux -f "$TMUX_CONFIG_PATH" -L "$TMUX_SOCKET" set-option -g "$option" "$value"
}
tmux_get_key_bindings() {
tmux -f "$TMUX_CONFIG_PATH" -L "$TMUX_SOCKET" list-keys 2>/dev/null | grep "toggle-term" || echo ""
}
tmux_has_prefix_binding() {
key="$1"
mode="$2"
tmux_get_key_bindings | grep -q "bind-key.*-T prefix.*${key}.*toggle-term.sh $mode"
}
tmux_has_root_binding() {
key="$1"
mode="$2"
tmux_get_key_bindings | grep -q "bind-key.*-T root.*\"*${key}\"*.*toggle-term.sh $mode"
}
load_plugin() {
"$PLUGIN_SCRIPT_PATH"
}
@test 'split creates a new pane' {
assert_equal "$(tmux_pane_count)" 1
assert_equal "$(tmux_active_panes)" '1'
run "$TOGGLE_TERM_SCRIPT_PATH" split
assert_success
assert_equal "$(tmux_pane_count)" 2
assert_equal "$(tmux_active_panes)" '0-1'
}
@test 'toggling split changes back active pane' {
assert_equal "$(tmux_pane_count)" 1
assert_equal "$(tmux_active_panes)" '1'
run "$TOGGLE_TERM_SCRIPT_PATH" split
assert_success
run "$TOGGLE_TERM_SCRIPT_PATH" split
assert_success
assert_equal "$(tmux_pane_count)" 2
assert_equal "$(tmux_active_panes)" '1-0'
assert_equal "$(tmux_is_zoomed)" 'true'
}
@test 'plugin loads with default key bindings' {
run load_plugin
assert_success
run tmux_has_root_binding "C-f" "float"
assert_success
run tmux_has_root_binding "C-;" "split"
assert_success
}
@test 'custom float key without prefix works' {
tmux_set_option "@toggle-term-float-key" "M-f"
run load_plugin
assert_success
run tmux_has_root_binding "M-f" "float"
assert_success
}
@test 'custom split key without prefix works' {
tmux_set_option "@toggle-term-split-key" "M-t"
run load_plugin
assert_success
run tmux_has_root_binding "M-t" "split"
assert_success
}
@test 'float key with prefix enabled' {
tmux_set_option "@toggle-term-float-key" "f"
tmux_set_option "@toggle-term-float-use-prefix" "true"
run load_plugin
assert_success
run tmux_has_prefix_binding "f" "float"
assert_success
run tmux_has_root_binding "f" "float"
assert_failure
}
@test 'split key with prefix enabled' {
tmux_set_option "@toggle-term-split-key" "s"
tmux_set_option "@toggle-term-split-use-prefix" "true"
run load_plugin
assert_success
run tmux_has_prefix_binding "s" "split"
assert_success
run tmux_has_root_binding "s" "split"
assert_failure
}
@test 'mixed prefix configuration works' {
tmux_set_option "@toggle-term-float-key" "f"
tmux_set_option "@toggle-term-float-use-prefix" "true"
tmux_set_option "@toggle-term-split-key" "C-t"
tmux_set_option "@toggle-term-split-use-prefix" "false"
run load_plugin
assert_success
run tmux_has_prefix_binding "f" "float"
assert_success
run tmux_has_root_binding "f" "float"
assert_failure
run tmux_has_root_binding "C-t" "split"
assert_success
run tmux_has_prefix_binding "C-t" "split"
assert_failure
}
@test 'prefix options default to false' {
run load_plugin
assert_success
run tmux_has_root_binding "C-f" "float"
assert_success
run tmux_has_root_binding "C-;" "split"
assert_success
run tmux_has_prefix_binding "C-f" "float"
assert_failure
run tmux_has_prefix_binding "C-;" "split"
assert_failure
}
@test 'both float and split are enabled by default' {
run load_plugin
assert_success
run tmux_has_root_binding "C-f" "float"
assert_success
run tmux_has_root_binding "C-;" "split"
assert_success
}
@test 'float can be disabled' {
tmux_set_option "@toggle-term-float-enabled" "false"
run load_plugin
assert_success
run tmux_has_root_binding "C-f" "float"
assert_failure
run tmux_has_root_binding "C-;" "split"
assert_success
}
@test 'split can be disabled' {
tmux_set_option "@toggle-term-split-enabled" "false"
run load_plugin
assert_success
run tmux_has_root_binding "C-f" "float"
assert_success
run tmux_has_root_binding "C-;" "split"
assert_failure
}
@test 'both float and split can be disabled' {
tmux_set_option "@toggle-term-float-enabled" "false"
tmux_set_option "@toggle-term-split-enabled" "false"
run load_plugin
assert_success
run tmux_has_root_binding "C-f" "float"
assert_failure
run tmux_has_root_binding "C-;" "split"
assert_failure
}
@test 'disabled float does not bind with custom key' {
tmux_set_option "@toggle-term-float-enabled" "false"
tmux_set_option "@toggle-term-float-key" "M-f"
run load_plugin
assert_success
run tmux_has_root_binding "M-f" "float"
assert_failure
}
@test 'disabled split does not bind with custom key' {
tmux_set_option "@toggle-term-split-enabled" "false"
tmux_set_option "@toggle-term-split-key" "M-t"
run load_plugin
assert_success
run tmux_has_root_binding "M-t" "split"
assert_failure
}
@test 'disabled float does not bind with prefix' {
tmux_set_option "@toggle-term-float-enabled" "false"
tmux_set_option "@toggle-term-float-key" "f"
tmux_set_option "@toggle-term-float-use-prefix" "true"
run load_plugin
assert_success
run tmux_has_prefix_binding "f" "float"
assert_failure
}
@test 'disabled split does not bind with prefix' {
tmux_set_option "@toggle-term-split-enabled" "false"
tmux_set_option "@toggle-term-split-key" "f"
tmux_set_option "@toggle-term-split-use-prefix" "true"
run load_plugin
assert_success
run tmux_has_prefix_binding "f" "split"
assert_failure
}
|