From 8e0173cce362afb47c740253aac2ebf8ead3c694 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 1 May 2021 20:04:46 -0400 Subject: [PATCH] cell unit tests: use nccell_width() --- NEWS.md | 1 + src/tests/cell.cpp | 31 ++++++++++++++----------------- src/tests/egcpool.cpp | 9 ++------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/NEWS.md b/NEWS.md index 6540aee1d..b2baaf07d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,6 +22,7 @@ rearrangements of Notcurses. For this to work properly, other threads ought also have 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. + * Added `nccell_width()` to get the column length of an `nccell`. * 2.2.8 (2021-04-18) * All remaining functions prefixed with `cell_` or `cells_` have been diff --git a/src/tests/cell.cpp b/src/tests/cell.cpp index 82951cb7a..1624d3b8e 100644 --- a/src/tests/cell.cpp +++ b/src/tests/cell.cpp @@ -14,33 +14,30 @@ TEST_CASE("Cell") { REQUIRE(nullptr != n_); SUBCASE("EGCs") { - int cols, bytes; - bytes = utf8_egc_len("é", &cols); - CHECK(2 == bytes); - CHECK(1 == cols); - bytes = utf8_egc_len("\x41\u0301", &cols); - CHECK(3 == bytes); - CHECK(1 == cols); - bytes = utf8_egc_len(" ி", &cols); - CHECK(4 == bytes); + nccell c = CELL_TRIVIAL_INITIALIZER; + CHECK(2 == nccell_load(n_, &c, "é")); + CHECK(1 == nccell_width(n_, &c)); + int cols; + CHECK(3 == nccell_load(n_, &c, "\x41\u0301")); + CHECK(1 == nccell_width(n_, &c)); + CHECK(4 == nccell_load(n_, &c, " ி")); + cols = nccell_width(n_, &c); #ifdef __linux__ CHECK(2 == cols); #else CHECK(1 == cols); #endif - bytes = utf8_egc_len(" ि", &cols); - CHECK(4 == bytes); + CHECK(4 == nccell_load(n_, &c, " ि")); + cols = nccell_width(n_, &c); #ifdef __linux__ CHECK(2 == cols); #else CHECK(1 == cols); #endif - bytes = utf8_egc_len("◌̈", &cols); - CHECK(5 == bytes); - CHECK(1 == cols); - bytes = utf8_egc_len("นี้", &cols); - CHECK(9 == bytes); - CHECK(1 == cols); + CHECK(5 == nccell_load(n_, &c, "◌̈")); + CHECK(1 == nccell_width(n_, &c)); + CHECK(9 == nccell_load(n_, &c, "นี้")); + CHECK(1 == nccell_width(n_, &c)); } SUBCASE("Loadchar") { diff --git a/src/tests/egcpool.cpp b/src/tests/egcpool.cpp index 16d22ab95..acaa50f32 100644 --- a/src/tests/egcpool.cpp +++ b/src/tests/egcpool.cpp @@ -23,14 +23,9 @@ TEST_CASE("EGCpool") { CHECK(0 == notcurses_stop(nc_)); SUBCASE("UTF8EGC") { - const char* wstr = "☢"; - int c; - auto ulen = utf8_egc_len(wstr, &c); - REQUIRE(0 < ulen); + int c = ncstrwidth("☢"); CHECK(0 < c); - wstr = "▓"; - ulen = utf8_egc_len(wstr, &c); - REQUIRE(0 < ulen); + c = ncstrwidth("▓"); CHECK(0 < c); }