2026-10-03 16:40:17 +02:00
|
|
|
use crate::{Apply, CommandError, Selection, State};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct DeleteAll;
|
|
|
|
|
|
|
|
|
|
impl Apply for DeleteAll {
|
|
|
|
|
fn apply(self, state: &mut State) -> Result<(), CommandError> {
|
|
|
|
|
if state.files.is_empty() {
|
|
|
|
|
return Err(CommandError::NothingToDo);
|
|
|
|
|
}
|
|
|
|
|
state.files.clear();
|
|
|
|
|
state.order.0.clear();
|
|
|
|
|
*state.selection = Selection::Empty;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use crate::engine::command::fixture::Fixture;
|
|
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_delete_all() {
|
|
|
|
|
let mut fx = Fixture::default();
|
|
|
|
|
assert_eq!(
|
|
|
|
|
DeleteAll.apply(&mut fx.state()),
|
|
|
|
|
Err(CommandError::NothingToDo)
|
|
|
|
|
);
|
2026-10-07 17:58:17 +02:00
|
|
|
crate::New {
|
|
|
|
|
name: "a",
|
|
|
|
|
trackpoint: None,
|
|
|
|
|
}
|
|
|
|
|
.apply(&mut fx.state())
|
|
|
|
|
.unwrap();
|
|
|
|
|
crate::New {
|
|
|
|
|
name: "b",
|
|
|
|
|
trackpoint: None,
|
|
|
|
|
}
|
|
|
|
|
.apply(&mut fx.state())
|
|
|
|
|
.unwrap();
|
2026-10-03 16:40:17 +02:00
|
|
|
assert!(DeleteAll.apply(&mut fx.state()).is_ok());
|
|
|
|
|
assert!(fx.files.is_empty());
|
|
|
|
|
assert!(fx.order.0.is_empty());
|
|
|
|
|
assert!(matches!(fx.selection, Selection::Empty));
|
|
|
|
|
}
|
|
|
|
|
}
|