git/testutil/
build_file_status.rs1use std::path::{Path, PathBuf};
2
3use crate::{Delta, FileMode, FileStatus, Status};
4
5#[derive(Debug)]
7pub struct FileStatusBuilder {
8 file_status: FileStatus,
9}
10
11impl FileStatusBuilder {
12 #[inline]
14 #[must_use]
15 pub fn new() -> Self {
16 Self {
17 file_status: FileStatus {
18 deltas: vec![],
19 destination_is_binary: false,
20 destination_mode: FileMode::Normal,
21 destination_path: PathBuf::default(),
22 largest_new_line_number: 0,
23 largest_old_line_number: 0,
24 source_is_binary: false,
25 source_mode: FileMode::Normal,
26 source_path: PathBuf::default(),
27 status: Status::Added,
28 },
29 }
30 }
31
32 #[inline]
34 #[must_use]
35 pub fn push_delta(mut self, delta: Delta) -> Self {
36 self.file_status.add_delta(delta);
37 self
38 }
39
40 #[inline]
42 #[must_use]
43 pub const fn destination_is_binary(mut self, binary: bool) -> Self {
44 self.file_status.destination_is_binary = binary;
45 self
46 }
47
48 #[inline]
50 #[must_use]
51 pub const fn destination_mode(mut self, mode: FileMode) -> Self {
52 self.file_status.destination_mode = mode;
53 self
54 }
55
56 #[inline]
58 #[must_use]
59 pub fn destination_path<F: AsRef<Path>>(mut self, path: F) -> Self {
60 self.file_status.destination_path = PathBuf::from(path.as_ref());
61 self
62 }
63
64 #[inline]
66 #[must_use]
67 pub const fn largest_new_line_number(mut self, largest_new_line_number: u32) -> Self {
68 self.file_status.largest_new_line_number = largest_new_line_number;
69 self
70 }
71
72 #[inline]
74 #[must_use]
75 pub const fn largest_old_line_number(mut self, largest_old_line_number: u32) -> Self {
76 self.file_status.largest_old_line_number = largest_old_line_number;
77 self
78 }
79
80 #[inline]
82 #[must_use]
83 pub const fn source_is_binary(mut self, binary: bool) -> Self {
84 self.file_status.source_is_binary = binary;
85 self
86 }
87
88 #[inline]
90 #[must_use]
91 pub const fn source_mode(mut self, mode: FileMode) -> Self {
92 self.file_status.source_mode = mode;
93 self
94 }
95
96 #[inline]
98 #[must_use]
99 pub fn source_path<F: AsRef<Path>>(mut self, path: F) -> Self {
100 self.file_status.source_path = PathBuf::from(path.as_ref());
101 self
102 }
103
104 #[inline]
106 #[must_use]
107 pub const fn status(mut self, status: Status) -> Self {
108 self.file_status.status = status;
109 self
110 }
111
112 #[inline]
114 #[must_use]
115 #[allow(clippy::missing_const_for_fn)]
116 pub fn build(self) -> FileStatus {
117 self.file_status
118 }
119}