ncplane_puttext: more unit tests, check for spcae before width #691

pull/723/head
nick black 4 years ago
parent d7b04217f9
commit 6ff0bec2fa
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -1521,14 +1521,6 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
}
return -1;
}
width = wcwidth(w);
if(width < 0){
logerror(n->nc, "Non-printable UTF-8 after %zu bytes\n", text - beginning);
if(bytes){
*bytes = text - beginning;
}
return -1;
}
// FIXME use the more advanced unicode functionality to break lines
if(iswspace(w)){
if(x == 0){
@ -1539,6 +1531,14 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
breaker = text;
}
}
width = wcwidth(w);
if(width < 0){
logerror(n->nc, "Non-printable UTF-8 after %zu bytes\n", text - beginning);
if(bytes){
*bytes = text - beginning;
}
return -1;
}
if(x + width > dimx){
break;
}

@ -86,7 +86,7 @@ TEST_CASE("TextLayout") {
}
// lay out text where a word is longer than the plane
SUBCASE("LayoutCrossBoundary") {
SUBCASE("LayoutTransPlanar") {
auto sp = ncplane_new(nc_, 3, 10, 0, 0, nullptr);
REQUIRE(sp);
size_t bytes;
@ -96,6 +96,40 @@ TEST_CASE("TextLayout") {
CHECK(bytes == strlen(boundstr));
char* line = ncplane_contents(sp, 0, 0, -1, -1);
REQUIRE(line);
// FIXME i think i'd prefer that this printed what it could of thermo
// on the first line, and continued it on the second, since it has to
// break the word anyway...then we'd get "my thermonuclear arms"
CHECK(0 == strcmp(line, "mythermonuclear arms"));
free(line);
ncplane_destroy(sp);
}
// lay out text where a word is longer than the plane
SUBCASE("LayoutTransPlanar") {
auto sp = ncplane_new(nc_, 3, 10, 0, 0, nullptr);
REQUIRE(sp);
size_t bytes;
const char boundstr[] = "my thermonuclear arms";
CHECK(0 < ncplane_puttext(sp, 0, NCALIGN_CENTER, boundstr, &bytes));
CHECK(0 == notcurses_render(nc_));
CHECK(bytes == strlen(boundstr));
char* line = ncplane_contents(sp, 0, 0, -1, -1);
REQUIRE(line);
CHECK(0 == strcmp(line, "mythermonuclear arms"));
free(line);
ncplane_destroy(sp);
}
SUBCASE("LayoutLeadingSpaces") {
auto sp = ncplane_new(nc_, 3, 10, 0, 0, nullptr);
REQUIRE(sp);
size_t bytes;
const char boundstr[] = " \t\n my thermonuclear arms";
CHECK(0 < ncplane_puttext(sp, 0, NCALIGN_CENTER, boundstr, &bytes));
CHECK(0 == notcurses_render(nc_));
CHECK(bytes == strlen(boundstr));
char* line = ncplane_contents(sp, 0, 0, -1, -1);
REQUIRE(line);
CHECK(0 == strcmp(line, "mythermonuclear arms"));
free(line);
ncplane_destroy(sp);

Loading…
Cancel
Save