Ensure item-closing actions do not panic when no items are present (#31845)

This PR adds a comprehensive test that ensures that no item-closing
action will panic when no items are present. A test already existed
(`test_remove_active_empty `) that ensured `CloseActiveItem` didn't
panic, but the new test covers:

- `CloseActiveItem`
- `CloseInactiveItems`
- `CloseAllItems`
- `CloseCleanItems`
- `CloseItemsToTheRight`
- `CloseItemsToTheLeft`

I plan to do a bit more clean up in `pane.rs` and this feels like a good
thing to add before that.

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2025-05-31 23:31:38 -04:00 committed by GitHub
parent 24e4446cd3
commit f13f2dfb70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 146 additions and 117 deletions

View file

@ -7761,7 +7761,6 @@ mod tests {
// Close the active item
pane.update_in(cx, |pane, window, cx| {
pane.close_active_item(&Default::default(), window, cx)
.unwrap()
})
.await
.unwrap();
@ -9075,18 +9074,16 @@ mod tests {
buffer.project_items[0].update(cx, |pi, _| pi.is_dirty = true)
});
let close_multi_buffer_task = pane
.update_in(cx, |pane, window, cx| {
pane.close_active_item(
&CloseActiveItem {
save_intent: Some(SaveIntent::Close),
close_pinned: false,
},
window,
cx,
)
})
.expect("should have the multi buffer to close");
let close_multi_buffer_task = pane.update_in(cx, |pane, window, cx| {
pane.close_active_item(
&CloseActiveItem {
save_intent: Some(SaveIntent::Close),
close_pinned: false,
},
window,
cx,
)
});
cx.background_executor.run_until_parked();
assert!(
cx.has_pending_prompt(),
@ -9184,18 +9181,16 @@ mod tests {
"Should select the multi buffer in the pane"
);
});
let _close_multi_buffer_task = pane
.update_in(cx, |pane, window, cx| {
pane.close_active_item(
&CloseActiveItem {
save_intent: None,
close_pinned: false,
},
window,
cx,
)
})
.expect("should have active multi buffer to close");
let _close_multi_buffer_task = pane.update_in(cx, |pane, window, cx| {
pane.close_active_item(
&CloseActiveItem {
save_intent: None,
close_pinned: false,
},
window,
cx,
)
});
cx.background_executor.run_until_parked();
assert!(
cx.has_pending_prompt(),
@ -9282,18 +9277,16 @@ mod tests {
"Should select the multi buffer in the pane"
);
});
let close_multi_buffer_task = pane
.update_in(cx, |pane, window, cx| {
pane.close_active_item(
&CloseActiveItem {
save_intent: None,
close_pinned: false,
},
window,
cx,
)
})
.expect("should have active multi buffer to close");
let close_multi_buffer_task = pane.update_in(cx, |pane, window, cx| {
pane.close_active_item(
&CloseActiveItem {
save_intent: None,
close_pinned: false,
},
window,
cx,
)
});
cx.background_executor.run_until_parked();
assert!(
!cx.has_pending_prompt(),