summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-05-31 10:55:20 -0400
committerDan Davison <dandavison7@gmail.com>2020-05-31 14:55:46 -0400
commit643a0f6c881e33f5156836108efb5d8cb4815482 (patch)
tree6249d6a03a1db3c85ba4a7b01c72be6f96002210 /src
parent20eeaba4b3ad6dddff50a7d8f1864d68a1810c49 (diff)
Add failing tests of handling input with color
Diffstat (limited to 'src')
-rw-r--r--src/tests/test_example_diffs.rs158
1 files changed, 158 insertions, 0 deletions
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
@@ -223,6 +223,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();
options.commit_style = "blue".to_string();
@@ -384,6 +418,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();
options.file_style = "green".to_string();
@@ -520,6 +594,38 @@ src/align.rs
}
#[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();
options.hunk_header_decoration_style = "omit".to_string();
@@ -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 <dandavison7@gmail.com>
+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