Debian Codegraph @

src/features/mod.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
2
3 use craterust-analyzer cargo git-delta 0.19.2 crate/::clirust-analyzer cargo git-delta 0.19.2 cli/;
4 use craterust-analyzer cargo git-delta 0.19.2 crate/::git_configrust-analyzer cargo git-delta 0.19.2 git_config/::GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#;
5 use craterust-analyzer cargo git-delta 0.19.2 crate/::optionsrust-analyzer cargo git-delta 0.19.2 options/::option_valuerust-analyzer cargo git-delta 0.19.2 options/option_value/::ProvenancedOptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/ProvenancedOptionValue#;
6 use ProvenancedOptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/ProvenancedOptionValue#::*;
7
8 /// A custom feature is a named set of command line (option, value) pairs, supplied in a git config
9 /// file. I.e. it might look like
10 ///
11 /// [delta "decorations"]
12 /// commit-decoration-style = bold box ul
13 /// file-style = bold 19 ul
14 /// file-decoration-style = none
15 ///
16 /// A builtin feature is a named set of command line (option, value) pairs that is built-in to
17 /// delta. The valueof a builtin feature is a function. This function is passed the current set of
18 /// all command-line option-value pairs, and GitConfig, and returns either a GitConfigValue, or a
19 /// DefaultValue. (It may use the set of all option-value pairs when computing its default).
20 pub type BuiltinFeaturerust-analyzer cargo git-delta 0.19.2 features/BuiltinFeature# = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, OptionValueFunctionrust-analyzer cargo git-delta 0.19.2 features/OptionValueFunction#>;
21
22 type OptionValueFunctionrust-analyzer cargo git-delta 0.19.2 features/OptionValueFunction# = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#, &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#>) -> ProvenancedOptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/ProvenancedOptionValue#>;
23
24 // Construct a 2-level hash map: (feature name) -> (option name) -> (value function). A value
25 // function is a function that takes an Opt struct, and a git Config struct, and returns the value
26 // for the option.
27 pub fn make_builtin_featuresrust-analyzer cargo git-delta 0.19.2 features/make_builtin_features().() -> HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, BuiltinFeaturerust-analyzer cargo git-delta 0.19.2 features/BuiltinFeature#> {
28 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
29 (
30 "color-only".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
31 color_onlyrust-analyzer cargo git-delta 0.19.2 features/color_only/::make_featurerust-analyzer cargo git-delta 0.19.2 features/color_only/make_feature().().into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
32 ),
33 (
34 "diff-highlight".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
35 diff_highlightrust-analyzer cargo git-delta 0.19.2 features/diff_highlight/::make_featurerust-analyzer cargo git-delta 0.19.2 features/diff_highlight/make_feature().().into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
36 ),
37 (
38 "diff-so-fancy".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
39 diff_so_fancyrust-analyzer cargo git-delta 0.19.2 features/diff_so_fancy/::make_featurerust-analyzer cargo git-delta 0.19.2 features/diff_so_fancy/make_feature().().into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
40 ),
41 (
42 "hyperlinks".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
43 hyperlinksrust-analyzer cargo git-delta 0.19.2 features/hyperlinks/::make_featurerust-analyzer cargo git-delta 0.19.2 features/hyperlinks/make_feature().().into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
44 ),
45 (
46 "line-numbers".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
47 line_numbersrust-analyzer cargo git-delta 0.19.2 features/line_numbers/::make_featurerust-analyzer cargo git-delta 0.19.2 features/line_numbers/make_feature().().into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
48 ),
49 (
50 "navigate".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
51 navigaterust-analyzer cargo git-delta 0.19.2 features/navigate/::make_featurerust-analyzer cargo git-delta 0.19.2 features/navigate/make_feature().().into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
52 ),
53 ("raw".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), rawrust-analyzer cargo git-delta 0.19.2 features/raw/::make_featurerust-analyzer cargo git-delta 0.19.2 features/raw/make_feature().().into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()),
54 (
55 "side-by-side".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
56 side_by_siderust-analyzer cargo git-delta 0.19.2 features/side_by_side/::make_featurerust-analyzer cargo git-delta 0.19.2 features/side_by_side/make_feature().().into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
57 ),
58 ]
59 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
60 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
61 }
62
63 /// The macro permits the values of a builtin feature to be specified as either (a) a git config
64 /// entry or (b) a value, which may be computed from the other command line options (cli::Opt).
65 macro_rules! builtin_featurerust-analyzer cargo git-delta 0.19.2 features/builtin_feature! {
66 ([$( ($option_name:expr, $type:ty, $git_config_key:expr, $opt:ident => $value:expr) ),*]) => {
67 vec![$(
68 (
69 $option_name.to_string(),
70 Box::new(move |$opt: &$crate::cli::Opt, git_config: &Option<$crate::git_config::GitConfig>| {
71 match (git_config, $git_config_key) {
72 (Some(git_config), Some(git_config_key)) => git_config.get::<$type>(git_config_key).map(|value| $crate::features::GitConfigValue(value.into())),
73 _ => None,
74 }
75 .unwrap_or_else(|| $crate::features::DefaultValue($value.into()))
76 }) as OptionValueFunction
77 )
78 ),*]
79 }
80 }
81
82 pub mod color_onlyrust-analyzer cargo git-delta 0.19.2 features/color_only/;
83 pub mod diff_highlightrust-analyzer cargo git-delta 0.19.2 features/diff_highlight/;
84 pub mod diff_so_fancyrust-analyzer cargo git-delta 0.19.2 features/diff_so_fancy/;
85 pub mod hyperlinksrust-analyzer cargo git-delta 0.19.2 features/hyperlinks/;
86 pub mod line_numbersrust-analyzer cargo git-delta 0.19.2 features/line_numbers/;
87 pub mod navigaterust-analyzer cargo git-delta 0.19.2 features/navigate/;
88 pub mod rawrust-analyzer cargo git-delta 0.19.2 features/raw/;
89 pub mod side_by_siderust-analyzer cargo git-delta 0.19.2 features/side_by_side/;
90
91 #[cfg(test)]
92 pub mod testsrust-analyzer cargo git-delta 0.19.2 features/tests/ {
93 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#;
94 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().;
95
96 use craterust-analyzer cargo git-delta 0.19.2 crate/::clirust-analyzer cargo git-delta 0.19.2 cli/;
97 use craterust-analyzer cargo git-delta 0.19.2 crate/::envrust-analyzer cargo git-delta 0.19.2 env/::DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#;
98 use craterust-analyzer cargo git-delta 0.19.2 crate/::featuresrust-analyzer cargo git-delta 0.19.2 features/::make_builtin_featuresrust-analyzer cargo git-delta 0.19.2 features/make_builtin_features().;
99 use craterust-analyzer cargo git-delta 0.19.2 crate/::testsrust-analyzer cargo git-delta 0.19.2 tests/::integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().;
100
101 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
102 fn test_builtin_features_have_flags_and_these_set_featuresrust-analyzer cargo git-delta 0.19.2 features/tests/test_builtin_features_have_flags_and_these_set_features().() {
103 let builtin_features = make_builtin_featuresrust-analyzer cargo git-delta 0.19.2 features/make_builtin_features().();
104 let mut args = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["delta".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()];
105 args.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(builtin_features.keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("--{s}")));
106 let opt = clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#::from_iter_and_git_configrust-analyzer cargo git-delta 0.19.2 cli/impl#[Opt]from_iter_and_git_config().(&DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::defaultrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv][Default]default().(), args, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
107 let features: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<&str> = opt
108 .featuresrust-analyzer cargo git-delta 0.19.2 cli/Opt#features.
109 .as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
110 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("")
111 .split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().()
112 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
113 for feature in builtin_features.keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().() {
114 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(features.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(feature.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()))
115 }
116 }
117
118 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
119 fn test_builtin_feature_from_gitconfigrust-analyzer cargo git-delta 0.19.2 features/tests/test_builtin_feature_from_gitconfig().() {
120 let git_config_contents = b"
121 [delta]
122 navigate = true
123 ";
124 let git_config_path = "delta__test_builtin_feature_from_gitconfig.gitconfig";
125
126 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
127 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
128 &[],
129 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
130 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path)
131 )
132 .featuresrust-analyzer cargo git-delta 0.19.2 cli/Opt#features.
133 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
134 "navigate"
135 );
136
137 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
138 }
139
140 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
141 fn test_features_on_command_line_replace_features_in_gitconfigrust-analyzer cargo git-delta 0.19.2 features/tests/test_features_on_command_line_replace_features_in_gitconfig().() {
142 let git_config_contents = b"
143 [delta]
144 features = my-feature
145 ";
146 let git_config_path =
147 "delta__test_features_on_command_line_replace_features_in_gitconfig.gitconfig";
148
149 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
150 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
151 &["--features", "navigate raw"],
152 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
153 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
154 )
155 .featuresrust-analyzer cargo git-delta 0.19.2 cli/Opt#features.
156 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
157 "navigate raw"
158 );
159 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
160 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
161 &["--navigate", "--features", "raw"],
162 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
163 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
164 )
165 .featuresrust-analyzer cargo git-delta 0.19.2 cli/Opt#features.
166 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
167 "navigate raw"
168 );
169
170 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
171 }
172
173 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
174 fn test_feature_flag_on_command_line_does_not_replace_features_in_gitconfigrust-analyzer cargo git-delta 0.19.2 features/tests/test_feature_flag_on_command_line_does_not_replace_features_in_gitconfig().() {
175 let git_config_contents = b"
176 [delta]
177 features = my-feature
178 ";
179 let git_config_path =
180 "delta__test_feature_flag_on_command_line_does_not_replace_features_in_gitconfig.gitconfig";
181 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
182 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
183 &["--navigate", "--raw"],
184 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
185 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
186 )
187 .featuresrust-analyzer cargo git-delta 0.19.2 cli/Opt#features.
188 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
189 "my-feature navigate raw"
190 );
191
192 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
193 }
194
195 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
196 fn test_recursive_feature_gathering_1rust-analyzer cargo git-delta 0.19.2 features/tests/test_recursive_feature_gathering_1().() {
197 let git_config_contents = b"
198 [delta]
199 features = h g
200
201 [delta \"a\"]
202 features = c b
203 diff-highlight = true
204
205 [delta \"d\"]
206 features = f e
207 diff-so-fancy = true
208 ";
209 let git_config_path = "delta__test_feature_collection.gitconfig";
210
211 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
212 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
213 &["--raw", "--features", "d a"],
214 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
215 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
216 )
217 .featuresrust-analyzer cargo git-delta 0.19.2 cli/Opt#features.
218 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
219 "raw diff-so-fancy f e d diff-highlight c b a"
220 );
221
222 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
223 }
224
225 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
226 fn test_recursive_feature_gathering_2rust-analyzer cargo git-delta 0.19.2 features/tests/test_recursive_feature_gathering_2().() {
227 let git_config_contents = b"
228 [delta]
229 features = feature-1
230
231 [delta \"feature-1\"]
232 features = feature-2 feature-3
233
234 [delta \"feature-2\"]
235 features = feature-4
236
237 [delta \"feature-4\"]
238 minus-style = blue
239 ";
240 let git_config_path = "delta__test_recursive_features.gitconfig";
241 let opt = make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
242 &["delta"],
243 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
244 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
245 );
246 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
247 opt.featuresrust-analyzer cargo git-delta 0.19.2 cli/Opt#features..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
248 "feature-4 feature-2 feature-3 feature-1"
249 );
250
251 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
252 }
253
254 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
255 fn test_main_sectionrust-analyzer cargo git-delta 0.19.2 features/tests/test_main_section().() {
256 let git_config_contents = b"
257 [delta]
258 minus-style = blue
259 ";
260 let git_config_path = "delta__test_main_section.gitconfig";
261
262 // First check that it doesn't default to blue, because that's going to be used to signal
263 // that gitconfig has set the style.
264 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(
265 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(&[], Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
266 "blue"
267 );
268
269 // Check that --minus-style is honored as we expect.
270 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
271 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(&["--minus-style", "red"], Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
272 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
273 "red"
274 );
275
276 // Check that gitconfig does not override a command line argument
277 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
278 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
279 &["--minus-style", "red"],
280 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
281 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
282 )
283 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
284 "red"
285 );
286
287 // Finally, check that gitconfig is honored when not overridden by a command line argument.
288 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
289 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
290 &[],
291 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
292 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path)
293 )
294 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
295 "blue"
296 );
297
298 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
299 }
300
301 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
302 fn test_featurerust-analyzer cargo git-delta 0.19.2 features/tests/test_feature().() {
303 let git_config_contents = b"
304 [delta]
305
306
307 [delta \"my-feature\"]
308 minus-style = green
309 ";
310 let git_config_path = "delta__test_feature.gitconfig";
311
312 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
313 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
314 &["--features", "my-feature"],
315 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
316 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
317 )
318 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
319 "green"
320 );
321 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
322 }
323
324 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
325 fn test_main_section_overrides_featurerust-analyzer cargo git-delta 0.19.2 features/tests/test_main_section_overrides_feature().() {
326 let git_config_contents = b"
327 [delta]
328 minus-style = blue
329
330 [delta \"my-feature-1\"]
331 minus-style = green
332 ";
333 let git_config_path = "delta__test_main_section_overrides_feature.gitconfig";
334
335 // Without --features the main section takes effect
336 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
337 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
338 &[],
339 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
340 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path)
341 )
342 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
343 "blue"
344 );
345
346 // Event with --features the main section overrides the feature.
347 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
348 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
349 &["--features", "my-feature-1"],
350 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
351 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
352 )
353 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
354 "blue"
355 );
356 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
357 }
358
359 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
360 fn test_multiple_featuresrust-analyzer cargo git-delta 0.19.2 features/tests/test_multiple_features().() {
361 let git_config_contents = b"
362 [delta]
363
364
365 [delta \"my-feature-1\"]
366 minus-style = green
367
368 [delta \"my-feature-2\"]
369 minus-style = yellow
370 ";
371 let git_config_path = "delta__test_multiple_features.gitconfig";
372
373 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
374 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
375 &["--features", "my-feature-1 my-feature-2"],
376 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
377 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
378 )
379 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
380 "yellow"
381 );
382
383 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
384 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
385 &["--features", "my-feature-2 my-feature-1"],
386 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
387 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
388 )
389 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
390 "green"
391 );
392
393 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
394 }
395
396 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
397 fn test_invalid_featuresrust-analyzer cargo git-delta 0.19.2 features/tests/test_invalid_features().() {
398 let git_config_contents = b"
399 [delta \"my-feature-1\"]
400 minus-style = green
401
402 [delta \"my-feature-2\"]
403 minus-style = yellow
404 ";
405 let git_config_path = "delta__test_invalid_features.gitconfig";
406
407 let default = make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(&[], Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.;
408 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(default, "green");
409 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(default, "yellow");
410
411 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
412 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
413 &["--features", "my-feature-1"],
414 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
415 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
416 )
417 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
418 "green"
419 );
420
421 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
422 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
423 &["--features", "my-feature-x"],
424 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
425 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
426 )
427 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
428 default
429 );
430
431 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
432 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
433 &["--features", "my-feature-1 my-feature-x"],
434 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
435 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
436 )
437 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
438 "green"
439 );
440
441 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
442 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
443 &["--features", "my-feature-x my-feature-2 my-feature-x"],
444 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
445 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
446 )
447 .minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style.,
448 "yellow"
449 );
450
451 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
452 }
453
454 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
455 fn test_whitespace_error_stylerust-analyzer cargo git-delta 0.19.2 features/tests/test_whitespace_error_style().() {
456 let git_config_contents = b"
457 [color \"diff\"]
458 whitespace = yellow dim ul magenta
459 ";
460 let git_config_path = "delta__test_whitespace_error_style.gitconfig";
461
462 // Git config disabled: hard-coded delta default wins
463 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
464 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(&[], Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).whitespace_error_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#whitespace_error_style.,
465 "magenta reverse"
466 );
467
468 // Unspecified by user: color.diff.whitespace wins
469 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
470 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
471 &[],
472 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
473 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path)
474 )
475 .whitespace_error_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#whitespace_error_style.,
476 "yellow dim ul magenta"
477 );
478
479 // Command line argument wins
480 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
481 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
482 &["--whitespace-error-style", "red reverse"],
483 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
484 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path)
485 )
486 .whitespace_error_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#whitespace_error_style.,
487 "red reverse"
488 );
489
490 let git_config_contents = b"
491 [color \"diff\"]
492 whitespace = yellow dim ul magenta
493
494 [delta]
495 whitespace-error-style = blue reverse
496
497 [delta \"my-whitespace-error-style-feature\"]
498 whitespace-error-style = green reverse
499 ";
500
501 // Command line argument wins
502 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
503 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
504 &["--whitespace-error-style", "red reverse"],
505 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
506 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path)
507 )
508 .whitespace_error_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#whitespace_error_style.,
509 "red reverse"
510 );
511
512 // No command line argument or features; main [delta] section wins
513 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
514 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
515 &[],
516 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
517 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path)
518 )
519 .whitespace_error_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#whitespace_error_style.,
520 "blue reverse"
521 );
522
523 // Feature contains key, but main [delta] section still wins.
524 // This is equivalent to
525 //
526 // [delta]
527 // features = my-whitespace-error-style-feature
528 // whitespace-error-style = blue reverse
529 //
530 // In this situation, the value from the feature is overridden.
531 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
532 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
533 &["--features", "my-whitespace-error-style-feature"],
534 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
535 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path)
536 )
537 .whitespace_error_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#whitespace_error_style.,
538 "blue reverse"
539 );
540
541 remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(git_config_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
542 }
543 }