From 352a7b6d5d7a3aec121c5f7aa3685d56e715d5df Mon Sep 17 00:00:00 2001 From: Thomas Jensen Date: Sun, 14 Feb 2021 14:38:00 +0100 Subject: [PATCH] Add test cases for removal of colored boxes --- src/remove.c | 9 +++++++-- src/tools.c | 2 +- test/114_headline_ansi_unicode_remove.txt | 2 ++ test/121_remove_box_lolcat.txt | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 test/121_remove_box_lolcat.txt diff --git a/src/remove.c b/src/remove.c index e8184cc..174b39c 100644 --- a/src/remove.c +++ b/src/remove.c @@ -976,7 +976,7 @@ int remove_box() break; } } - #ifdef DEBUG + #if defined(DEBUG) fprintf(stderr, "memmove(\"%s\", \"%s\", %d);\n", input.lines[j].text, input.lines[j].text + c, (int) (input.lines[j].len - c + 1)); #endif @@ -984,7 +984,12 @@ int remove_box() input.lines[j].len - c + 1); /* +1 for zero byte */ input.lines[j].len -= c; - /* TODO the next line may kill an escape code to color the next char */ + #if defined(DEBUG) + fprintf(stderr, "u32_move(\"%s\", \"%s\", %d); // posmap[c]=%d\n", + u32_strconv_to_output(input.lines[j].mbtext), + u32_strconv_to_output(input.lines[j].mbtext + input.lines[j].posmap[c]), + (int) (input.lines[j].num_chars - c + 1), (int) input.lines[j].posmap[c]); + #endif u32_move(input.lines[j].mbtext, input.lines[j].mbtext + input.lines[j].posmap[c], input.lines[j].num_chars - c + 1); /* +1 for zero byte */ input.lines[j].num_chars -= c; diff --git a/src/tools.c b/src/tools.c index 9c021e0..02ff9e5 100644 --- a/src/tools.c +++ b/src/tools.c @@ -197,7 +197,7 @@ void concat_strings(char *dst, int max_len, int count, ...) /* * Concatenate 'src' onto 'dst', as long as we have room. */ - while (*src && max_len > 1) { // TODO Can this be improved via strcpy + while (*src && max_len > 1) { *dst++ = *src++; max_len--; } diff --git a/test/114_headline_ansi_unicode_remove.txt b/test/114_headline_ansi_unicode_remove.txt index 57c11b2..0c1b5e8 100644 --- a/test/114_headline_ansi_unicode_remove.txt +++ b/test/114_headline_ansi_unicode_remove.txt @@ -9,8 +9,10 @@ box was created. :INPUT /**************************/ /* f o o  ęµ·  b a r  */ + /* f o o b a r */ /**************************/ :OUTPUT-FILTER :EXPECTED foo ęµ· bar + foobar :EOF diff --git a/test/121_remove_box_lolcat.txt b/test/121_remove_box_lolcat.txt new file mode 100644 index 0000000..45e576e --- /dev/null +++ b/test/121_remove_box_lolcat.txt @@ -0,0 +1,16 @@ +:DESC +Remove a box which has been piped through lolcat, including the box itself and the indentation, all of which was +colored. + +:ARGS +-r +:INPUT +   /**********/ +   /* foobar */ +   /* boofar */ +   /**********/ +:OUTPUT-FILTER +:EXPECTED +   foobar +   boofar +:EOF