[ncplane_puttext] unit test for newline while growing plane #2446

This commit is contained in:
nick black 2021-12-09 17:01:26 -05:00 committed by nick black
parent ba1fbbee90
commit adcdef6288
2 changed files with 41 additions and 1 deletions

View File

@ -18,7 +18,9 @@ auto testing_notcurses() -> struct notcurses* {
// get loglevel from command line. enabling it by default leads to
// more confusion than useful information, so leave it off by default.
nopts.loglevel = cliloglevel;
nopts.flags = NCOPTION_SUPPRESS_BANNERS | NCOPTION_NO_ALTERNATE_SCREEN;
nopts.flags = NCOPTION_SUPPRESS_BANNERS
| NCOPTION_NO_ALTERNATE_SCREEN
| NCOPTION_DRAIN_INPUT;
auto nc = notcurses_init(&nopts, nullptr);
return nc;
}

View File

@ -653,6 +653,44 @@ TEST_CASE("TextLayout") {
CHECK(0 == ncplane_destroy(sp));
}
// test that multiple new lines are treated as such, both on the plane
// originally, and in any autogrown region.
SUBCASE("MultipleNewlines") {
struct ncplane_options nopts{};
nopts.rows = 3;
nopts.cols = 10;
nopts.flags = NCPLANE_OPTION_VSCROLL | NCPLANE_OPTION_AUTOGROW;
auto nn = ncplane_create(n_, &nopts);
REQUIRE(nn);
size_t b;
CHECK(0 == ncplane_puttext(nn, -1, NCALIGN_LEFT, "\n\n", &b));
unsigned y, x;
ncplane_cursor_yx(nn, &y, &x);
CHECK(2 == y);
CHECK(0 == x);
CHECK(3 == ncplane_puttext(nn, -1, NCALIGN_LEFT, "erp", &b));
ncplane_cursor_yx(nn, &y, &x);
CHECK(2 == y);
CHECK(3 == x);
CHECK(0 == notcurses_render(nc_));
CHECK(0 == ncplane_puttext(nn, -1, NCALIGN_LEFT, "\n", &b));
ncplane_cursor_yx(nn, &y, &x);
CHECK(3 == y);
CHECK(0 == x);
CHECK(0 == notcurses_render(nc_));
CHECK(0 == ncplane_puttext(nn, -1, NCALIGN_LEFT, "\n\n", &b));
ncplane_cursor_yx(nn, &y, &x);
CHECK(5 == y);
CHECK(0 == x);
CHECK(0 == notcurses_render(nc_));
CHECK(3 == ncplane_puttext(nn, -1, NCALIGN_LEFT, "erp\n", &b));
ncplane_cursor_yx(nn, &y, &x);
CHECK(6 == y);
CHECK(0 == x);
CHECK(0 == notcurses_render(nc_));
CHECK(0 == ncplane_destroy(nn));
}
CHECK(0 == notcurses_stop(nc_));
}