Debian Codegraph @

src/options/get.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/::featuresrust-analyzer cargo git-delta 0.19.2 features/;
5 use craterust-analyzer cargo git-delta 0.19.2 crate/::git_configrust-analyzer cargo git-delta 0.19.2 git_config/::{selfrust-analyzer cargo git-delta 0.19.2 git_config/, GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet#};
6 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/::{OptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/OptionValue#, ProvenancedOptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/ProvenancedOptionValue#};
7 use ProvenancedOptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/ProvenancedOptionValue#::*;
8
9 // Look up a value of type `T` associated with `option name`. The search rules are:
10 //
11 // 1. If there is a value associated with `option_name` in the main [delta] git config
12 // section, then stop searching and return that value (steps 2 and 3 are not executed at all).
13 //
14 // 2. For each feature in the ordered list of enabled features:
15 //
16 // 2.1 Look-up the value, treating `feature` as a custom feature.
17 // I.e., if there is a value associated with `option_name` in a git config section
18 // named [delta "`feature`"] then stop searching and return that value.
19 //
20 // 2.2 Look-up the value, treating `feature` as a builtin feature.
21 // I.e., if there is a value (not a default value) associated with `option_name` in a
22 // builtin feature named `feature`, then stop searching and return that value.
23 // Otherwise, record the default value and continue searching.
24 //
25 // 3. Return the last default value that was encountered.
26 pub fn get_option_valuerust-analyzer cargo git-delta 0.19.2 options/get/get_option_value().<T>(
27 option_name: &str,
28 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#, featuresrust-analyzer cargo git-delta 0.19.2 features/::BuiltinFeaturerust-analyzer cargo git-delta 0.19.2 features/BuiltinFeature#>,
29 opt: &clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#,
30 git_config: &mut Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<git_configrust-analyzer cargo git-delta 0.19.2 git_config/::GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#>,
31 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>
32 where
33 T: GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet#,
34 T: GetOptionValuerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue#,
35 T: Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<OptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/OptionValue#>,
36 T: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<OptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/OptionValue#>,
37 {
38 T::get_option_valuerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue#get_option_value().(option_name, builtin_features, opt, git_config)
39 }
40
41 static GIT_CONFIG_THEME_REGEXrust-analyzer cargo git-delta 0.19.2 options/get/GIT_CONFIG_THEME_REGEX.: &str = r"^delta\.(.+)\.(light|dark)$";
42
43 pub fn get_themesrust-analyzer cargo git-delta 0.19.2 options/get/get_themes().(git_config: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<git_configrust-analyzer cargo git-delta 0.19.2 git_config/::GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#>) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
44 let mut themes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
45 let git_config = git_config.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
46 git_config.for_eachrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]for_each().(GIT_CONFIG_THEME_REGEXrust-analyzer cargo git-delta 0.19.2 options/get/GIT_CONFIG_THEME_REGEX., |name, _| {
47 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) = name.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().("delta.") {
48 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((name, _)) = name.rsplit_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rsplit_once().('.') {
49 let name = name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().();
50 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().themes.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&name) {
51 themes.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(name);
52 }
53 }
54 }
55 });
56 themes.sort_by_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort_by_key().(|a| a.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().());
57 themes
58 }
59
60 pub trait GetOptionValuerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue# {
61 fn get_option_valuerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue#get_option_value().(
62 option_name: &str,
63 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#, featuresrust-analyzer cargo git-delta 0.19.2 features/::BuiltinFeaturerust-analyzer cargo git-delta 0.19.2 features/BuiltinFeature#>,
64 opt: &clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#,
65 git_config: &mut Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<git_configrust-analyzer cargo git-delta 0.19.2 git_config/::GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#>,
66 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self>
67 where
68 Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
69 Self: GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet#,
70 Self: Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<OptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/OptionValue#>,
71 Self: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<OptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/OptionValue#>,
72 {
73 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config) = git_config {
74 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = git_config.getrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]get().::<Self>(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("delta.{option_name}")) {
75 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value);
76 }
77 }
78 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(features) = &opt.featuresrust-analyzer cargo git-delta 0.19.2 cli/Opt#features. {
79 for feature in features.split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() {
80 match Self::get_provenanced_value_for_featurerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue#get_provenanced_value_for_feature().(
81 option_name,
82 feature,
83 builtin_features,
84 opt,
85 git_config,
86 ) {
87 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(GitConfigValuerust-analyzer cargo git-delta 0.19.2 options/option_value/ProvenancedOptionValue#GitConfigValue#(value)) | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DefaultValuerust-analyzer cargo git-delta 0.19.2 options/option_value/ProvenancedOptionValue#DefaultValue#(value)) => {
88 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
89 }
90 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {}
91 }
92 }
93 }
94 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
95 }
96
97 /// Return the value, or default value, associated with `option_name` under feature name
98 /// `feature`. This may refer to a custom feature, or a builtin feature, or both. Only builtin
99 /// features have defaults. See `GetOptionValue::get_option_value`.
100 fn get_provenanced_value_for_featurerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue#get_provenanced_value_for_feature().(
101 option_name: &str,
102 feature: &str,
103 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#, featuresrust-analyzer cargo git-delta 0.19.2 features/::BuiltinFeaturerust-analyzer cargo git-delta 0.19.2 features/BuiltinFeature#>,
104 opt: &clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#,
105 git_config: &mut Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<git_configrust-analyzer cargo git-delta 0.19.2 git_config/::GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#>,
106 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ProvenancedOptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/ProvenancedOptionValue#>
107 where
108 Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
109 Self: GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet#,
110 Self: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<OptionValuerust-analyzer cargo git-delta 0.19.2 options/option_value/OptionValue#>,
111 {
112 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config) = git_config {
113 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = git_config.getrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]get().::<Self>(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("delta.{feature}.{option_name}")) {
114 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(GitConfigValuerust-analyzer cargo git-delta 0.19.2 options/option_value/ProvenancedOptionValue#GitConfigValue#(value.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()));
115 }
116 }
117 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(builtin_feature) = builtin_features.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(feature) {
118 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value_function) = builtin_feature.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(option_name) {
119 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value_function(opt, git_config));
120 }
121 }
122 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
123 }
124 }
125
126 impl GetOptionValuerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue# for Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {}
127 impl GetOptionValuerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue# for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {}
128 impl GetOptionValuerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue# for bool {}
129 impl GetOptionValuerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue# for f64 {}
130 impl GetOptionValuerust-analyzer cargo git-delta 0.19.2 options/get/GetOptionValue# for usize {}
131
132 #[cfg(test)]
133 pub mod testsrust-analyzer cargo git-delta 0.19.2 options/get/tests/ {
134 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().;
135
136 use craterust-analyzer cargo git-delta 0.19.2 crate/::clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#;
137 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#;
138 use craterust-analyzer cargo git-delta 0.19.2 crate/::optionsrust-analyzer cargo git-delta 0.19.2 options/::getrust-analyzer cargo git-delta 0.19.2 options/get/::get_themesrust-analyzer cargo git-delta 0.19.2 options/get/get_themes().;
139 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/;
140
141 // fn generic<T>(_s: SGen<T>) {}
142 fn _test_env_var_overrides_git_config_genericrust-analyzer cargo git-delta 0.19.2 options/get/tests/_test_env_var_overrides_git_config_generic().(
143 git_config_contents: &[u8],
144 git_config_path: &str,
145 env_value: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
146 fn_cmp_before: &dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#),
147 fn_cmp_after: &dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#),
148 ) {
149 let opt = 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().(
150 &[],
151 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
152 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
153 );
154 fn_cmp_before(opt);
155
156 let opt = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_options_from_args_and_git_config_honoring_env_var_with_custom_envrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config_honoring_env_var_with_custom_env().(
157 DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv# {
158 git_config_parametersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#git_config_parameters.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(env_value),
159 ..DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::defaultrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv][Default]default().()
160 },
161 &[],
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 fn_cmp_after(opt);
166
167 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().();
168 }
169 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
170 fn test_env_var_overrides_git_config_simple_stringrust-analyzer cargo git-delta 0.19.2 options/get/tests/test_env_var_overrides_git_config_simple_string().() {
171 let git_config_contents = b"
172 [delta]
173 plus-style = blue
174 ";
175 let git_config_path = "delta__test_simple_string_env_var_overrides_git_config.gitconfig";
176 _test_env_var_overrides_git_config_genericrust-analyzer cargo git-delta 0.19.2 options/get/tests/_test_env_var_overrides_git_config_generic().(
177 git_config_contents,
178 git_config_path,
179 "'delta.plus-style=green'".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
180 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.plus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#plus_style., "blue"),
181 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.plus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#plus_style., "green"),
182 );
183 }
184
185 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
186 fn test_env_var_overrides_git_config_complex_stringrust-analyzer cargo git-delta 0.19.2 options/get/tests/test_env_var_overrides_git_config_complex_string().() {
187 let git_config_contents = br##"
188 [delta]
189 minus-style = red bold ul "#ffeeee"
190 "##;
191 let git_config_path = "delta__test_complex_string_env_var_overrides_git_config.gitconfig";
192 _test_env_var_overrides_git_config_genericrust-analyzer cargo git-delta 0.19.2 options/get/tests/_test_env_var_overrides_git_config_generic().(
193 git_config_contents,
194 git_config_path,
195 r##"'delta.minus-style=magenta italic ol "#aabbcc"'"##.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
196 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style., r##"red bold ul #ffeeee"##),
197 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.minus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#minus_style., r##"magenta italic ol "#aabbcc""##,),
198 );
199 }
200
201 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
202 fn test_env_var_overrides_git_config_option_stringrust-analyzer cargo git-delta 0.19.2 options/get/tests/test_env_var_overrides_git_config_option_string().() {
203 let git_config_contents = b"
204 [delta]
205 plus-style = blue
206 ";
207 let git_config_path = "delta__test_option_string_env_var_overrides_git_config.gitconfig";
208 _test_env_var_overrides_git_config_genericrust-analyzer cargo git-delta 0.19.2 options/get/tests/_test_env_var_overrides_git_config_generic().(
209 git_config_contents,
210 git_config_path,
211 "'delta.plus-style=green'".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
212 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.plus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#plus_style., "blue"),
213 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.plus_stylerust-analyzer cargo git-delta 0.19.2 cli/Opt#plus_style., "green"),
214 );
215 }
216
217 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
218 fn test_env_var_overrides_git_config_boolrust-analyzer cargo git-delta 0.19.2 options/get/tests/test_env_var_overrides_git_config_bool().() {
219 let git_config_contents = b"
220 [delta]
221 side-by-side = true
222 ";
223 let git_config_path = "delta__test_bool_env_var_overrides_git_config.gitconfig";
224 _test_env_var_overrides_git_config_genericrust-analyzer cargo git-delta 0.19.2 options/get/tests/_test_env_var_overrides_git_config_generic().(
225 git_config_contents,
226 git_config_path,
227 "'delta.side-by-side=false'".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
228 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(opt.side_by_siderust-analyzer cargo git-delta 0.19.2 cli/Opt#side_by_side.),
229 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().opt.side_by_siderust-analyzer cargo git-delta 0.19.2 cli/Opt#side_by_side.),
230 );
231 }
232
233 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
234 fn test_env_var_overrides_git_config_intrust-analyzer cargo git-delta 0.19.2 options/get/tests/test_env_var_overrides_git_config_int().() {
235 let git_config_contents = b"
236 [delta]
237 max-line-length = 1
238 ";
239 let git_config_path = "delta__test_int_env_var_overrides_git_config.gitconfig";
240 _test_env_var_overrides_git_config_genericrust-analyzer cargo git-delta 0.19.2 options/get/tests/_test_env_var_overrides_git_config_generic().(
241 git_config_contents,
242 git_config_path,
243 "'delta.max-line-length=2'".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
244 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.max_line_lengthrust-analyzer cargo git-delta 0.19.2 cli/Opt#max_line_length., 1),
245 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.max_line_lengthrust-analyzer cargo git-delta 0.19.2 cli/Opt#max_line_length., 2),
246 );
247 }
248
249 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
250 fn test_env_var_overrides_git_config_floatrust-analyzer cargo git-delta 0.19.2 options/get/tests/test_env_var_overrides_git_config_float().() {
251 let git_config_contents = b"
252 [delta]
253 max-line-distance = 0.6
254 ";
255 let git_config_path = "delta__test_float_env_var_overrides_git_config.gitconfig";
256 _test_env_var_overrides_git_config_genericrust-analyzer cargo git-delta 0.19.2 options/get/tests/_test_env_var_overrides_git_config_generic().(
257 git_config_contents,
258 git_config_path,
259 "'delta.max-line-distance=0.7'".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
260 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.max_line_distancerust-analyzer cargo git-delta 0.19.2 cli/Opt#max_line_distance., 0.6),
261 &|opt: Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#| assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opt.max_line_distancerust-analyzer cargo git-delta 0.19.2 cli/Opt#max_line_distance., 0.7),
262 );
263 }
264
265 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
266 fn test_delta_features_env_varrust-analyzer cargo git-delta 0.19.2 options/get/tests/test_delta_features_env_var().() {
267 let git_config_contents = b"
268 [delta]
269 features = feature-from-gitconfig
270 ";
271 let git_config_path = "delta__test_delta_features_env_var.gitconfig";
272
273 let opt = 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().(
274 &[],
275 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
276 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
277 );
278 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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().(), "feature-from-gitconfig");
279 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().opt.side_by_siderust-analyzer cargo git-delta 0.19.2 cli/Opt#side_by_side.);
280
281 let opt = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_options_from_args_and_git_config_with_custom_envrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config_with_custom_env().(
282 DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv# {
283 featuresrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#features.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("side-by-side".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
284 ..DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::defaultrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv][Default]default().()
285 },
286 &[],
287 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
288 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
289 );
290 // `line-numbers` is a builtin feature induced by side-by-side
291 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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().(), "line-numbers side-by-side");
292 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(opt.side_by_siderust-analyzer cargo git-delta 0.19.2 cli/Opt#side_by_side.);
293
294 let opt = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_options_from_args_and_git_config_with_custom_envrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config_with_custom_env().(
295 DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv# {
296 featuresrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#features.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("+side-by-side".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
297 ..DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::defaultrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv][Default]default().()
298 },
299 &[],
300 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_contents),
301 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(git_config_path),
302 );
303 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
304 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().(),
305 "feature-from-gitconfig line-numbers side-by-side"
306 );
307 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(opt.side_by_siderust-analyzer cargo git-delta 0.19.2 cli/Opt#side_by_side.);
308
309 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().();
310 }
311
312 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
313 fn test_get_themes_from_configrust-analyzer cargo git-delta 0.19.2 options/get/tests/test_get_themes_from_config().() {
314 let git_config_contents = r#"
315 [delta "dark-theme"]
316 max-line-distance = 0.6
317 dark = true
318
319 [delta "light-theme"]
320 max-line-distance = 0.6
321 light = true
322
323 [delta "light-and-dark-theme"]
324 max-line-distance = 0.6
325 light = true
326 dark = true
327
328 [delta "Uppercase-Theme"]
329 light = true
330
331 [delta "not-a-theme"]
332 max-line-distance = 0.6
333 "#;
334 let git_config_path = "delta__test_get_themes_git_config.gitconfig";
335
336 let git_config = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_git_config().(
337 &DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::defaultrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv][Default]default().(),
338 git_config_contents.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(),
339 git_config_path,
340 false,
341 ));
342
343 let themes = get_themesrust-analyzer cargo git-delta 0.19.2 options/get/get_themes().(git_config);
344
345 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
346 themes,
347 [
348 "dark-theme",
349 "light-and-dark-theme",
350 "light-theme",
351 "Uppercase-Theme"
352 ]
353 );
354
355 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().();
356 }
357 }