summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-05-31 14:35:21 -0400
committerDan Davison <dandavison7@gmail.com>2020-05-31 14:55:46 -0400
commite10f7f6f7758c35bd6740399e724043680a60005 (patch)
tree39551b7fe8d5d37f2c8152683b1fb69162e60e2f /src/tests
parent9715086c87f6cbd15905f024822c3546df9f37ff (diff)
In tests, handle 4-bit colors in the context of arbitrary styles
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/ansi_test_utils.rs32
-rw-r--r--src/tests/test_example_diffs.rs78
2 files changed, 29 insertions, 81 deletions
diff --git a/src/tests/ansi_test_utils.rs b/src/tests/ansi_test_utils.rs
index 33ee5d0f..5beb3f4e 100644
--- a/src/tests/ansi_test_utils.rs
+++ b/src/tests/ansi_test_utils.rs
@@ -7,14 +7,14 @@ pub mod ansi_test_utils {
use crate::paint;
use crate::style::Style;
- pub fn assert_line_has_foreground_color(
+ pub fn assert_line_has_style(
output: &str,
line_number: usize,
expected_prefix: &str,
expected_style: &str,
config: &Config,
) {
- _assert_line_has_foreground_color(
+ _assert_line_has_style(
output,
line_number,
expected_prefix,
@@ -24,14 +24,14 @@ pub mod ansi_test_utils {
);
}
- pub fn assert_line_has_4_bit_foreground_color(
+ pub fn assert_line_has_4_bit_color_style(
output: &str,
line_number: usize,
expected_prefix: &str,
expected_style: &str,
config: &Config,
) {
- _assert_line_has_foreground_color(
+ _assert_line_has_style(
output,
line_number,
expected_prefix,
@@ -117,17 +117,7 @@ pub mod ansi_test_utils {
output_buffer
}
- fn has_foreground_color(string: &str, color: ansi_term::Color, _4_bit_color: bool) -> bool {
- let color = if _4_bit_color {
- ansi_term_fixed_foreground_to_4_bit_color(color)
- } else {
- color
- };
- let style = ansi_term::Style::default().fg(color);
- string.starts_with(&style.prefix().to_string())
- }
-
- fn _assert_line_has_foreground_color(
+ fn _assert_line_has_style(
output: &str,
line_number: usize,
expected_prefix: &str,
@@ -137,14 +127,14 @@ pub mod ansi_test_utils {
) {
let line = output.lines().nth(line_number).unwrap();
assert!(strip_ansi_codes(line).starts_with(expected_prefix));
- assert!(has_foreground_color(
- line,
- Style::from_str(expected_style, None, None, None, config.true_color, false)
+ let mut style = Style::from_str(expected_style, None, None, None, config.true_color, false);
+ if _4_bit_color {
+ style.ansi_term_style.foreground = style
.ansi_term_style
.foreground
- .unwrap(),
- _4_bit_color
- ));
+ .map(ansi_term_fixed_foreground_to_4_bit_color);
+ }
+ assert!(line.starts_with(&style.ansi_term_style.prefix().to_string()))
}
fn ansi_term_fixed_foreground_to_4_bit_color(color: ansi_term::Color) -> ansi_term::Color {
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index 2e8d5901..dcca092a 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -247,7 +247,7 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES,
options,
);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
0,
"commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e",
@@ -276,7 +276,7 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
let (output, config) = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, options);
if false {
// `--commit-style xxx` is not honored yet: always behaves like xxx=raw
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
0,
"commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e",
@@ -313,21 +313,21 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
options.commit_style = "blue".to_string();
options.commit_decoration_style = "blue box".to_string();
let (output, config) = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, options);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
0,
"────────────────────────────────────────────────┐",
"blue",
&config,
);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
1,
"commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e │",
"blue",
&config,
);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
2,
"────────────────────────────────────────────────┴─",
@@ -368,14 +368,14 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e │
options.commit_style = "yellow".to_string();
options.commit_decoration_style = "yellow underline".to_string();
let (output, config) = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, options);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
0,
"commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e",
"yellow",
&config,
);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
1,
"───────────────────────────────────────────────",
@@ -447,13 +447,7 @@ index 8e37a9e..6ce4863 100644
.iter()
.enumerate()
{
- ansi_test_utils::assert_line_has_4_bit_foreground_color(
- &output,
- 6 + i,
- line,
- "31",
- &config,
- )
+ ansi_test_utils::assert_line_has_4_bit_color_style(&output, 6 + i, line, "31", &config)
}
}
@@ -475,13 +469,7 @@ index 8e37a9e..6ce4863 100644
fn _do_test_file_style_no_decoration(options: cli::Opt) {
let (output, config) = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, options);
- ansi_test_utils::assert_line_has_foreground_color(
- &output,
- 7,
- "src/align.rs",
- "green",
- &config,
- );
+ ansi_test_utils::assert_line_has_style(&output, 7, "src/align.rs", "green", &config);
let output = strip_ansi_codes(&output);
assert!(output.contains("src/align.rs"));
assert!(!output.contains("src/align.rs │"));
@@ -506,27 +494,9 @@ src/align.rs
options.file_style = "green".to_string();
options.file_decoration_style = "green box".to_string();
let (output, config) = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, options);
- ansi_test_utils::assert_line_has_foreground_color(
- &output,
- 7,
- "─────────────┐",
- "green",
- &config,
- );
- ansi_test_utils::assert_line_has_foreground_color(
- &output,
- 8,
- "src/align.rs │",
- "green",
- &config,
- );
- ansi_test_utils::assert_line_has_foreground_color(
- &output,
- 9,
- "─────────────┴─",
- "green",
- &config,
- );
+ ansi_test_utils::assert_line_has_style(&output, 7, "─────────────┐", "green", &config);
+ ansi_test_utils::assert_line_has_style(&output, 8, "src/align.rs │", "green", &config);
+ ansi_test_utils::assert_line_has_style(&output, 9, "─────────────┴─", "green", &config);
let output = strip_ansi_codes(&output);
assert!(output.contains(
"
@@ -557,20 +527,8 @@ src/align.rs │
options.file_style = "magenta".to_string();
options.file_decoration_style = "magenta underline".to_string();
let (output, config) = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, options);
- ansi_test_utils::assert_line_has_foreground_color(
- &output,
- 7,
- "src/align.rs",
- "magenta",
- &config,
- );
- ansi_test_utils::assert_line_has_foreground_color(
- &output,
- 8,
- "────────────",
- "magenta",
- &config,
- );
+ ansi_test_utils::assert_line_has_style(&output, 7, "src/align.rs", "magenta", &config);
+ ansi_test_utils::assert_line_has_style(&output, 8, "────────────", "magenta", &config);
let output = strip_ansi_codes(&output);
assert!(output.contains(
"
@@ -616,7 +574,7 @@ src/align.rs
GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES,
options,
);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
9,
"@@ -71,11 +71,8 @@ impl<'a> Alignment<'a> {",
@@ -674,14 +632,14 @@ src/align.rs
let mut options = integration_test_utils::get_command_line_options();
options.hunk_header_decoration_style = "white box".to_string();
let (output, config) = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, options);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
10,
"──────────────────────────┐",
"white",
&config,
);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
12,
"──────────────────────────┘",
@@ -723,7 +681,7 @@ src/align.rs
let mut options = integration_test_utils::get_command_line_options();
options.hunk_header_decoration_style = "black underline".to_string();
let (output, config) = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, options);
- ansi_test_utils::assert_line_has_foreground_color(
+ ansi_test_utils::assert_line_has_style(
&output,
11,
"─────────────────────────",