| 1 | use crate::features::diff_highlight; |
| 2 | use crate::features::OptionValueFunction; |
| 3 | |
| 4 | pub fn make_feature() -> Vec<(String, OptionValueFunction)> { |
| 5 | let mut feature = diff_highlight::_make_feature(true); |
| 6 | feature.extend(builtin_feature!([ |
| 7 | ( |
| 8 | "minus-emph-style", |
| 9 | String, |
| 10 | Some("color.diff-highlight.oldHighlight"), |
| 11 | _opt => "bold red 52" |
| 12 | ), |
| 13 | ( |
| 14 | "plus-emph-style", |
| 15 | String, |
| 16 | Some("color.diff-highlight.newHighlight"), |
| 17 | _opt => "bold green 22" |
| 18 | ), |
| 19 | ( |
| 20 | "file-style", |
| 21 | String, |
| 22 | Some("color.diff.meta"), |
| 23 | _opt => "11" |
| 24 | ), |
| 25 | ( |
| 26 | "file-decoration-style", |
| 27 | String, |
| 28 | None, |
| 29 | _opt => "bold yellow ul ol" |
| 30 | ), |
| 31 | ( |
| 32 | "hunk-header-style", |
| 33 | String, |
| 34 | Some("color.diff.frag"), |
| 35 | _opt => "file line-number bold syntax" |
| 36 | ), |
| 37 | ( |
| 38 | "hunk-header-decoration-style", |
| 39 | String, |
| 40 | None, |
| 41 | _opt => "magenta box" |
| 42 | ) |
| 43 | ])); |
| 44 | feature |
| 45 | } |
| 46 | |
| 47 | #[cfg(test)] |
| 48 | pub mod tests { |
| 49 | use std::fs::remove_file; |
| 50 | |
| 51 | use crate::tests::integration_test_utils; |
| 52 | |
| 53 | #[test] |
| 54 | fn test_diff_so_fancy_defaults() { |
| 55 | let opt = integration_test_utils::make_options_from_args_and_git_config( |
| 56 | &["--features", "diff-so-fancy"], |
| 57 | None, |
| 58 | None, |
| 59 | ); |
| 60 | |
| 61 | assert_eq!(opt.commit_style, "raw"); |
| 62 | assert_eq!(opt.commit_decoration_style, "none"); |
| 63 | |
| 64 | assert_eq!(opt.file_style, "11"); |
| 65 | assert_eq!(opt.file_decoration_style, "bold yellow ul ol"); |
| 66 | |
| 67 | assert_eq!(opt.hunk_header_style, "file line-number bold syntax"); |
| 68 | assert_eq!(opt.hunk_header_decoration_style, "magenta box"); |
| 69 | } |
| 70 | |
| 71 | #[test] |
| 72 | fn test_diff_so_fancy_respects_git_config() { |
| 73 | let git_config_contents = b" |
| 74 | [color \"diff\"] |
| 75 | meta = 11 |
| 76 | frag = magenta bold |
| 77 | commit = purple bold |
| 78 | old = red bold |
| 79 | new = green bold |
| 80 | whitespace = red reverse |
| 81 | "; |
| 82 | let git_config_path = "delta__test_diff_so_fancy.gitconfig"; |
| 83 | |
| 84 | let opt = integration_test_utils::make_options_from_args_and_git_config( |
| 85 | &["--features", "diff-so-fancy some-other-feature"], |
| 86 | Some(git_config_contents), |
| 87 | Some(git_config_path), |
| 88 | ); |
| 89 | |
| 90 | assert_eq!(opt.commit_style, "purple bold"); |
| 91 | assert_eq!(opt.file_style, "11"); |
| 92 | assert_eq!(opt.hunk_header_style, "magenta bold"); |
| 93 | assert_eq!(opt.commit_decoration_style, "none"); |
| 94 | assert_eq!(opt.file_decoration_style, "bold yellow ul ol"); |
| 95 | assert_eq!(opt.hunk_header_decoration_style, "magenta box"); |
| 96 | |
| 97 | remove_file(git_config_path).unwrap(); |
| 98 | } |
| 99 | |
| 100 | #[test] |
| 101 | fn test_diff_so_fancy_obeys_feature_precedence_rules() { |
| 102 | let git_config_contents = b" |
| 103 | [color \"diff\"] |
| 104 | meta = 11 |
| 105 | frag = magenta bold |
| 106 | commit = yellow bold |
| 107 | old = red bold |
| 108 | new = green bold |
| 109 | whitespace = red reverse |
| 110 | |
| 111 | [delta \"decorations\"] |
| 112 | commit-decoration-style = bold box ul |
| 113 | file-style = bold 19 ul |
| 114 | file-decoration-style = none |
| 115 | "; |
| 116 | let git_config_path = "delta__test_diff_so_fancy_obeys_feature_precedence_rules.gitconfig"; |
| 117 | |
| 118 | let opt = integration_test_utils::make_options_from_args_and_git_config( |
| 119 | &["--features", "decorations diff-so-fancy"], |
| 120 | Some(git_config_contents), |
| 121 | Some(git_config_path), |
| 122 | ); |
| 123 | |
| 124 | assert_eq!(opt.file_style, "11"); |
| 125 | |
| 126 | assert_eq!(opt.file_decoration_style, "bold yellow ul ol"); |
| 127 | |
| 128 | let opt = integration_test_utils::make_options_from_args_and_git_config( |
| 129 | &["--features", "diff-so-fancy decorations"], |
| 130 | Some(git_config_contents), |
| 131 | Some(git_config_path), |
| 132 | ); |
| 133 | |
| 134 | assert_eq!(opt.file_style, "bold 19 ul"); |
| 135 | |
| 136 | assert_eq!(opt.file_decoration_style, "none"); |
| 137 | |
| 138 | remove_file(git_config_path).unwrap(); |
| 139 | } |
| 140 | } |