From d4e3c288ae8bdfe2bf93c9c23c88860a3987973c Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Tue, 16 Nov 2021 18:57:44 -0800 Subject: Use file-modified-label consistently. When filtering a diff and when directly diffing files/dirs, use the modified label that is output when interpreting git diffs. This gets rid of the "comparing:" prefix (which was otherwise missing from the --navigate regex) and ensures that a direct diff has a label to stop at when --navigate is enabled. One of the unified-diff tests now uses --file-modified-label=comparing: to generate the same output as before, while the other now uses --navigate to get a delta char label. --- src/handlers/file_meta.rs | 23 ++++++++++++++--------- src/tests/test_example_diffs.rs | 13 ++++++------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/handlers/file_meta.rs b/src/handlers/file_meta.rs index 82109a91..d58eb9dd 100644 --- a/src/handlers/file_meta.rs +++ b/src/handlers/file_meta.rs @@ -304,16 +304,21 @@ pub fn get_file_change_description_from_file_paths( plus_file_event: &FileEvent, config: &Config, ) -> String { + let format_label = |label: &str| { + if !label.is_empty() { + format!("{} ", label) + } else { + "".to_string() + } + }; if comparing { - format!("comparing: {} ⟶ {}", minus_file, plus_file) + format!( + "{}{} ⟶ {}", + format_label(&config.file_modified_label), + minus_file, + plus_file + ) } else { - let format_label = |label: &str| { - if !label.is_empty() { - format!("{} ", label) - } else { - "".to_string() - } - }; let format_file = |file| { if config.hyperlinks { features::hyperlinks::format_osc8_file_hyperlink(file, None, file, config) @@ -356,7 +361,7 @@ pub fn get_file_change_description_from_file_paths( format_label(match file_event { FileEvent::Rename => &config.file_renamed_label, FileEvent::Copy => &config.file_copied_label, - _ => "", + _ => &config.file_modified_label, }), format_file(minus_file), format_file(plus_file) diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs index dda5bcf6..a6d5f497 100644 --- a/src/tests/test_example_diffs.rs +++ b/src/tests/test_example_diffs.rs @@ -110,7 +110,8 @@ mod tests { #[test] fn test_diff_unified_two_files() { - let config = integration_test_utils::make_config_from_args(&[]); + let config = + integration_test_utils::make_config_from_args(&["--file-modified-label", "comparing:"]); let output = integration_test_utils::run_delta(DIFF_UNIFIED_TWO_FILES, &config); let output = strip_ansi_codes(&output); let mut lines = output.lines(); @@ -125,16 +126,14 @@ mod tests { #[test] fn test_diff_unified_two_directories() { - let config = integration_test_utils::make_config_from_args(&["--width", "80"]); + let config = + integration_test_utils::make_config_from_args(&["--width", "80", "--navigate"]); let output = integration_test_utils::run_delta(DIFF_UNIFIED_TWO_DIRECTORIES, &config); let output = strip_ansi_codes(&output); let mut lines = output.lines(); // Header - assert_eq!( - lines.nth(1).unwrap(), - "comparing: a/different ⟶ b/different" - ); + assert_eq!(lines.nth(1).unwrap(), "Δ a/different ⟶ b/different"); // Change assert_eq!(lines.nth(7).unwrap(), "This is different from b"); // File uniqueness @@ -144,7 +143,7 @@ mod tests { // Next hunk assert_eq!( lines.nth(4).unwrap(), - "comparing: a/more_difference ⟶ b/more_difference" + "Δ a/more_difference ⟶ b/more_difference" ); } -- cgit v1.2.3