Skip to content

Commit

Permalink
avoid negative repeat_count fixes #1760
Browse files Browse the repository at this point in the history
  • Loading branch information
lrfurtado committed Jul 23, 2024
1 parent 4127abc commit a0d0786
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ impl<'p> Painter<'p> {
line.push_str(
#[allow(clippy::unnecessary_to_owned)]
&fill_style
.paint(" ".repeat(config.available_terminal_width - text_width))
.paint(
" ".repeat(config.available_terminal_width.saturating_sub(text_width)),
)
.to_string(),
);
} else if line_is_empty {
Expand Down
50 changes: 50 additions & 0 deletions src/tests/test_example_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,30 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
.expect_after_header("#partial\n\nremoved: a");
}

#[test]
fn test_long_line_underflow() {
let output = DeltaTest::with_args(&["--raw", "--width" , "111", "--zero-style", "syntax #FFFFFF"]).with_input(GIT_DIFF_LONG_LINE).skip_header();

assert_snapshot!(output, @r###"
diff --git a/foobar b/foobar
index 185a33cd5b..123f893935 100755
--- a/foobar
+++ b/foobar
@@ -14,6 +14,11 @@ function UNDERFLOW_EXEC() {
XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX →
}
+
+
+echo "=== VALIDATE UNDERFLOW"
+/usr/local/bin/check_underflow
+
# this is an example of the underflow error
echo "=== UNDERFLOW_EXEC"
UNDERFLOW_EXEC -i foobar.yaml
"###);
}

const GIT_DIFF_SINGLE_HUNK: &str = "\
commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
Author: Dan Davison <[email protected]>
Expand Down Expand Up @@ -2965,4 +2989,30 @@ diff --git a a
new file mode 100644
index 0000000..e69de29
";

const GIT_DIFF_LONG_LINE: &str = r#"\
commit XXXXXXXXXXXXXXXXXXXXXXXXX
Author: LUCIANO FURTADO <[email protected]>
Date: Tue Jun 25 14:07:31 2024 -0500
Ref: https://github.com/dandavison/delta/issues/1760
diff --git a/foobar b/foobar
index 185a33cd5b..123f893935 100755
--- a/foobar
+++ b/foobar
@@ -14,6 +14,11 @@ function UNDERFLOW_EXEC() {
XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
}
+
+
+echo "=== VALIDATE UNDERFLOW"
+/usr/local/bin/check_underflow
+
# this is an example of the underflow error
echo "=== UNDERFLOW_EXEC"
UNDERFLOW_EXEC -i foobar.yaml
"#;
}

0 comments on commit a0d0786

Please sign in to comment.