summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorryuta69 <eyma22s.yu@gmail.com>2020-09-24 08:36:03 +0900
committerGitHub <noreply@github.com>2020-09-23 19:36:03 -0400
commit42bfff5a4dbaaf466b083dae137efb1dc4518410 (patch)
tree99413311d2ed2a3dd9adb76aacd12b55e9745c2c
parent788c3636ece17612c7adf262f209990f603bb512 (diff)
Add identical test when color_only and line_numbers are enabled at same time (#331)
* Delete assert_eq of each lines of input and output * Add checking identical between input and output
-rw-r--r--src/tests/test_example_diffs.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index e7a00ee3..9332b212 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -841,6 +841,13 @@ src/align.rs
_do_test_output_is_in_one_to_one_correspondence_with_input(&[
"--color-only",
"true",
+ "--hunk-header-style",
+ "normal",
+ "--line-numbers",
+ ]);
+ _do_test_output_is_in_one_to_one_correspondence_with_input(&[
+ "--color-only",
+ "true",
"--file-style",
"blue",
"--commit-style",
@@ -867,15 +874,26 @@ src/align.rs
fn _do_test_output_is_in_one_to_one_correspondence_with_input(args: &[&str]) {
let config = integration_test_utils::make_config_from_args(args);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
-
let output = strip_ansi_codes(&output);
- let output_lines: Vec<&str> = output.split('\n').collect();
- let input_lines: Vec<&str> = GIT_DIFF_SINGLE_HUNK.split('\n').collect();
+ let input_lines: Vec<&str> = GIT_DIFF_SINGLE_HUNK.split('\n').collect();
+ let output_lines: Vec<&str> = output.split('\n').collect();
assert_eq!(input_lines.len(), output_lines.len());
+ // Although git patch options only checks the line counts of input and output,
+ // we should check if they are identical as well to avoid unexpected decoration.
for n in 0..input_lines.len() {
- assert_eq!(input_lines[n], output_lines[n]);
+ let input_line = input_lines[n];
+ // If config.line_numbers is enabled,
+ // we should remove line_numbers decoration while checking.
+ let output_line = if config.line_numbers && n > 11 && n < input_lines.len() - 1 {
+ &output_lines[n][14..]
+ } else {
+ output_lines[n]
+ };
+ // TODO: this trim() can be removed by simplifing width_boxed of draw_fn.
+ assert_eq!(input_line.trim(), output_line.trim());
+ // assert_eq!(input_line, output_line);
}
}