| 1 | use crate::features::raw; |
| 2 | use crate::features::OptionValueFunction; |
| 3 | |
| 4 | pub fn make_feature() -> Vec<(String, OptionValueFunction)> { |
| 5 | _make_feature(false) |
| 6 | } |
| 7 | |
| 8 | pub fn _make_feature(bold: bool) -> Vec<(String, OptionValueFunction)> { |
| 9 | let mut feature = raw::make_feature(); |
| 10 | feature.retain(|(s, _)| s != "keep-plus-minus-markers" && s != "tabs"); |
| 11 | feature.extend(builtin_feature!([ |
| 12 | ( |
| 13 | "commit-style", |
| 14 | String, |
| 15 | Some("color.diff.commit"), |
| 16 | _opt => "raw" |
| 17 | ), |
| 18 | ( |
| 19 | "minus-style", |
| 20 | String, |
| 21 | Some("color.diff.old"), |
| 22 | _opt => if bold { "bold red" } else { "red" } |
| 23 | ), |
| 24 | ( |
| 25 | "minus-non-emph-style", |
| 26 | String, |
| 27 | Some("color.diff-highlight.oldNormal"), |
| 28 | opt => opt.minus_style.clone() |
| 29 | ), |
| 30 | ( |
| 31 | "minus-emph-style", |
| 32 | String, |
| 33 | Some("color.diff-highlight.oldHighlight"), |
| 34 | opt => format!("{} reverse", opt.minus_style) |
| 35 | ), |
| 36 | ( |
| 37 | "plus-style", |
| 38 | String, |
| 39 | Some("color.diff.new"), |
| 40 | _opt => if bold { "bold green" } else { "green" } |
| 41 | ), |
| 42 | ( |
| 43 | "plus-non-emph-style", |
| 44 | String, |
| 45 | Some("color.diff-highlight.newNormal"), |
| 46 | opt => opt.plus_style.clone() |
| 47 | ), |
| 48 | ( |
| 49 | "plus-emph-style", |
| 50 | String, |
| 51 | Some("color.diff-highlight.newHighlight"), |
| 52 | opt => format!("{} reverse", opt.plus_style) |
| 53 | ) |
| 54 | ])); |
| 55 | feature |
| 56 | } |
| 57 | |
| 58 | #[cfg(test)] |
| 59 | mod test_utils { |
| 60 | use std::fs::remove_file; |
| 61 | |
| 62 | use crate::tests::integration_test_utils; |
| 63 | |
| 64 | #[test] |
| 65 | fn test_diff_highlight_defaults() { |
| 66 | let opt = integration_test_utils::make_options_from_args_and_git_config( |
| 67 | &["--features", "diff-highlight"], |
| 68 | None, |
| 69 | None, |
| 70 | ); |
| 71 | assert_eq!(opt.minus_style, "red"); |
| 72 | assert_eq!(opt.minus_non_emph_style, "red"); |
| 73 | assert_eq!(opt.minus_emph_style, "red reverse"); |
| 74 | assert_eq!(opt.zero_style, "normal"); |
| 75 | assert_eq!(opt.plus_style, "green"); |
| 76 | assert_eq!(opt.plus_non_emph_style, "green"); |
| 77 | assert_eq!(opt.plus_emph_style, "green reverse"); |
| 78 | } |
| 79 | |
| 80 | #[test] |
| 81 | fn test_diff_highlight_respects_gitconfig() { |
| 82 | let git_config_contents = b" |
| 83 | [color \"diff\"] |
| 84 | old = red bold |
| 85 | new = green bold |
| 86 | |
| 87 | [color \"diff-highlight\"] |
| 88 | oldNormal = ul red bold |
| 89 | oldHighlight = red bold 52 |
| 90 | newNormal = ul green bold |
| 91 | newHighlight = green bold 22 |
| 92 | "; |
| 93 | let git_config_path = "delta__test_diff_highlight.gitconfig"; |
| 94 | |
| 95 | let opt = integration_test_utils::make_options_from_args_and_git_config( |
| 96 | &["--features", "diff-highlight"], |
| 97 | Some(git_config_contents), |
| 98 | Some(git_config_path), |
| 99 | ); |
| 100 | |
| 101 | assert_eq!(opt.minus_style, "red bold"); |
| 102 | assert_eq!(opt.minus_non_emph_style, "ul red bold"); |
| 103 | assert_eq!(opt.minus_emph_style, "red bold 52"); |
| 104 | assert_eq!(opt.zero_style, "normal"); |
| 105 | assert_eq!(opt.plus_style, "green bold"); |
| 106 | assert_eq!(opt.plus_non_emph_style, "ul green bold"); |
| 107 | assert_eq!(opt.plus_emph_style, "green bold 22"); |
| 108 | |
| 109 | remove_file(git_config_path).unwrap(); |
| 110 | } |
| 111 | } |