mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-24 19:51:29 +02:00
Add unit tests for alignment option parsing (-a)
This commit is contained in:
parent
fbc4678faa
commit
413b174d6c
@ -139,10 +139,11 @@ static opt_t *create_new_opt()
|
|||||||
*/
|
*/
|
||||||
static int alignment(opt_t *result, char *optarg)
|
static int alignment(opt_t *result, char *optarg)
|
||||||
{
|
{
|
||||||
int errfl = 0;
|
int errfl = 1;
|
||||||
char *p = optarg;
|
char *p = optarg;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
|
errfl = 0;
|
||||||
if (p[1] == '\0' && !strchr("lLcCrR", *p)) {
|
if (p[1] == '\0' && !strchr("lLcCrR", *p)) {
|
||||||
errfl = 1;
|
errfl = 1;
|
||||||
break;
|
break;
|
||||||
@ -210,7 +211,7 @@ static int alignment(opt_t *result, char *optarg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (errfl) {
|
if (errfl) {
|
||||||
fprintf(stderr, "%s: Illegal text format -- %s\n", PROJECT, optarg);
|
bx_fprintf(stderr, "%s: Illegal text format -- %s\n", PROJECT, optarg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -276,7 +277,7 @@ static int eol_override(opt_t *result, char *optarg)
|
|||||||
result->eol = "\r";
|
result->eol = "\r";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: invalid eol spec -- %s\n", PROJECT, optarg);
|
bx_fprintf(stderr, "%s: invalid eol spec -- %s\n", PROJECT, optarg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -443,7 +444,7 @@ static int size_of_box(opt_t *result, char *optarg)
|
|||||||
*p = 'x';
|
*p = 'x';
|
||||||
}
|
}
|
||||||
if (errno || (result->reqwidth == 0 && result->reqheight == 0) || result->reqwidth < 0 || result->reqheight < 0) {
|
if (errno || (result->reqwidth == 0 && result->reqheight == 0) || result->reqwidth < 0 || result->reqheight < 0) {
|
||||||
fprintf(stderr, "%s: invalid box size specification -- %s\n", PROJECT, optarg);
|
bx_fprintf(stderr, "%s: invalid box size specification -- %s\n", PROJECT, optarg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -535,7 +536,7 @@ static int input_output_files(opt_t *result, char *argv[], int optind)
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (argv[optind + 1] && argv[optind + 2]) { /* illegal third file */
|
else if (argv[optind + 1] && argv[optind + 2]) { /* illegal third file */
|
||||||
fprintf(stderr, "%s: illegal parameter -- %s\n", PROJECT, argv[optind + 2]);
|
bx_fprintf(stderr, "%s: illegal parameter -- %s\n", PROJECT, argv[optind + 2]);
|
||||||
usage_short(stderr);
|
usage_short(stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -547,7 +548,7 @@ static int input_output_files(opt_t *result, char *argv[], int optind)
|
|||||||
else {
|
else {
|
||||||
result->infile = fopen(argv[optind], "r");
|
result->infile = fopen(argv[optind], "r");
|
||||||
if (result->infile == NULL) {
|
if (result->infile == NULL) {
|
||||||
fprintf(stderr, "%s: Can\'t open input file -- %s\n", PROJECT, argv[optind]);
|
bx_fprintf(stderr, "%s: Can\'t open input file -- %s\n", PROJECT, argv[optind]);
|
||||||
return 9; /* can't read infile */
|
return 9; /* can't read infile */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -741,7 +742,7 @@ opt_t *process_commandline(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s: internal error\n", PROJECT);
|
bx_fprintf(stderr, "%s: internal error\n", PROJECT);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} while (oc != EOF);
|
} while (oc != EOF);
|
||||||
|
@ -307,4 +307,64 @@ void test_tabstops_7(void **state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_alignment_invalid_hX(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(2, "-a", "hX");
|
||||||
|
|
||||||
|
assert_null(actual); // invalid option, so we would need to exit with error
|
||||||
|
assert_int_equal(1, collect_err_size);
|
||||||
|
assert_string_equal("boxes: Illegal text format -- hX\n", collect_err[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_alignment_invalid_vX(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(2, "-a", "vX");
|
||||||
|
|
||||||
|
assert_null(actual); // invalid option, so we would need to exit with error
|
||||||
|
assert_int_equal(1, collect_err_size);
|
||||||
|
assert_string_equal("boxes: Illegal text format -- vX\n", collect_err[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_alignment_invalid_jX(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(2, "-a", "jX");
|
||||||
|
|
||||||
|
assert_null(actual); // invalid option, so we would need to exit with error
|
||||||
|
assert_int_equal(1, collect_err_size);
|
||||||
|
assert_string_equal("boxes: Illegal text format -- jX\n", collect_err[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_alignment_notset(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(2, "-a", "");
|
||||||
|
|
||||||
|
assert_null(actual); // invalid option, so we would need to exit with error
|
||||||
|
assert_int_equal(1, collect_err_size);
|
||||||
|
assert_string_equal("boxes: Illegal text format -- \n", collect_err[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_alignment_incomplete(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(2, "-a", "v");
|
||||||
|
|
||||||
|
assert_null(actual); // invalid option, so we would need to exit with error
|
||||||
|
assert_int_equal(1, collect_err_size);
|
||||||
|
assert_string_equal("boxes: Illegal text format -- v\n", collect_err[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*EOF*/ /* vim: set cindent sw=4: */
|
/*EOF*/ /* vim: set cindent sw=4: */
|
||||||
|
@ -51,6 +51,12 @@ void test_tabstops_4e(void **state);
|
|||||||
void test_tabstops_4ex(void **state);
|
void test_tabstops_4ex(void **state);
|
||||||
void test_tabstops_7(void **state);
|
void test_tabstops_7(void **state);
|
||||||
|
|
||||||
|
void test_alignment_invalid_hX(void **state);
|
||||||
|
void test_alignment_invalid_vX(void **state);
|
||||||
|
void test_alignment_invalid_jX(void **state);
|
||||||
|
void test_alignment_notset(void **state);
|
||||||
|
void test_alignment_incomplete(void **state);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -68,7 +68,12 @@ int main(void)
|
|||||||
cmocka_unit_test_setup(test_tabstops_4X, beforeTest),
|
cmocka_unit_test_setup(test_tabstops_4X, beforeTest),
|
||||||
cmocka_unit_test_setup(test_tabstops_4e, beforeTest),
|
cmocka_unit_test_setup(test_tabstops_4e, beforeTest),
|
||||||
cmocka_unit_test_setup(test_tabstops_4ex, beforeTest),
|
cmocka_unit_test_setup(test_tabstops_4ex, beforeTest),
|
||||||
cmocka_unit_test_setup(test_tabstops_7, beforeTest)
|
cmocka_unit_test_setup(test_tabstops_7, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_alignment_invalid_hX, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_alignment_invalid_vX, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_alignment_invalid_jX, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_alignment_notset, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_alignment_incomplete, beforeTest)
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct CMUnitTest regulex_tests[] = {
|
const struct CMUnitTest regulex_tests[] = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user