Beef up ncplane_puttext() tests, fix a problem #691

This commit is contained in:
nick black 2020-06-16 00:30:02 -04:00
parent b49d1ad838
commit 2be041b1f4
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 26 additions and 11 deletions

View File

@ -1502,7 +1502,8 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
int width;
// verified columns thus far (carried, and through breaker)
size_t verifiedcols = x;
while(*text && x < dimx - 1){
// FIXME what ought be done with \n or multiple spaces?
while(*text && x < dimx){
wchar_t w;
size_t consumed = mbrtowc(&w, text, MB_CUR_MAX, &mbstate);
if(consumed == (size_t)-2 || consumed == (size_t)-1){
@ -1520,14 +1521,14 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
}
return -1;
}
if(x + width >= dimx){
break;
}
// FIXME use the more advanced unicode functionality to break lines
if(iswspace(w)){
breaker = text;
verifiedcols = x;
}
if(x + width > dimx){
break;
}
x += width;
text += consumed;
}
@ -1539,7 +1540,7 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
}
totalcols += verifiedcols;
const int xpos = ncplane_align(n, align, x);
if(breaker == NULL){
if(!*text || breaker == NULL){
breaker = text;
}
if(ncplane_putnstr_yx(n, y, xpos, breaker - linestart, linestart) < 0){

View File

@ -20,12 +20,10 @@ TEST_CASE("TextLayout") {
CHECK(bytes == strlen(str));
char* line = ncplane_contents(sp, 0, 0, 1, 20);
REQUIRE(line);
fprintf(stderr, "**********\n%s\n", line);
CHECK(0 == strcmp(line, "this is going to be"));
free(line);
line = ncplane_contents(sp, 1, 0, 1, 20);
REQUIRE(line);
fprintf(stderr, "**********\n%s\n", line);
CHECK(0 == strcmp(line, "broken up"));
free(line);
ncplane_destroy(sp);
@ -38,7 +36,14 @@ fprintf(stderr, "**********\n%s\n", line);
CHECK(0 < ncplane_puttext(sp, 0, NCALIGN_RIGHT, str, &bytes));
CHECK(0 == notcurses_render(nc_));
CHECK(bytes == strlen(str));
// FIXME inspect layout
char* line = ncplane_contents(sp, 0, 0, 1, 20);
REQUIRE(line);
CHECK(0 == strcmp(line, "this is going to be"));
free(line);
line = ncplane_contents(sp, 1, 0, 1, 20);
REQUIRE(line);
CHECK(0 == strcmp(line, "broken up"));
free(line);
ncplane_destroy(sp);
}
@ -49,7 +54,14 @@ fprintf(stderr, "**********\n%s\n", line);
CHECK(0 < ncplane_puttext(sp, 0, NCALIGN_CENTER, str, &bytes));
CHECK(0 == notcurses_render(nc_));
CHECK(bytes == strlen(str));
// FIXME inspect layout
char* line = ncplane_contents(sp, 0, 0, 1, 20);
REQUIRE(line);
CHECK(0 == strcmp(line, "this is going to be"));
free(line);
line = ncplane_contents(sp, 1, 0, 1, 20);
REQUIRE(line);
CHECK(0 == strcmp(line, "broken up"));
free(line);
ncplane_destroy(sp);
}

View File

@ -16,7 +16,7 @@ static const char* datadir = NOTCURSES_SHARE;
auto testing_notcurses() -> struct notcurses* {
notcurses_options nopts{};
nopts.loglevel = NCLOGLEVEL_DEBUG;
nopts.flags = NCOPTION_SUPPRESS_BANNERS;
nopts.flags = NCOPTION_SUPPRESS_BANNERS/* | NCOPTION_NO_ALTERNATE_SCREEN*/;
auto nc = notcurses_init(&nopts, nullptr);
return nc;
}
@ -98,10 +98,12 @@ auto main(int argc, const char **argv) -> int {
std::cerr << "Couldn't set locale based on user preferences!" << std::endl;
return EXIT_FAILURE;
}
if(getenv("TERM") == NULL){
const char* term = getenv("TERM");
if(term == nullptr){
std::cerr << "TERM wasn't defined, exiting with success" << std::endl;
return EXIT_SUCCESS;
}
std::cout << "Running with TERM=" << term << std::endl;
doctest::Context context;
context.setOption("order-by", "name"); // sort the test cases by their name