Add more box removal test cases

This commit is contained in:
Thomas Jensen 2023-05-21 13:59:25 +02:00
parent 15c72d4d99
commit 45ce5e6762
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB
7 changed files with 197 additions and 13 deletions

View File

@ -20,7 +20,7 @@
#ifndef BOXES_H
#define BOXES_H
/* #define DEBUG 1 */
#define DEBUG 1
/* #define REGEXP_DEBUG 1 */
/* #define PARSER_DEBUG 1 */
/* #define LEXER_DEBUG 1 */

View File

@ -18,6 +18,7 @@
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -155,8 +156,10 @@ static int best_match(const line_t *line,
cs = opt.design->shape + east_side[++w];
}
#ifdef DEBUG
fprintf(stderr, "\nj %d, k %d, w %d, cs->chars[k] = \"%s\"\n",
(int) j, (int) k, w, cs->chars[k] ? cs->chars[k] : "(null)");
char *mbcs_temp = bxs_to_output(cs->mbcs[k]);
fprintf(stderr, "\nj %d, k %d, w %d, cs->chars[k] = \"%s\", cs->mbcs[k] = \"%s\"\n",
(int) j, (int) k, w, cs->chars[k] ? cs->chars[k] : "(null)", mbcs_temp);
BFREE(mbcs_temp);
#endif
chkline.text = cs->chars[k];
@ -528,8 +531,7 @@ static design_t *detect_design()
for (dcnt = 0; dcnt < num_designs; ++dcnt, ++d) {
#ifdef DEBUG
fprintf (stderr, "CONSIDERING DESIGN ---- \"%s\" ---------------\n",
d->name);
fprintf(stderr, "CONSIDERING DESIGN ---- \"%s\" ---------------\n", d->name);
#endif
hits = 0;
@ -537,7 +539,7 @@ static design_t *detect_design()
empty[j] = empty_side(d->shape, j);
}
#ifdef DEBUG
fprintf (stderr, "Empty sides: TOP %d, LEFT %d, BOTTOM %d, RIGHT %d\n",
fprintf (stderr, "Empty sides: TOP %d, LEFT %d, BOTTOM %d, RIGHT %d\n",
empty[BTOP], empty[BLEF], empty[BBOT], empty[BRIG]);
#endif
@ -556,7 +558,7 @@ static design_t *detect_design()
break;
}
for (j = 0; j < d->shape[scnt].height; ++j) {
shpln.text = d->shape[scnt].chars[j];
shpln.text = d->shape[scnt].chars[j]; // TODO HERE
shpln.len = d->shape[scnt].width;
if (empty_line(&shpln)) {
continue;
@ -578,9 +580,9 @@ static design_t *detect_design()
}
}
}
#ifdef DEBUG
fprintf (stderr, "After %s corner check:\t%ld hits.\n", shape_name[scnt], hits);
#endif
#ifdef DEBUG
fprintf(stderr, "After %s corner check:\t%ld hits.\n", shape_name[scnt], hits);
#endif
break;
case NE:
@ -1089,7 +1091,9 @@ void output_input(const int trim_only)
indentspc[ntabs + nspcs] = '\0';
}
else if (opt.tabexp == 'k') {
indentspc = tabbify_indent(j, NULL, input.indent);
uint32_t *indent32 = tabbify_indent(j, NULL, input.indent);
indentspc = u32_strconv_to_output(indent32);
BFREE(indent32);
indent = input.indent;
}
else {
@ -1104,5 +1108,4 @@ void output_input(const int trim_only)
}
/*EOF*/ /* vim: set sw=4: */
/* vim: set sw=4: */

View File

@ -0,0 +1,35 @@
:DESC
Remove a broken box which is still recognized by the design autodetector because of its intact west side.
Boxes usually get damaged on their east side because their contents got edited.
:ARGS
-r
:INPUT
._____. ._____. .________________________. ._____. ._____.
| ._. | | ._. | | .____________________. | | ._. | | ._. |
| !_| |_|_|_! | | !____________________! | | !_| |_|_|_! |
!___| |_______! !________________________! !___| |_______!
.___|_|_| |____________________________________|_|_| |___.
| ._____| |________________________________________| |_. |
| !_! | | | | | ! !_! |
!_____! | |
._____. | |
| ._. | | | Lorem ipsum | | | ._. |
| | | | | | dolor sit amet | | | | | |
| !_! | | | consectetur adipiscing elit, | | ! !_! |
!_____! | | sed do eiusmod tempor. | | !_____!
._____. | | | | ._____.
| ._. | | |
| !_| |_|_|____________________________________| |_|_|_! |
!___| |________________________________________| |_______!
.___|_|_| |___. .________________________. .___|_|_| |___.
| ._____| |_. | | .____________________. | | ._____| |_. |
| !_! | | !_! | | !____________________! | | !_! | | !_! |
!_____! !_____! !________________________! !_____! !_____!
:OUTPUT-FILTER
:EXPECTED
Lorem ipsum
dolor sit amet
consectetur adipiscing elit,
sed do eiusmod tempor.
:EOF

