From 8c10547325a088ba5d0ff4ca44dce04cd3ce94a1 Mon Sep 17 00:00:00 2001 From: Jerry Kingsbury Date: Fri, 2 May 2025 17:19:44 -0500 Subject: [PATCH] test(workspace): remove a non existent window Created a test for removing a window that doesn't exist. The test creates a container with a window and then attempts to remove a window that doesn't exist. The test will check the result to ensure that the result returned an error and that we still have the expected number of windows. --- komorebi/src/workspace.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 597b305d..fe97a111 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -1939,6 +1939,33 @@ mod tests { assert_eq!(container.windows().len(), 3); } + #[test] + fn test_remove_non_existent_window() { + let mut workspace = Workspace::default(); + + { + // Add a container with one window + let mut container = Container::default(); + container.windows_mut().push_back(Window::from(1)); + workspace.add_container_to_back(container); + } + + // Attempt to remove a non-existent window + let result = workspace.remove_window(2); + + // Should return an error + assert!( + result.is_err(), + "Expected an error when removing a non-existent window" + ); + + // Get focused container. Should be the index of the last container added + let container = workspace.focused_container_mut().unwrap(); + + // Should still have 1 window + assert_eq!(container.windows().len(), 1); + } + #[test] fn test_remove_focused_container() { let mut workspace = Workspace::default();