From ba40638946a99653452b9ccfc9d78bb7afc2a6b9 Mon Sep 17 00:00:00 2001 From: Thomas Jensen Date: Sun, 29 Oct 2023 14:35:06 +0100 Subject: [PATCH] Add two more black-box tests for removal with fixes --- src/remove.c | 8 +++++--- test/188_design_not_detectable.txt | 11 +++++++++++ test/189_blank_lines_surrounding_box.txt | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/188_design_not_detectable.txt create mode 100644 test/189_blank_lines_surrounding_box.txt diff --git a/src/remove.c b/src/remove.c index fe3cc14..c0b9258 100644 --- a/src/remove.c +++ b/src/remove.c @@ -730,11 +730,13 @@ static void match_vertical_side(remove_ctx_t *ctx, int vside, shape_line_ctx_t * BFREE(to_free); shape_text = NULL; - if (p == NULL) { + if ((p == NULL) + || (vside == BLEF && ((size_t) (p - input_line) > input_indent + (max_quality - quality))) + || (vside == BRIG && ((size_t) (p - input_line) < input_length - input_trailing - quality))) { shape_text = shorten(*shape_line_ctx, &quality, vside == BLEF, 1, 1); to_free = shape_text; } - else if (vside == BLEF && ((size_t) (p - input_line) <= input_indent + (max_quality - quality))) { + else if (vside == BLEF) { if (quality > line_ctx->west_quality) { line_ctx->west_start = (size_t) (p - input_line); line_ctx->west_end = line_ctx->west_start + quality; @@ -744,7 +746,7 @@ static void match_vertical_side(remove_ctx_t *ctx, int vside, shape_line_ctx_t * break; } } - else if (vside == BRIG && ((size_t) (p - input_line) >= input_length - input_trailing - quality)) { + else if (vside == BRIG) { if (quality > line_ctx->east_quality) { line_ctx->east_start = (size_t) (p - input_line); line_ctx->east_end = line_ctx->east_start + quality; diff --git a/test/188_design_not_detectable.txt b/test/188_design_not_detectable.txt new file mode 100644 index 0000000..26adcab --- /dev/null +++ b/test/188_design_not_detectable.txt @@ -0,0 +1,11 @@ +:DESC +Tests that a proper error message is produced when the box design cannot be detected. + +:ARGS +-r +:INPUT +foo +:OUTPUT-FILTER +:EXPECTED-ERROR 1 +boxes: Box design autodetection failed. Use -d option. +:EOF diff --git a/test/189_blank_lines_surrounding_box.txt b/test/189_blank_lines_surrounding_box.txt new file mode 100644 index 0000000..137b54e --- /dev/null +++ b/test/189_blank_lines_surrounding_box.txt @@ -0,0 +1,22 @@ +:DESC +Blank lines above and below the box are retained when the box is removed. +There are some spaces in the line just above the box. + +:ARGS +-r -d jstone +:INPUT + + +/*-------------+ + | Lorem Ipsum | + +-------------*/ + + +:OUTPUT-FILTER +:EXPECTED + + +Lorem Ipsum + + +:EOF