diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-08-16 15:29:24 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-08-16 15:29:24 -0400 |
| commit | fc2c4f173673fce90cfa16dfe0d425bf1c399b54 (patch) | |
| tree | 8bf6ccc3138d0695e509a527309b2869e9c8de27 /tests.sh | |
| parent | Fix plugin hotkey (diff) | |
| download | tmux-toggle-term-fc2c4f173673fce90cfa16dfe0d425bf1c399b54.zip | |
Add bats to test splitting panes
Diffstat (limited to 'tests.sh')
| -rw-r--r-- | tests.sh | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests.sh b/tests.sh new file mode 100644 index 0000000..09126f9 --- /dev/null +++ b/tests.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bats + +load 'vendor/bats-support/load' +load 'vendor/bats-assert/load' + +setup() { + export TMUX_SOCKET="test$$" + export TEST_SESSION="test-$BATS_TEST_NUMBER-$$" + tmux_start_server +} + +teardown() { + tmux_kill_server +} + +tmux_start_server() { + tmux -L "$TMUX_SOCKET" new-session -d -s "$TEST_SESSION" 'sleep 1000' +} + +tmux_kill_server() { + tmux -L "$TMUX_SOCKET" kill-server || true +} + +tmux_pane_count() { + num_panes=$(tmux -L "$TMUX_SOCKET" list-panes | wc -l | bc) + echo "$num_panes" +} + +tmux_active_panes() { + active_panes=$(tmux -L "$TMUX_SOCKET" list-panes -F '#{pane_active}' | tr '\n' '-' | sed 's/-$//g') + echo "$active_panes" +} + +tmux_is_zoomed() { + is_zoomed=$(tmux -L "$TMUX_SOCKET" list-panes -F '#{window_zoomed_flag}') + if echo "$is_zoomed" | grep -q 1; then + echo 'true' + else + echo 'false' + fi +} + +@test 'split creates a new pane' { + assert_equal "$(tmux_pane_count)" 1 + assert_equal "$(tmux_active_panes)" '1' + + ./toggle-term.sh split + + 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' + + ./toggle-term.sh split + ./toggle-term.sh split + + assert_equal "$(tmux_pane_count)" 2 + assert_equal "$(tmux_active_panes)" '1-0' + assert_equal "$(tmux_is_zoomed)" 'true' +} |