View File

@ -0,0 +1,51 @@
# A partially colored box of unicode characters, including double-wide characters.
BOX designA
sample
┏━┳━━━━━━━━━━ 沐宸 若汐 ━━━━━━━━━┳━┓
┃ ┃ ┃ ┃
ほ┃ Lorem ipsum ┃ふ
げ┃ dolor sit amet ┃が
ほ┃ consectetur adipiscing elit, ┃ふ
げ┃ sed do eiusmod tempor. ┃が
┣━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━┫
┗━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━┛
ends
# Monochrome sample:
# ┏━┳━━━━━━━━━━ 沐宸 若汐 ━━━━━━━━━┳━┓
# ┃ ┃ ┃ ┃
# ほ┃ Lorem ipsum ┃ふ
# げ┃ dolor sit amet ┃が
# ほ┃ consectetur adipiscing elit, ┃ふ
# げ┃ sed do eiusmod tempor. ┃が
# ┣━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━┫
# ┗━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━┛
shapes {
n (" 沐宸 若汐 ",
" ")
nw ("┏━┳", "┃ ┃")
nnw ("━", " ")
nne ("━", " ")
ne ("┳━┓", "┃ ┃")
e ("┃ふ",
"┃が")
w ("ほ┃",
"げ┃")
se ("╋━┫",
"┻━┛")
s ("━", "━")
sw ("┣━╋", "┗━┻")
}
elastic (
nnw, nne, e, w, s
)
padding {
horiz 1
}
END designA

View File

@ -0,0 +1,21 @@
:DESC
Remove a box consisting of unicode characters, double-wide characters, and ansi escape codes.
:ARGS
-f 179_remove_box_ansi_unicode.cfg -r
:INPUT
┏━┳━━━━━━━━━━ 沐宸 若汐 ━━━━━━━━━┳━┓
┃ ┃ ┃ ┃
ほ┃ Lorem ipsum ┃ふ
げ┃ dolor sit amet ┃が
ほ┃ consectetur adipiscing elit, ┃ふ
げ┃ sed do eiusmod tempor. ┃が
┣━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━┫
┗━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━┛
:OUTPUT-FILTER
:EXPECTED
Lorem ipsum
dolor sit amet
consectetur adipiscing elit,
sed do eiusmod tempor.
:EOF

View File

@ -0,0 +1,51 @@
# A partially colored box of unicode characters, include double-wide characters.
BOX designA
sample
┏━┳━━━━━━━━━━ 沐宸 若汐 ━━━━━━━━━┳━┓
┃ ┃ ┃ ┃
ほ┃ Lorem ipsum ┃ふ
げ┃ dolor sit amet ┃が
ほ┃ consectetur adipiscing elit, ┃ふ
げ┃ sed do eiusmod tempor. ┃が
┣━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━┫
┗━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━┛
ends
# Monochrome sample:
# ┏━┳━━━━━━━━━━ 沐宸 若汐 ━━━━━━━━━┳━┓
# ┃ ┃ ┃ ┃
# ほ┃ Lorem ipsum ┃ふ
# げ┃ dolor sit amet ┃が
# ほ┃ consectetur adipiscing elit, ┃ふ
# げ┃ sed do eiusmod tempor. ┃が
# ┣━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━┫
# ┗━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━┛
shapes {
n (" 沐宸 若汐 ",
" ")
nw ("┏━┳", "┃ ┃")
nnw ("━", " ")
nne ("━", " ")
ne ("┳━┓", "┃ ┃")
e ("┃ふ",
"┃が")
w ("ほ┃",
"げ┃")
se ("╋━┫",
"┻━┛")
s ("━", "━")
sw ("┣━╋", "┗━┻")
}
elastic (
nnw, nne, e, w, s
)
padding {
horiz 1
}
END designA

View File

@ -0,0 +1,23 @@
:DESC
Remove a box consisting of unicode characters, double-wide characters, and ansi escape codes,
while properly restoring tabbed indentation and handling the fact that the box is broken due to editing of the text
inside.
:ARGS
--config 180_remove_box_ansi_unicode_broken_indented.cfg --remove --tabs 4u
:INPUT
┏━┳━━━━━━━━━━ 沐宸 若汐 ━━━━━━━━━┳━┓
┃ ┃ ┃ ┃
ほ┃ Lorem ipsum ┃ふ
げ┃ dolor sit amet
ほ┃ consectetur adipiscing elit, ┃ふ
げ┃ sed do eiusmod tempor. ┃が
┣━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━┫
┗━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━┛
:OUTPUT-FILTER
:EXPECTED
Lorem ipsum
dolor sit amet
consectetur adipiscing elit,
sed do eiusmod tempor.
:EOF