diff options
Diffstat (limited to 'src/test_helpers/builders/file_status.rs')
-rw-r--r-- | src/test_helpers/builders/file_status.rs | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/src/test_helpers/builders/file_status.rs b/src/test_helpers/builders/file_status.rs index 35cd434..25cb1f8 100644 --- a/src/test_helpers/builders/file_status.rs +++ b/src/test_helpers/builders/file_status.rs @@ -5,7 +5,14 @@ use crate::git::{Delta, FileMode, FileStatus, Status}; /// Builder for creating a new reference. #[derive(Debug)] pub(crate) struct FileStatusBuilder { - file_status: FileStatus, + deltas: Vec<Delta>, + destination_is_binary: bool, + destination_mode: FileMode, + destination_path: PathBuf, + source_is_binary: bool, + source_mode: FileMode, + source_path: PathBuf, + status: Status, } impl FileStatusBuilder { @@ -13,88 +20,73 @@ impl FileStatusBuilder { #[must_use] pub(crate) fn new() -> Self { Self { - file_status: FileStatus { - deltas: vec![], - destination_is_binary: false, - destination_mode: FileMode::Normal, - destination_path: PathBuf::default(), - largest_new_line_number: 0, - largest_old_line_number: 0, - source_is_binary: false, - source_mode: FileMode::Normal, - source_path: PathBuf::default(), - status: Status::Added, - }, + deltas: vec![], + destination_is_binary: false, + destination_mode: FileMode::Normal, + destination_path: PathBuf::default(), + source_is_binary: false, + source_mode: FileMode::Normal, + source_path: PathBuf::default(), + status: Status::Added, } } /// Push a `Delta`. #[must_use] pub(crate) fn push_delta(mut self, delta: Delta) -> Self { - self.file_status.add_delta(delta); + self.deltas.push(delta); self } /// Set if the destination is binary. #[must_use] + #[allow(dead_code)] pub(crate) const fn destination_is_binary(mut self, binary: bool) -> Self { - self.file_status.destination_is_binary = binary; + self.destination_is_binary = binary; self } /// Set the destination file mode. #[must_use] pub(crate) const fn destination_mode(mut self, mode: FileMode) -> Self { - self.file_status.destination_mode = mode; + self.destination_mode = mode; self } /// Set the destination file path. #[must_use] pub(crate) fn destination_path<F: AsRef<Path>>(mut self, path: F) -> Self { - self.file_status.destination_path = PathBuf::from(path.as_ref()); - self - } - - /// Set the largest new line number. - #[must_use] - pub(crate) const fn largest_new_line_number(mut self, largest_new_line_number: u32) -> Self { - self.file_status.largest_new_line_number = largest_new_line_number; - self - } - - /// Set the largest old line number. - #[must_use] - pub(crate) const fn largest_old_line_number(mut self, largest_old_line_number: u32) -> Self { - self.file_status.largest_old_line_number = largest_old_line_number; + self.destination_path = PathBuf::from(path.as_ref()); self } /// Set if the source is binary. #[must_use] + #[allow(dead_code)] pub(crate) const fn source_is_binary(mut self, binary: bool) -> Self { - self.file_status.source_is_binary = binary; + self.source_is_binary = binary; self } /// Set if the source file mode. #[must_use] + #[allow(dead_code)] pub(crate) const fn source_mode(mut self, mode: FileMode) -> Self { - self.file_status.source_mode = mode; + self.source_mode = mode; self } /// Set the destination file path. #[must_use] pub(crate) fn source_path<F: AsRef<Path>>(mut self, path: F) -> Self { - self.file_status.source_path = PathBuf::from(path.as_ref()); + self.source_path = PathBuf::from(path.as_ref()); self } /// Set the status. #[must_use] pub(crate) const fn status(mut self, status: Status) -> Self { - self.file_status.status = status; + self.status = status; self } @@ -102,6 +94,19 @@ impl FileStatusBuilder { #[must_use] #[allow(clippy::missing_const_for_fn)] pub(crate) fn build(self) -> FileStatus { - self.file_status + let mut file_status = FileStatus::new( + self.source_path, + self.source_mode, + self.source_is_binary, + self.destination_path, + self.destination_mode, + self.destination_is_binary, + self.status, + ); + for delta in self.deltas { + file_status.add_delta(delta); + } + + file_status } } |