mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-17 08:42:28 +00:00
progress
This commit is contained in:
1 parent
41b9116c6a
commit
97d597e139
181 files changed
+1970
-2643
No files matched your search
@@ -0,0 +1,48 @@
|
||||
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)
|
||||
);
|
||||
crate::New {
|
||||
name: "a",
|
||||
trackpoint: None,
|
||||
}
|
||||
.apply(&mut fx.state())
|
||||
.unwrap();
|
||||
crate::New {
|
||||
name: "b",
|
||||
trackpoint: None,
|
||||
}
|
||||
.apply(&mut fx.state())
|
||||
.unwrap();
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user