mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-03-10 20:28:15 +01:00
Add more box removal test cases
This commit is contained in:
parent
15c72d4d99
commit
45ce5e6762
@ -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 */
|
||||
|
27
src/remove.c
27
src/remove.c
@ -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: */
|
||||
|
35
test/178_remove_broken_box.txt
Normal file
35
test/178_remove_broken_box.txt
Normal 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
|
51
test/179_remove_box_ansi_unicode.cfg
Normal file
51
test/179_remove_box_ansi_unicode.cfg
Normal file
@ -0,0 +1,51 @@
|
||||
# A partially colored box of unicode characters, including double-wide characters.
|
||||
|
||||
BOX designA
|
||||
|
||||
sample
|
||||
┏━┳━━━━━━━━━━ [38;5;154m沐[0m[38;5;184m宸[0m[38;5;184m [0m[38;5;184m若[0m[38;5;214m汐[0m ━━━━━━━━━┳━┓
|
||||
┃ ┃ ┃ ┃
|
||||
[38;5;63mほ[39m[38;5;63m┃[39m Lorem ipsum [38;5;44m┃[39m[38;5;44mふ[39m
|
||||
[38;5;63mげ[39m[38;5;69m┃[39m dolor sit amet [38;5;43m┃[39m[38;5;49mが[39m
|
||||
[38;5;63mほ[39m[38;5;63m┃[39m consectetur adipiscing elit, [38;5;44m┃[39m[38;5;44mふ[39m
|
||||
[38;5;63mげ[39m[38;5;69m┃[39m sed do eiusmod tempor. [38;5;43m┃[39m[38;5;49mが[39m
|
||||
┣━╋[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m╋[39m[38;5;48m━[39m[38;5;48m┫[39m
|
||||
┗━┻[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m┻[39m[38;5;48m━[39m[38;5;48m┛[39m
|
||||
ends
|
||||
|
||||
# Monochrome sample:
|
||||
# ┏━┳━━━━━━━━━━ 沐宸 若汐 ━━━━━━━━━┳━┓
|
||||
# ┃ ┃ ┃ ┃
|
||||
# ほ┃ Lorem ipsum ┃ふ
|
||||
# げ┃ dolor sit amet ┃が
|
||||
# ほ┃ consectetur adipiscing elit, ┃ふ
|
||||
# げ┃ sed do eiusmod tempor. ┃が
|
||||
# ┣━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━┫
|
||||
# ┗━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━┛
|
||||
|
||||
shapes {
|
||||
n (" [38;5;154m沐[0m[38;5;184m宸[0m[38;5;184m [0m[38;5;184m若[0m[38;5;214m汐[0m ",
|
||||
" ")
|
||||
nw ("┏━┳", "┃ ┃")
|
||||
nnw ("━", " ")
|
||||
nne ("━", " ")
|
||||
ne ("┳━┓", "┃ ┃")
|
||||
e ("[38;5;44m┃[39m[38;5;44mふ[39m",
|
||||
"[38;5;43m┃[39m[38;5;49mが[39m")
|
||||
w ("[38;5;63mほ[39m[38;5;63m┃[39m",
|
||||
"[38;5;63mげ[39m[38;5;69m┃[39m")
|
||||
se ("[38;5;49m╋[39m[38;5;48m━[39m[38;5;48m┫[39m",
|
||||
"[38;5;48m┻[39m[38;5;48m━[39m[38;5;48m┛[39m")
|
||||
s ("[38;5;49m━[39m", "[38;5;48m━[39m")
|
||||
sw ("┣━╋", "┗━┻")
|
||||
}
|
||||
|
||||
elastic (
|
||||
nnw, nne, e, w, s
|
||||
)
|
||||
|
||||
padding {
|
||||
horiz 1
|
||||
}
|
||||
|
||||
END designA
|
21
test/179_remove_box_ansi_unicode.txt
Normal file
21
test/179_remove_box_ansi_unicode.txt
Normal 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
|
||||
┏━┳━━━━━━━━━━ [38;5;154m沐[0m[38;5;184m宸[0m[38;5;184m [0m[38;5;184m若[0m[38;5;214m汐[0m ━━━━━━━━━┳━┓
|
||||
┃ ┃ ┃ ┃
|
||||
[38;5;63mほ[39m[38;5;63m┃[39m Lorem ipsum [38;5;44m┃[39m[38;5;44mふ[39m
|
||||
[38;5;63mげ[39m[38;5;69m┃[39m dolor sit amet [38;5;43m┃[39m[38;5;49mが[39m
|
||||
[38;5;63mほ[39m[38;5;63m┃[39m consectetur adipiscing elit, [38;5;44m┃[39m[38;5;44mふ[39m
|
||||
[38;5;63mげ[39m[38;5;69m┃[39m sed do eiusmod tempor. [38;5;43m┃[39m[38;5;49mが[39m
|
||||
┣━╋[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m╋[39m[38;5;48m━[39m[38;5;48m┫[39m
|
||||
┗━┻[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m┻[39m[38;5;48m━[39m[38;5;48m┛[39m
|
||||
:OUTPUT-FILTER
|
||||
:EXPECTED
|
||||
Lorem ipsum
|
||||
dolor sit amet
|
||||
consectetur adipiscing elit,
|
||||
sed do eiusmod tempor.
|
||||
:EOF
|
51
test/180_remove_box_ansi_unicode_broken_indented.cfg
Normal file
51
test/180_remove_box_ansi_unicode_broken_indented.cfg
Normal file
@ -0,0 +1,51 @@
|
||||
# A partially colored box of unicode characters, include double-wide characters.
|
||||
|
||||
BOX designA
|
||||
|
||||
sample
|
||||
┏━┳━━━━━━━━━━ [38;5;154m沐[0m[38;5;184m宸[0m[38;5;184m [0m[38;5;184m若[0m[38;5;214m汐[0m ━━━━━━━━━┳━┓
|
||||
┃ ┃ ┃ ┃
|
||||
[38;5;63mほ[39m[38;5;63m┃[39m Lorem ipsum [38;5;44m┃[39m[38;5;44mふ[39m
|
||||
[38;5;63mげ[39m[38;5;69m┃[39m dolor sit amet [38;5;43m┃[39m[38;5;49mが[39m
|
||||
[38;5;63mほ[39m[38;5;63m┃[39m consectetur adipiscing elit, [38;5;44m┃[39m[38;5;44mふ[39m
|
||||
[38;5;63mげ[39m[38;5;69m┃[39m sed do eiusmod tempor. [38;5;43m┃[39m[38;5;49mが[39m
|
||||
┣━╋[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m╋[39m[38;5;48m━[39m[38;5;48m┫[39m
|
||||
┗━┻[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m┻[39m[38;5;48m━[39m[38;5;48m┛[39m
|
||||
ends
|
||||
|
||||
# Monochrome sample:
|
||||
# ┏━┳━━━━━━━━━━ 沐宸 若汐 ━━━━━━━━━┳━┓
|
||||
# ┃ ┃ ┃ ┃
|
||||
# ほ┃ Lorem ipsum ┃ふ
|
||||
# げ┃ dolor sit amet ┃が
|
||||
# ほ┃ consectetur adipiscing elit, ┃ふ
|
||||
# げ┃ sed do eiusmod tempor. ┃が
|
||||
# ┣━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━┫
|
||||
# ┗━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━┛
|
||||
|
||||
shapes {
|
||||
n (" [38;5;154m沐[0m[38;5;184m宸[0m[38;5;184m [0m[38;5;184m若[0m[38;5;214m汐[0m ",
|
||||
" ")
|
||||
nw ("┏━┳", "┃ ┃")
|
||||
nnw ("━", " ")
|
||||
nne ("━", " ")
|
||||
ne ("┳━┓", "┃ ┃")
|
||||
e ("[38;5;44m┃[39m[38;5;44mふ[39m",
|
||||
"[38;5;43m┃[39m[38;5;49mが[39m")
|
||||
w ("[38;5;63mほ[39m[38;5;63m┃[39m",
|
||||
"[38;5;63mげ[39m[38;5;69m┃[39m")
|
||||
se ("[38;5;49m╋[39m[38;5;48m━[39m[38;5;48m┫[39m",
|
||||
"[38;5;48m┻[39m[38;5;48m━[39m[38;5;48m┛[39m")
|
||||
s ("[38;5;49m━[39m", "[38;5;48m━[39m")
|
||||
sw ("┣━╋", "┗━┻")
|
||||
}
|
||||
|
||||
elastic (
|
||||
nnw, nne, e, w, s
|
||||
)
|
||||
|
||||
padding {
|
||||
horiz 1
|
||||
}
|
||||
|
||||
END designA
|
23
test/180_remove_box_ansi_unicode_broken_indented.txt
Normal file
23
test/180_remove_box_ansi_unicode_broken_indented.txt
Normal 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
|
||||
┏━┳━━━━━━━━━━ [38;5;154m沐[0m[38;5;184m宸[0m[38;5;184m [0m[38;5;184m若[0m[38;5;214m汐[0m ━━━━━━━━━┳━┓
|
||||
┃ ┃ ┃ ┃
|
||||
[38;5;63mほ[39m[38;5;63m┃[39m Lorem ipsum [38;5;44m┃[39m[38;5;44mふ[39m
|
||||
[38;5;63mげ[39m[38;5;69m┃[39m dolor sit amet
|
||||
[38;5;63mほ[39m[38;5;63m┃[39m consectetur adipiscing elit, [38;5;44m┃[39m[38;5;44mふ[39m
|
||||
[38;5;63mげ[39m[38;5;69m┃[39m sed do eiusmod tempor. [38;5;43m┃[39m[38;5;49mが[39m
|
||||
┣━╋[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m━[39m[38;5;49m╋[39m[38;5;48m━[39m[38;5;48m┫[39m
|
||||
┗━┻[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m━[39m[38;5;48m┻[39m[38;5;48m━[39m[38;5;48m┛[39m
|
||||
:OUTPUT-FILTER
|
||||
:EXPECTED
|
||||
Lorem ipsum
|
||||
dolor sit amet
|
||||
consectetur adipiscing elit,
|
||||
sed do eiusmod tempor.
|
||||
:EOF
|
Loading…
Reference in New Issue
Block a user