more TaB unit tests #1233

This commit is contained in:
nick black 2022-02-11 03:21:48 -05:00 committed by nick black
parent 6bf37089a1
commit 25b94c021d
2 changed files with 88 additions and 3 deletions

View File

@ -727,6 +727,7 @@ typedef struct nccell {
// protect against such misuse here. problems *will* ensue. similarly, do not
// set channel flags other than colors/alpha. we assign non-printing glyphs
// a width of 1 to match utf8_egc_len()'s behavior for whitespace/NUL.
// FIXME can we enforce this with static_assert?
#define NCCELL_INITIALIZER(c, s, chan) { .gcluster = (htole(c)), .gcluster_backstop = 0,\
.width = (uint8_t)((wcwidth(c) < 0 || !c) ? 1 : wcwidth(c)), .stylemask = (s), .channels = (chan), }
// python fails on #define CELL_CHAR_INITIALIZER(c) CELL_INITIALIZER(c, 0, 0)

View File

@ -9,12 +9,96 @@ TEST_CASE("TaBs") { // refreshing and delicious
struct ncplane* n_ = notcurses_stdplane(nc_);
REQUIRE(n_);
// FIXME these ought all use a specific plane to avoid requirements on the stdplane
SUBCASE("PutcTaB") {
struct ncplane_options nopts{};
nopts.rows = 2;
nopts.cols = 80;
auto n = ncplane_create(n_, &nopts);
unsigned y, x;
CHECK(1 == ncplane_putchar(n_, '\n'));
ncplane_cursor_yx(n_, &y, &x);
CHECK(y == 8);
CHECK(1 == ncplane_putchar(n, '\t'));
ncplane_cursor_yx(n, &y, &x);
CHECK(y == 0);
CHECK(x == 8);
for(unsigned i = 0 ; i < x ; ++i){
char* c = ncplane_at_yx(n, 0, i, nullptr, nullptr);
REQUIRE(c);
CHECK(0 == strcmp(c, " "));
free(c);
}
}
SUBCASE("PutwcTaB") {
struct ncplane_options nopts{};
nopts.rows = 2;
nopts.cols = 80;
auto n = ncplane_create(n_, &nopts);
unsigned y, x;
CHECK(1 == ncplane_putwc(n, L'\t'));
ncplane_cursor_yx(n, &y, &x);
CHECK(y == 0);
CHECK(x == 8);
for(unsigned i = 0 ; i < x ; ++i){
char* c = ncplane_at_yx(n, 0, i, nullptr, nullptr);
REQUIRE(c);
CHECK(0 == strcmp(c, " "));
free(c);
}
}
SUBCASE("PutCellTaB") {
struct ncplane_options nopts{};
nopts.rows = 2;
nopts.cols = 80;
auto n = ncplane_create(n_, &nopts);
nccell c = NCCELL_CHAR_INITIALIZER('\t');
unsigned y, x;
CHECK(1 == ncplane_putc(n, &c));
ncplane_cursor_yx(n, &y, &x);
CHECK(y == 0);
CHECK(x == 8);
for(unsigned i = 0 ; i < x ; ++i){
char* s = ncplane_at_yx(n, 0, i, nullptr, nullptr);
REQUIRE(s);
CHECK(0 == strcmp(s, " "));
free(s);
}
}
SUBCASE("PutMultipleTaBs") {
struct ncplane_options nopts{};
nopts.rows = 2;
nopts.cols = 80;
auto n = ncplane_create(n_, &nopts);
unsigned y, x;
CHECK(1 == ncplane_putstr(n, "\t\t"));
ncplane_cursor_yx(n, &y, &x);
CHECK(y == 0);
CHECK(x == 16);
for(unsigned i = 0 ; i < x ; ++i){
char* c = ncplane_at_yx(n, 0, i, nullptr, nullptr);
REQUIRE(c);
CHECK(0 == strcmp(c, " "));
free(c);
}
}
SUBCASE("PutRowOfTaBs") {
struct ncplane_options nopts{};
nopts.rows = 2;
nopts.cols = 80;
auto n = ncplane_create(n_, &nopts);
unsigned y, x;
CHECK(1 == ncplane_putstr(n, "\t\t\t\t\t\t\t\t\t\t"));
ncplane_cursor_yx(n, &y, &x);
CHECK(y == 1);
CHECK(x == 0);
for(unsigned i = 0 ; i < ncplane_dim_x(n) ; ++i){
char* c = ncplane_at_yx(n, 0, i, nullptr, nullptr);
REQUIRE(c);
CHECK(0 == strcmp(c, " "));
free(c);
}
}
CHECK(0 == notcurses_stop(nc_));