aboutsummaryrefslogtreecommitdiff
path: root/tests/tmux-util/test_tmux_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tmux-util/test_tmux_util.py')
-rw-r--r--tests/tmux-util/test_tmux_util.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/tmux-util/test_tmux_util.py b/tests/tmux-util/test_tmux_util.py
index 24cc335..e313af6 100644
--- a/tests/tmux-util/test_tmux_util.py
+++ b/tests/tmux-util/test_tmux_util.py
@@ -477,5 +477,77 @@ class TestGoErrors(TmuxUtilHarness):
self.assertIn("missing session name", result.stderr)
+# -----------------------------------------------------------------------------
+# find — Normal cases
+# -----------------------------------------------------------------------------
+
+class TestFindNormal(TmuxUtilHarness):
+
+ def test_find_matches_pane_running_named_command(self):
+ # Two sessions, one has a pane running vim; find should locate it.
+ self.set_sessions([
+ ("work", 1, ["101:zsh", "102:vim"], 950, 2, "/tmp/work"),
+ ("idle", 0, ["201:zsh"], 900, 1, "/tmp/idle"),
+ ])
+ result = self.run_script("find", "vim")
+ self.assertEqual(result.returncode, 0, msg=result.stderr)
+ self.assertIn("work:", result.stdout)
+ self.assertIn("vim", result.stdout)
+ # idle session pane shouldn't be in the output
+ self.assertNotIn("idle:", result.stdout)
+
+ def test_find_matches_multiple_panes(self):
+ self.set_sessions([
+ ("a", 1, ["101:zsh", "102:vim"], 950, 1, "/tmp/a"),
+ ("b", 1, ["201:vim"], 900, 1, "/tmp/b"),
+ ])
+ result = self.run_script("find", "vim")
+ self.assertEqual(result.returncode, 0)
+ self.assertIn("a:", result.stdout)
+ self.assertIn("b:", result.stdout)
+ # Two matches, two output lines
+ lines = [ln for ln in result.stdout.strip().split("\n") if ln]
+ self.assertEqual(len(lines), 2, msg=f"expected 2 matching lines, got {lines!r}")
+
+ def test_find_output_includes_session_window_pane_location(self):
+ self.set_sessions([
+ ("work", 1, ["101:zsh", "102:vim"], 950, 1, "/tmp/work"),
+ ])
+ result = self.run_script("find", "vim")
+ self.assertEqual(result.returncode, 0)
+ # Expected format: work:0.1 vim (window 0, pane index 1)
+ self.assertRegex(result.stdout, r"work:0\.1\s+vim")
+
+
+# -----------------------------------------------------------------------------
+# find — Boundary / Error cases
+# -----------------------------------------------------------------------------
+
+class TestFindBoundary(TmuxUtilHarness):
+
+ def test_find_no_matches_exits_nonzero(self):
+ self.set_sessions([
+ ("work", 1, ["101:zsh"], 950, 1, "/tmp/work"),
+ ])
+ result = self.run_script("find", "nothing-matches-this")
+ self.assertNotEqual(result.returncode, 0)
+ self.assertEqual(result.stdout.strip(), "")
+
+ def test_find_no_sessions_exits_nonzero(self):
+ self.set_sessions([])
+ result = self.run_script("find", "vim")
+ self.assertNotEqual(result.returncode, 0)
+
+ def test_find_no_pattern_exits_nonzero(self):
+ result = self.run_script("find")
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("missing pattern", result.stderr)
+
+ def test_find_empty_pattern_exits_nonzero(self):
+ result = self.run_script("find", "")
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("missing pattern", result.stderr)
+
+
if __name__ == "__main__":
unittest.main()