cell unit tests: use nccell_width()

pull/1621/head
nick black 3 years ago
parent 55837bcb55
commit 8e0173cce3
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -22,6 +22,7 @@ rearrangements of Notcurses.
For this to work properly, other threads ought also have these signals For this to work properly, other threads ought also have these signals
blocked. `notcurses_getc()` and friends thus no longer drop these signals blocked. `notcurses_getc()` and friends thus no longer drop these signals
from the provided `sigset_t`; they are instead added if not present. from the provided `sigset_t`; they are instead added if not present.
* Added `nccell_width()` to get the column length of an `nccell`.
* 2.2.8 (2021-04-18) * 2.2.8 (2021-04-18)
* All remaining functions prefixed with `cell_` or `cells_` have been * All remaining functions prefixed with `cell_` or `cells_` have been

@ -14,33 +14,30 @@ TEST_CASE("Cell") {
REQUIRE(nullptr != n_); REQUIRE(nullptr != n_);
SUBCASE("EGCs") { SUBCASE("EGCs") {
int cols, bytes; nccell c = CELL_TRIVIAL_INITIALIZER;
bytes = utf8_egc_len("é", &cols); CHECK(2 == nccell_load(n_, &c, "é"));
CHECK(2 == bytes); CHECK(1 == nccell_width(n_, &c));
CHECK(1 == cols); int cols;
bytes = utf8_egc_len("\x41\u0301", &cols); CHECK(3 == nccell_load(n_, &c, "\x41\u0301"));
CHECK(3 == bytes); CHECK(1 == nccell_width(n_, &c));
CHECK(1 == cols); CHECK(4 == nccell_load(n_, &c, " ி"));
bytes = utf8_egc_len(" ி", &cols); cols = nccell_width(n_, &c);
CHECK(4 == bytes);
#ifdef __linux__ #ifdef __linux__
CHECK(2 == cols); CHECK(2 == cols);
#else #else
CHECK(1 == cols); CHECK(1 == cols);
#endif #endif
bytes = utf8_egc_len(" ि", &cols); CHECK(4 == nccell_load(n_, &c, " ि"));
CHECK(4 == bytes); cols = nccell_width(n_, &c);
#ifdef __linux__ #ifdef __linux__
CHECK(2 == cols); CHECK(2 == cols);
#else #else
CHECK(1 == cols); CHECK(1 == cols);
#endif #endif
bytes = utf8_egc_len("◌̈", &cols); CHECK(5 == nccell_load(n_, &c, "◌̈"));
CHECK(5 == bytes); CHECK(1 == nccell_width(n_, &c));
CHECK(1 == cols); CHECK(9 == nccell_load(n_, &c, "นี้"));
bytes = utf8_egc_len("นี้", &cols); CHECK(1 == nccell_width(n_, &c));
CHECK(9 == bytes);
CHECK(1 == cols);
} }
SUBCASE("Loadchar") { SUBCASE("Loadchar") {

@ -23,14 +23,9 @@ TEST_CASE("EGCpool") {
CHECK(0 == notcurses_stop(nc_)); CHECK(0 == notcurses_stop(nc_));
SUBCASE("UTF8EGC") { SUBCASE("UTF8EGC") {
const char* wstr = ""; int c = ncstrwidth("");
int c;
auto ulen = utf8_egc_len(wstr, &c);
REQUIRE(0 < ulen);
CHECK(0 < c); CHECK(0 < c);
wstr = ""; c = ncstrwidth("");
ulen = utf8_egc_len(wstr, &c);
REQUIRE(0 < ulen);
CHECK(0 < c); CHECK(0 < c);
} }

Loading…
Cancel
Save