Skip to content

Commit

Permalink
Add test cases for removal of colored boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsjensen committed Feb 15, 2021
1 parent beb8696 commit 352a7b6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,15 +976,20 @@ 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
memmove(input.lines[j].text, input.lines[j].text + c,
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;
Expand Down
2 changes: 1 addition & 1 deletion src/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
Expand Down
2 changes: 2 additions & 0 deletions test/114_headline_ansi_unicode_remove.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions test/121_remove_box_lolcat.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 352a7b6

Please sign in to comment.