diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-20 17:04:11 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-20 17:04:11 -0400 |
commit | be655baa7454c4d0dbc5cb3bb48e40eb5ac4f629 (patch) | |
tree | 35e1b514fa6f58636ba65f429373cfe7953d5401 /src/features/diff_so_fancy.rs | |
parent | 9c7c855d7ad72bd2475db0c4e1ff7320898ec011 (diff) |
Refactor: features tests
Diffstat (limited to 'src/features/diff_so_fancy.rs')
-rw-r--r-- | src/features/diff_so_fancy.rs | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/features/diff_so_fancy.rs b/src/features/diff_so_fancy.rs index fa5952db..0013ef37 100644 --- a/src/features/diff_so_fancy.rs +++ b/src/features/diff_so_fancy.rs @@ -55,3 +55,142 @@ pub fn make_feature() -> Vec<(String, FeatureValueFunction)> { ])); feature } + +#[cfg(test)] +pub mod tests { + use std::fs::remove_file; + + use crate::features; + + #[test] + fn test_diff_so_fancy_defaults() { + let config = features::tests::make_config(&["--features", "diff-so-fancy"], None, None); + + assert_eq!( + config.commit_style.ansi_term_style, + features::tests::make_style("bold yellow").ansi_term_style + ); + assert_eq!( + config.commit_style.decoration_style, + features::tests::make_decoration_style("none") + ); + + assert_eq!( + config.file_style.ansi_term_style, + features::tests::make_style("11").ansi_term_style + ); + assert_eq!( + config.file_style.decoration_style, + features::tests::make_decoration_style("bold yellow ul ol") + ); + + assert_eq!( + config.hunk_header_style.ansi_term_style, + features::tests::make_style("bold syntax").ansi_term_style + ); + assert_eq!( + config.hunk_header_style.decoration_style, + features::tests::make_decoration_style("magenta box") + ); + } + + #[test] + fn test_diff_so_fancy_respects_git_config() { + let git_config_contents = b" +[color \"diff\"] + meta = 11 + frag = magenta bold + commit = yellow bold + old = red bold + new = green bold + whitespace = red reverse +"; + let git_config_path = "delta__test_diff_so_fancy.gitconfig"; + + let config = features::tests::make_config( + &["--features", "diff-so-fancy some-other-feature"], + Some(git_config_contents), + Some(git_config_path), + ); + + assert_eq!( + config.commit_style.ansi_term_style, + features::tests::make_style("yellow bold").ansi_term_style + ); + assert_eq!( + config.file_style.ansi_term_style, + features::tests::make_style("11").ansi_term_style + ); + assert_eq!( + config.hunk_header_style.ansi_term_style, + features::tests::make_style("magenta bold").ansi_term_style + ); + assert_eq!( + config.commit_style.decoration_style, + features::tests::make_decoration_style("none") + ); + assert_eq!( + config.file_style.decoration_style, + features::tests::make_decoration_style("yellow bold ul ol") + ); + assert_eq!( + config.hunk_header_style.decoration_style, + features::tests::make_decoration_style("magenta box") + ); + + remove_file(git_config_path).unwrap(); + } + + #[test] + fn test_diff_so_fancy_obeys_feature_precedence_rules() { + let git_config_contents = b" +[color \"diff\"] + meta = 11 + frag = magenta bold + commit = yellow bold + old = red bold + new = green bold + whitespace = red reverse + +[delta \"decorations\"] + commit-decoration-style = bold box ul + file-style = bold 19 ul + file-decoration-style = none +"; + let git_config_path = "delta__test_diff_so_fancy_obeys_feature_precedence_rules.gitconfig"; + + let config = features::tests::make_config( + &["--features", "decorations diff-so-fancy"], + Some(git_config_contents), + Some(git_config_path), + ); + + assert_eq!( + config.file_style.ansi_term_style, + features::tests::make_style("11").ansi_term_style + ); + + assert_eq!( + config.file_style.decoration_style, + features::tests::make_decoration_style("yellow bold ul ol") + ); + + let config = features::tests::make_config( + &["--features", "diff-so-fancy decorations"], + Some(git_config_contents), + Some(git_config_path), + ); + + assert_eq!( + config.file_style.ansi_term_style, + features::tests::make_style("ul bold 19").ansi_term_style + ); + + assert_eq!( + config.file_style.decoration_style, + features::tests::make_decoration_style("none") + ); + + remove_file(git_config_path).unwrap(); + } +} |