diff options
-rw-r--r-- | src/git/commit_diff.rs | 2 | ||||
-rw-r--r-- | src/git/file_status.rs | 24 | ||||
-rw-r--r-- | src/test_helpers/builders/file_status.rs | 77 |
3 files changed, 56 insertions, 47 deletions
diff --git a/src/git/commit_diff.rs b/src/git/commit_diff.rs index ad4619b..9edde24 100644 --- a/src/git/commit_diff.rs +++ b/src/git/commit_diff.rs @@ -109,7 +109,7 @@ mod tests { let diff = CommitDiffBuilder::new(CommitBuilder::new("0123456789ABCDEF").build()) .file_statuses(file_statuses) .build(); - assert_eq!(diff.file_statuses()[0].source_path.to_string_lossy(), "foo"); + assert_eq!(diff.file_statuses()[0].source_path().to_string_lossy(), "foo"); } #[test] diff --git a/src/git/file_status.rs b/src/git/file_status.rs index 82fbed4..372b14f 100644 --- a/src/git/file_status.rs +++ b/src/git/file_status.rs @@ -5,16 +5,16 @@ use crate::git::{Delta, FileMode, Status}; /// Represents a file change within a Git repository #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct FileStatus { - pub(crate) deltas: Vec<Delta>, - pub(crate) destination_is_binary: bool, - pub(crate) destination_mode: FileMode, - pub(crate) destination_path: PathBuf, - pub(crate) largest_new_line_number: u32, - pub(crate) largest_old_line_number: u32, - pub(crate) source_is_binary: bool, - pub(crate) source_mode: FileMode, - pub(crate) source_path: PathBuf, - pub(crate) status: Status, + deltas: Vec<Delta>, + destination_is_binary: bool, + destination_mode: FileMode, + destination_path: PathBuf, + largest_new_line_number: u32, + largest_old_line_number: u32, + source_is_binary: bool, + source_mode: FileMode, + source_path: PathBuf, + status: Status, } impl FileStatus { @@ -70,12 +70,14 @@ impl FileStatus { /// Get the destination file mode for this change. #[must_use] + #[allow(dead_code)] pub(crate) const fn destination_mode(&self) -> FileMode { self.destination_mode } /// Is the destination file a binary file. #[must_use] + #[allow(dead_code)] pub(crate) const fn destination_is_binary(&self) -> bool { self.destination_is_binary } @@ -88,12 +90,14 @@ impl FileStatus { /// Get the source file mode for this change. #[must_use] + #[allow(dead_code)] pub(crate) const fn source_mode(&self) -> FileMode { self.source_mode } /// Is the source file a binary file. #[must_use] + #[allow(dead_code)] pub(crate) const fn source_is_binary(&self) -> bool { self.source_is_binary } 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 } } |