From 3b5c89fcbc6efc2a346dfbd2cc2c49fcdae8a0b0 Mon Sep 17 00:00:00 2001 From: ryuta69 Date: Sat, 19 Sep 2020 00:00:52 +0900 Subject: Fix `git add -p` to work when any options enabled (#323) * Add test for input and output for diff interactive filter * Add color_only in config struct * Refactor should_handle false when color_only and FileMeta, CommitMeta * Refactor handle_hunk_header_line to show raw_text with color_format when color_only * Fix indent * Revert the logic changes for interactive filter * Add color only workaround in set options * Add more test patterns for diff interactive fillter --- src/tests/test_example_diffs.rs | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/tests/test_example_diffs.rs') diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs index 9f1a257..e7a00ee 100644 --- a/src/tests/test_example_diffs.rs +++ b/src/tests/test_example_diffs.rs @@ -835,6 +835,50 @@ src/align.rs ); } + #[test] + fn test_color_only_output_is_in_one_to_one_correspondence_with_input() { + _do_test_output_is_in_one_to_one_correspondence_with_input(&["--color-only", "true"]); + _do_test_output_is_in_one_to_one_correspondence_with_input(&[ + "--color-only", + "true", + "--file-style", + "blue", + "--commit-style", + "omit", + "--hunk-header-style", + "omit", + "--hunk-header-decoration-style", + "omit", + ]); + _do_test_output_is_in_one_to_one_correspondence_with_input(&[ + "--color-only", + "true", + "--file-style", + "blue", + "--commit-style", + "red", + "--hunk-header-style", + "syntax", + "--hunk-header-decoration-style", + "box", + ]); + } + + 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(); + + assert_eq!(input_lines.len(), output_lines.len()); + + for n in 0..input_lines.len() { + assert_eq!(input_lines[n], output_lines[n]); + } + } + #[test] fn test_hunk_header_style_colored_input_color_is_stripped_under_normal() { let config = integration_test_utils::make_config_from_args(&[ -- cgit v1.2.3