summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-11-01 19:35:49 -0500
committerGitHub <noreply@github.com>2020-11-01 19:35:49 -0500
commit2d3b3ce5406f35daeb93a0dc40cdbd55e07dae6c (patch)
treeece67f2394adf80ad9a78dab58d2c91066ac510e
parent6c418e004a1b9071a6749de6d79c738d99dda4db (diff)
parent45422c99fa0b4444ff276b452ce9b3f70e0d0339 (diff)
Merge pull request #374 from dandavison/371-fix-keep-plus-minus-markers-for-color-moved-lines
Fix keep-plus-minus-markers for color moved lines
-rw-r--r--src/cli.rs2
-rw-r--r--src/paint.rs9
-rw-r--r--src/tests/test_example_diffs.rs49
3 files changed, 58 insertions, 2 deletions
diff --git a/src/cli.rs b/src/cli.rs
index e762fc38..53fcf1d4 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -585,7 +585,7 @@ impl Default for Width {
}
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
pub enum InspectRawLines {
True,
False,
diff --git a/src/paint.rs b/src/paint.rs
index d31868c0..e69ebeee 100644
--- a/src/paint.rs
+++ b/src/paint.rs
@@ -104,7 +104,14 @@ impl<'a> Painter<'a> {
/// Remove the initial +/- character of a line that will be emitted unchanged, including any
/// ANSI escape sequences.
pub fn prepare_raw_line(&self, line: &str) -> String {
- ansi::ansi_preserving_slice(&self.expand_tabs(line.graphemes(true)), 1)
+ ansi::ansi_preserving_slice(
+ &self.expand_tabs(line.graphemes(true)),
+ if self.config.keep_plus_minus_markers {
+ 0
+ } else {
+ 1
+ },
+ )
}
/// Expand tabs as spaces.
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index 94a100bb..661c44c7 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -1,6 +1,7 @@
#[cfg(test)]
mod tests {
use crate::ansi::{self, strip_ansi_codes};
+ use crate::cli::InspectRawLines;
use crate::delta::State;
use crate::style;
use crate::tests::ansi_test_utils::ansi_test_utils;
@@ -1259,6 +1260,23 @@ impl<'a> Alignment<'a> { │
assert_eq!(output, input);
}
+ // See https://github.com/dandavison/delta/issues/371#issuecomment-720173435
+ #[test]
+ fn test_keep_plus_minus_markers_under_inspect_raw_lines() {
+ let config = integration_test_utils::make_config_from_args(&["--keep-plus-minus-markers"]);
+ assert_eq!(config.inspect_raw_lines, InspectRawLines::True);
+ let output = integration_test_utils::run_delta(
+ GIT_DIFF_UNDER_COLOR_MOVED_DIMMED_ZEBRA_WITH_ANSI_ESCAPE_SEQUENCES,
+ &config,
+ );
+ let output = strip_ansi_codes(&output);
+ assert!(output.contains(
+ r#"
+- "stddev": 0.004157057519168492,
+"#
+ ));
+ }
+
const GIT_DIFF_SINGLE_HUNK: &str = "\
commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
Author: Dan Davison <dandavison7@gmail.com>
@@ -1790,4 +1808,35 @@ index 386f291a..22666f79 100644
@@ -5,0 +7 @@ int main() {
+ return 0;
"#;
+
+ const GIT_DIFF_UNDER_COLOR_MOVED_DIMMED_ZEBRA_WITH_ANSI_ESCAPE_SEQUENCES: &str = r#"
+commit 8406b1996daa176ca677ac33b18f071b766c87a5
+Author: Dan Davison <dandavison7@gmail.com>
+Date: Sun Nov 1 15:28:53 2020 -0500
+
+ A change to investigate color-moved behavior, see #371
+
+diff --git a/etc/performance/all-benchmarks.json b/etc/performance/all-benchmarks.json
+index f86240e7..f707e5fd 100644
+--- a/etc/performance/all-benchmarks.json
++++ b/etc/performance/all-benchmarks.json
+@@ -7,9 +7,9 @@
+ "median": 0.004928057465000001,
+ "message": "cargo new delta\n",
+ "min": 0.003220796465,
+- "stddev": 0.004157057519168492,
+ "system": 0.0016010150000000001,
+ "time": 0.013288195465,
++ "stddev": 0.004157057519168492,
+ "user": 0.0013687749999999996
+ },
+ {
+@@ -26649,4 +26649,4 @@
+ "time": 1.8524859272050003,
+ "user": 1.8240279649999998
+ }
+-]
+\ No newline at end of file
++]
+"#;
}