From 643a0f6c881e33f5156836108efb5d8cb4815482 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 31 May 2020 10:55:20 -0400 Subject: Add failing tests of handling input with color --- src/tests/test_example_diffs.rs | 158 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) (limited to 'src') diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs index 4029256e..2e8d5901 100644 --- a/src/tests/test_example_diffs.rs +++ b/src/tests/test_example_diffs.rs @@ -222,6 +222,40 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e )); } + #[test] + fn test_commit_style_colored_input_color_is_stripped_under_normal() { + let mut options = integration_test_utils::get_command_line_options(); + options.commit_style = "normal".to_string(); + options.commit_decoration_style = "omit".to_string(); + let (output, _) = integration_test_utils::run_delta( + GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES, + options, + ); + ansi_test_utils::assert_line_has_no_color( + &output, + 0, + "commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e", + ); + } + + #[test] + fn test_commit_style_colored_input_color_is_preserved_under_raw() { + let mut options = integration_test_utils::get_command_line_options(); + options.commit_style = "raw".to_string(); + options.commit_decoration_style = "omit".to_string(); + let (output, config) = integration_test_utils::run_delta( + GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES, + options, + ); + ansi_test_utils::assert_line_has_foreground_color( + &output, + 0, + "commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e", + "bold red", + &config, + ); + } + #[test] fn test_commit_decoration_style_omit() { let mut options = integration_test_utils::get_command_line_options(); @@ -383,6 +417,46 @@ index 8e37a9e..6ce4863 100644 )); } + #[test] + fn test_file_style_colored_input_color_is_stripped_under_normal() { + let mut options = integration_test_utils::get_command_line_options(); + options.file_style = "normal".to_string(); + options.file_decoration_style = "omit".to_string(); + let (output, _) = integration_test_utils::run_delta( + GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES, + options, + ); + ansi_test_utils::assert_line_has_no_color(&output, 7, "src/align.rs"); + } + + #[test] + fn test_file_style_colored_input_color_is_preserved_under_raw() { + let mut options = integration_test_utils::get_command_line_options(); + options.file_style = "raw".to_string(); + options.file_decoration_style = "omit".to_string(); + let (output, config) = integration_test_utils::run_delta( + GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES, + options, + ); + for (i, line) in vec![ + "diff --git a/src/align.rs b/src/align.rs", + "index 8e37a9e..6ce4863 100644", + "--- a/src/align.rs", + "+++ b/src/align.rs", + ] + .iter() + .enumerate() + { + ansi_test_utils::assert_line_has_4_bit_foreground_color( + &output, + 6 + i, + line, + "31", + &config, + ) + } + } + #[test] fn test_file_decoration_style_omit() { let mut options = integration_test_utils::get_command_line_options(); @@ -519,6 +593,38 @@ src/align.rs assert!(output.contains("@@ -71,11 +71,8 @@ impl<'a> Alignment<'a> {")); } + #[test] + fn test_hunk_header_style_colored_input_color_is_stripped_under_normal() { + let mut options = integration_test_utils::get_command_line_options(); + options.hunk_header_style = "normal".to_string(); + options.hunk_header_decoration_style = "omit".to_string(); + let (output, _) = integration_test_utils::run_delta( + GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES, + options, + ); + // An additional newline is inserted under anything other than `style=raw, + // decoration-style=omit`, to better separate the hunks. Hence 9 + 1. + ansi_test_utils::assert_line_has_no_color(&output, 9 + 1, " impl<'a> Alignment<'a> {"); + } + + #[test] + fn test_hunk_header_style_colored_input_color_is_preserved_under_raw() { + let mut options = integration_test_utils::get_command_line_options(); + options.hunk_header_style = "raw".to_string(); + options.hunk_header_decoration_style = "omit".to_string(); + let (output, config) = integration_test_utils::run_delta( + GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES, + options, + ); + ansi_test_utils::assert_line_has_foreground_color( + &output, + 9, + "@@ -71,11 +71,8 @@ impl<'a> Alignment<'a> {", + "bold red", + &config, + ); + } + #[test] fn test_hunk_header_decoration_style_omit() { let mut options = integration_test_utils::get_command_line_options(); @@ -686,6 +792,58 @@ index 8e37a9e..6ce4863 100644 parent: left, "; + const GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES: &str = "\ +commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e +Author: Dan Davison +Date: Thu May 14 11:13:17 2020 -0400 + + rustfmt + +diff --git a/src/align.rs b/src/align.rs +index 8e37a9e..6ce4863 100644 +--- a/src/align.rs ++++ b/src/align.rs +@@ -71,11 +71,8 @@ impl<'a> Alignment<'a> { +  + for (i, x_i) in self.x.iter().enumerate() { + for (j, y_j) in self.y.iter().enumerate() { +- let (left, diag, up) = ( +- self.index(i, j + 1), +- self.index(i, j), +- self.index(i + 1, j), +- ); ++ let (left, diag, up) = ++ (self.index(i, j + 1), self.index(i, j), self.index(i + 1, j)); + let candidates = [ + Cell { + parent: left, +diff --git a/src/bat/mod.rs b/src/bat/mod.rs +index 362ba77..7812e7c 100644 +--- a/src/bat/mod.rs ++++ b/src/bat/mod.rs +@@ -1,5 +1,5 @@ + pub mod assets; + pub mod dirs; ++mod less; + pub mod output; + pub mod terminal; +-mod less; +diff --git a/src/bat/output.rs b/src/bat/output.rs +index d23f5e8..e4ed702 100644 +--- a/src/bat/output.rs ++++ b/src/bat/output.rs +@@ -8,8 +8,8 @@ use std::process::{Child, Command, Stdio}; +  + use shell_words; +  +-use crate::env; + use super::less::retrieve_less_version; ++use crate::env; +  + #[derive(Debug, Clone, Copy, PartialEq)] + #[allow(dead_code)] +"; + const DIFF_IN_DIFF: &str = "\ diff --git a/0001-Init.patch b/0001-Init.patch deleted file mode 100644 -- cgit v1.2.3