1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/// Options for loading a commit with diff
#[derive(Copy, Clone, Debug)]
#[allow(clippy::struct_excessive_bools)]
pub struct CommitDiffLoaderOptions {
	pub(crate) context_lines: u32,
	pub(crate) copies: bool,
	pub(crate) ignore_whitespace: bool,
	pub(crate) ignore_whitespace_change: bool,
	pub(crate) interhunk_context: u32,
	pub(crate) rename_limit: u32,
	pub(crate) renames: bool,
}

impl CommitDiffLoaderOptions {
	/// Create a new default instance.
	#[inline]
	#[must_use]
	pub const fn new() -> Self {
		Self {
			context_lines: 0,
			copies: false,
			ignore_whitespace: false,
			ignore_whitespace_change: false,
			interhunk_context: 0,
			rename_limit: 0,
			renames: false,
		}
	}

	/// Set the number of context lines.
	#[inline]
	#[must_use]
	pub const fn context_lines(mut self, context_lines: u32) -> Self {
		self.context_lines = context_lines;
		self
	}

	/// Set the number of interhunk lines.
	#[inline]
	#[must_use]
	pub const fn interhunk_context(mut self, interhunk_context: u32) -> Self {
		self.interhunk_context = interhunk_context;
		self
	}

	/// Set if to detect copies or not.
	#[inline]
	#[must_use]
	pub const fn copies(mut self, copies: bool) -> Self {
		self.copies = copies;
		self
	}

	/// Set if to ignore whitespace.
	#[inline]
	#[must_use]
	pub const fn ignore_whitespace(mut self, ignore_whitespace: bool) -> Self {
		self.ignore_whitespace = ignore_whitespace;
		self
	}

	/// Set if to ignore changes in whitespace.
	#[inline]
	#[must_use]
	pub const fn ignore_whitespace_change(mut self, ignore_whitespace_change: bool) -> Self {
		self.ignore_whitespace_change = ignore_whitespace_change;
		self
	}

	/// Set if to detect renames, as well as the file rename limit.
	#[inline]
	#[must_use]
	pub const fn renames(mut self, renames: bool, limit: u32) -> Self {
		self.rename_limit = limit;
		self.renames = renames;
		self
	}
}

#[cfg(test)]
mod tests {
	use super::*;

	#[test]
	fn context_lines() {
		assert_eq!(CommitDiffLoaderOptions::new().context_lines(42).context_lines, 42);
	}

	#[test]
	fn interhunk_lines() {
		assert_eq!(
			CommitDiffLoaderOptions::new().interhunk_context(42).interhunk_context,
			42
		);
	}

	#[test]
	fn copies() {
		assert!(CommitDiffLoaderOptions::new().copies(true).copies);
	}

	#[test]
	fn ignore_whitespace() {
		assert!(CommitDiffLoaderOptions::new().ignore_whitespace(true).ignore_whitespace);
	}

	#[test]
	fn ignore_whitespace_change() {
		assert!(
			CommitDiffLoaderOptions::new()
				.ignore_whitespace_change(true)
				.ignore_whitespace_change
		);
	}

	#[test]
	fn renames() {
		let load_commit_diff_options = CommitDiffLoaderOptions::new().renames(true, 42);
		assert!(load_commit_diff_options.renames);
		assert_eq!(load_commit_diff_options.rename_limit, 42);
	}
}