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
|
use crate::features::raw;
use crate::features::OptionValueFunction;
pub fn make_feature() -> Vec<(String, OptionValueFunction)> {
_make_feature(false)
}
pub fn _make_feature(bold: bool) -> Vec<(String, OptionValueFunction)> {
let mut feature = raw::make_feature();
feature.extend(builtin_feature!([
(
"keep-plus-minus-markers",
bool,
None,
_opt => false
),
(
"minus-style",
String,
Some("color.diff.old"),
_opt => if bold { "bold red" } else { "red" }
),
(
"minus-non-emph-style",
String,
Some("color.diff-highlight.oldNormal"),
opt => opt.minus_style.clone()
),
(
"minus-emph-style",
String,
Some("color.diff-highlight.oldHighlight"),
opt => format!("{} reverse", opt.minus_style)
),
(
"plus-style",
String,
Some("color.diff.new"),
_opt => if bold { "bold green" } else { "green" }
),
(
"plus-non-emph-style",
String,
Some("color.diff-highlight.newNormal"),
opt => opt.plus_style.clone()
),
(
"plus-emph-style",
String,
Some("color.diff-highlight.newHighlight"),
opt => format!("{} reverse", opt.plus_style)
)
]));
feature
}
#[cfg(test)]
mod test_utils {
use std::fs::remove_file;
use crate::features;
#[test]
fn test_diff_highlight_defaults() {
let opt = features::tests::make_options(&["--features", "diff-highlight"], None, None);
assert_eq!(opt.minus_style, "red");
assert_eq!(opt.minus_non_emph_style, "red");
assert_eq!(opt.minus_emph_style, "red reverse");
assert_eq!(opt.zero_style, "normal");
assert_eq!(opt.plus_style, "green");
assert_eq!(opt.plus_non_emph_style, "green");
assert_eq!(opt.plus_emph_style, "green reverse");
}
#[test]
fn test_diff_highlight_respects_gitconfig() {
let git_config_contents = b"
[color \"diff\"]
old = red bold
new = green bold
[color \"diff-highlight\"]
oldNormal = ul red bold
oldHighlight = red bold 52
newNormal = ul green bold
newHighlight = green bold 22
";
let git_config_path = "delta__test_diff_highlight.gitconfig";
let opt = features::tests::make_options(
&["--features", "diff-highlight"],
Some(git_config_contents),
Some(git_config_path),
);
assert_eq!(opt.minus_style, "red bold");
assert_eq!(opt.minus_non_emph_style, "ul red bold");
assert_eq!(opt.minus_emph_style, "red bold 52");
assert_eq!(opt.zero_style, "normal");
assert_eq!(opt.plus_style, "green bold");
assert_eq!(opt.plus_non_emph_style, "ul green bold");
assert_eq!(opt.plus_emph_style, "green bold 22");
remove_file(git_config_path).unwrap();
}
}
|