summaryrefslogtreecommitdiffstats
path: root/src/features/side_by_side.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/side_by_side.rs')
-rw-r--r--src/features/side_by_side.rs64
1 files changed, 58 insertions, 6 deletions
diff --git a/src/features/side_by_side.rs b/src/features/side_by_side.rs
index f175fa2a..ac2de08e 100644
--- a/src/features/side_by_side.rs
+++ b/src/features/side_by_side.rs
@@ -1,6 +1,6 @@
use itertools::Itertools;
use syntect::highlighting::Style as SyntectStyle;
-use unicode_segmentation::UnicodeSegmentation;
+use unicode_width::UnicodeWidthStr;
use crate::ansi;
use crate::cli;
@@ -75,12 +75,10 @@ pub fn available_line_width(
}
pub fn line_is_too_long(line: &str, line_width: usize) -> bool {
- let line_sum = line.graphemes(true).count();
-
debug_assert!(line.ends_with('\n'));
- // `line_sum` is too large because a trailing newline is present,
- // so allow one more character.
- line_sum > line_width + 1
+
+ // graphemes will take care of newlines
+ line.width() > line_width
}
/// Return whether any of the input lines is too long, and a data
@@ -715,4 +713,58 @@ pub mod tests {
│ 2 │b = 2 │ 2 │bb = 2 "#,
);
}
+
+ #[test]
+ fn test_two_minus_lines_unicode_truncated() {
+ DeltaTest::with_args(&[
+ "--side-by-side",
+ "--wrap-max-lines",
+ "2",
+ "--width",
+ "16",
+ "--line-fill-method=spaces",
+ ])
+ .set_config(|cfg| cfg.truncation_symbol = ">".into())
+ .with_input(TWO_MINUS_LINES_UNICODE_DIFF)
+ .expect_after_header(
+ r#"
+ │ 1 │↵ │ │
+ │ │↵ │ │
+ │ │ >│ │"#,
+ );
+
+ DeltaTest::with_args(&[
+ "--side-by-side",
+ "--wrap-max-lines",
+ "2",
+ "--width",
+ "17",
+ "--line-fill-method=spaces",
+ ])
+ .set_config(|cfg| cfg.truncation_symbol = ">".into())
+ .with_input(TWO_MINUS_LINES_UNICODE_DIFF)
+ .expect_after_header(
+ r#"
+ │ 1 │↵ │ │
+ │ │↵ │ │
+ │ │ >│ │"#,
+ );
+
+ DeltaTest::with_args(&[
+ "--side-by-side",
+ "--wrap-max-lines",
+ "2",
+ "--width",
+ "18",
+ "--line-fill-method=spaces",
+ ])
+ .set_config(|cfg| cfg.truncation_symbol = ">".into())
+ .with_input(TWO_MINUS_LINES_UNICODE_DIFF)
+ .expect_after_header(
+ r#"
+ │ 1 │一↵│ │
+ │ │二↵│ │
+ │ │三 │ │"#,
+ );
+ }
}