diff options
| -rw-r--r-- | src/actions/create.rs | 21 | ||||
| -rw-r--r-- | src/actions/update.rs | 4 | ||||
| -rw-r--r-- | src/filesystem.rs | 21 |
3 files changed, 29 insertions, 17 deletions
diff --git a/src/actions/create.rs b/src/actions/create.rs index 2b664b3..c89c3c9 100644 --- a/src/actions/create.rs +++ b/src/actions/create.rs @@ -26,7 +26,14 @@ pub fn create(command_options: ActionOptions, fs: &impl Fs, timestamp: u64) -> R mod tests { use std::path::Path; - use crate::{actions::ActionOptions, diff::ContentChange, filesystem::mock::{EntryMock, FsMock, FsState}, history::{FileChange, FileChangeVariant, FileHistory, RepositoryChange, RepositoryHistory}}; + use crate::{ + actions::ActionOptions, + diff::ContentChange, + filesystem::mock::{EntryMock, FsMock, FsState}, + history::{ + FileChange, FileChangeVariant, FileHistory, RepositoryChange, RepositoryHistory, + }, + }; use super::create; @@ -37,7 +44,7 @@ mod tests { let options = ActionOptions::from_path("."); let expected_index = RepositoryHistory::default().encode().unwrap(); - + create(options, &fs_mock, now).expect("Action failed."); fs_mock.assert_match(FsState::new(vec![ @@ -76,19 +83,19 @@ mod tests { history.encode().unwrap() }; - fs_mock.set_state(FsState::new(vec![ - EntryMock::file("./test", &vec![1, 2, 3]) - ])); + fs_mock.set_state(FsState::new(vec![EntryMock::file( + "./test", + &vec![1, 2, 3], + )])); create(options, &fs_mock, now).expect("Action failed."); fs_mock.assert_match(FsState::new(vec![ EntryMock::file("./test", &vec![1, 2, 3]), - EntryMock::dir("./.ka"), EntryMock::file("./.ka/index", &expected_index), EntryMock::dir("./.ka/files"), EntryMock::file("./.ka/files/test", &expected_file_history), ])) } -} \ No newline at end of file +} diff --git a/src/actions/update.rs b/src/actions/update.rs index 05379c1..081be72 100644 --- a/src/actions/update.rs +++ b/src/actions/update.rs @@ -97,13 +97,13 @@ fn get_new_history_for_file<FS: Fs>( let changes = ContentChange::diff(&old_content, &new_content); - if !changes.is_empty() { + if !changes.is_empty() { let mut new_history = file_history; new_history.add_change(FileChange { change_index: cursor + 1, variant: FileChangeVariant::Updated(changes), }); - + Ok(Some((history_file, new_history))) } else { Ok(None) diff --git a/src/filesystem.rs b/src/filesystem.rs index 9ba2bf2..37b4667 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -500,7 +500,10 @@ pub mod mock { fn create_directory(&mut self, path: &Path) -> bool { if let Some(parent) = path.parent() { - if !parent.as_os_str().is_empty() && !self.is_directory(parent) && !self.create_directory(parent) { + if !parent.as_os_str().is_empty() + && !self.is_directory(parent) + && !self.create_directory(parent) + { return false; } } @@ -639,14 +642,14 @@ pub mod mock { fn deletion() { let mock = FsMock::new(); - mock.create_file(Path::new("./folder/file_to_delete")).unwrap(); + mock.create_file(Path::new("./folder/file_to_delete")) + .unwrap(); mock.create_directory(Path::new("./dir_to_delete")).unwrap(); - mock.delete_file(Path::new("./folder/file_to_delete")).unwrap(); + mock.delete_file(Path::new("./folder/file_to_delete")) + .unwrap(); mock.delete_directory(Path::new("./dir_to_delete")).unwrap(); - mock.assert_match(FsState::new(vec![ - EntryMock::dir("./folder"), - ])) + mock.assert_match(FsState::new(vec![EntryMock::dir("./folder")])) } #[test] @@ -654,8 +657,10 @@ pub mod mock { let mock = FsMock::new(); mock.create_file(Path::new("./folder/file")).unwrap(); - mock.create_file(Path::new("./folder/another_file")).unwrap(); - mock.create_file(Path::new("./folder/nested/file_too_deep")).unwrap(); + mock.create_file(Path::new("./folder/another_file")) + .unwrap(); + mock.create_file(Path::new("./folder/nested/file_too_deep")) + .unwrap(); let entries = mock.read_directory(Path::new("./folder")).unwrap(); |
