Add split-wezterm: split WezTerm pane into a rows x cols grid
Splits the current pane into evenly-sized grid using wezterm cli split-pane. Supports optional command per pane, dryrun mode, and auto-detects native or Flatpak WezTerm CLI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
67
tests/test-split-wezterm.sh
Executable file
67
tests/test-split-wezterm.sh
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
SCRIPT="$(cd "$(dirname "$0")/.." && pwd)/scripts/split-wezterm"
|
||||
PASS=0; FAIL=0
|
||||
|
||||
pass() { echo -e "\e[32m PASS\e[0m $1"; (( PASS++ )); }
|
||||
fail() { echo -e "\e[31m FAIL\e[0m $1: $2"; (( FAIL++ )); }
|
||||
|
||||
assert_exit() {
|
||||
local desc="$1" expected="$2"; shift 2
|
||||
local actual
|
||||
"$@" >/dev/null 2>&1 && actual=0 || actual=$?
|
||||
if [[ "$actual" == "$expected" ]]; then pass "$desc"; else fail "$desc" "expected exit $expected, got $actual"; fi
|
||||
}
|
||||
|
||||
assert_output_contains() {
|
||||
local desc="$1" pattern="$2"; shift 2
|
||||
local output
|
||||
output=$("$@" 2>&1) || true
|
||||
if echo "$output" | grep -qF "$pattern"; then pass "$desc"; else fail "$desc" "output missing: $pattern"; fi
|
||||
}
|
||||
|
||||
assert_line_count() {
|
||||
local desc="$1" expected="$2"; shift 2
|
||||
local count
|
||||
count=$("$@" 2>&1 | grep -c '^\[dryrun\]') || true
|
||||
if [[ "$count" == "$expected" ]]; then pass "$desc"; else fail "$desc" "expected $expected dryrun lines, got $count"; fi
|
||||
}
|
||||
|
||||
export WEZTERM_PANE=0
|
||||
|
||||
echo "=== split-wezterm tests ==="
|
||||
|
||||
# Help
|
||||
assert_exit "help flag exits 0" 0 "$SCRIPT" --help
|
||||
assert_output_contains "help shows usage" "Usage:" "$SCRIPT" --help
|
||||
|
||||
# Validation
|
||||
assert_exit "no args exits 1" 1 "$SCRIPT"
|
||||
assert_exit "one arg exits 1" 1 "$SCRIPT" 3
|
||||
assert_exit "zero rows exits 1" 1 "$SCRIPT" 0 3
|
||||
assert_exit "rows > 10 exits 1" 1 "$SCRIPT" 11 3
|
||||
assert_exit "non-integer rows exits 1" 1 "$SCRIPT" abc 3
|
||||
|
||||
# 1x1 — no-op
|
||||
assert_exit "1x1 exits 0" 0 "$SCRIPT" 1 1
|
||||
assert_output_contains "1x1 says nothing to do" "nothing to do" "$SCRIPT" 1 1
|
||||
|
||||
# Dryrun counts (each split-pane = 1 dryrun line + 1 summary line)
|
||||
# 2x1 = 1 row split + 1 summary = 2 lines
|
||||
assert_line_count "2x1 produces 1 split" 2 "$SCRIPT" --dryrun 2 1
|
||||
# 1x3 = 2 col splits + 1 summary = 3 lines
|
||||
assert_line_count "1x3 produces 2 splits" 3 "$SCRIPT" --dryrun 1 3
|
||||
# 2x2 = 1 row + 2 col + 1 summary = 4 lines
|
||||
assert_line_count "2x2 produces 3 splits" 4 "$SCRIPT" --dryrun 2 2
|
||||
# 3x4 = 2 row + 9 col + 1 summary = 12 lines
|
||||
assert_line_count "3x4 produces 11 splits" 12 "$SCRIPT" --dryrun 3 4
|
||||
# 3x4 with command = 11 splits + 1 send-text + 1 summary = 13 lines
|
||||
assert_line_count "3x4 with cmd produces 13 lines" 13 "$SCRIPT" --dryrun 3 4 -- echo hi
|
||||
|
||||
# Summary line
|
||||
assert_output_contains "dryrun summary" "Would create 3x4 grid (12 panes)" "$SCRIPT" --dryrun 3 4
|
||||
|
||||
echo ""
|
||||
echo "Results: $PASS passed, $FAIL failed"
|
||||
(( FAIL == 0 ))
|
||||
Reference in New Issue
Block a user