From 7ac3f68f4e28b9284b582115ebe4af8bb1d6ada1 Mon Sep 17 00:00:00 2001 From: nick black Date: Mon, 3 Aug 2020 20:33:10 -0400 Subject: [PATCH] cell_load: fix CELL_WIDEASIAN_MASK bug --- src/lib/notcurses.c | 1 - tests/wide.cpp | 30 +++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 177d1aa36..363643e22 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1377,7 +1377,6 @@ cell_load_direct(ncplane* n, cell* c, const char* gcluster, int bytes, int cols) } if(bytes <= 4){ cell_release(n, c); - c->channels &= ~CELL_WIDEASIAN_MASK; c->gcluster = 0; memcpy(&c->gcluster, gcluster, bytes); return bytes; diff --git a/tests/wide.cpp b/tests/wide.cpp index fd24404a0..0ba658c22 100644 --- a/tests/wide.cpp +++ b/tests/wide.cpp @@ -110,15 +110,19 @@ TEST_CASE("Wide") { CHECK(0 < ncplane_putegc_yx(n_, 1, 0, w, &sbytes)); cell c = CELL_TRIVIAL_INITIALIZER; ncplane_at_yx_cell(n_, 0, 0, &c); - const char* wres = extended_gcluster(n_, &c); + char* wres = cell_strdup(n_, &c); + REQUIRE(nullptr != wres); CHECK(0 == strcmp(wres, FROG)); + free(wres); ncplane_at_yx_cell(n_, 0, 1, &c); CHECK(mbswidth(FROG) == 1 + cell_double_wide_p(&c)); // should be wide ncplane_at_yx_cell(n_, 0, 2, &c); CHECK(0 == c.gcluster); // should be nothing ncplane_at_yx_cell(n_, 1, 0, &c); - wres = extended_gcluster(n_, &c); + wres = cell_strdup(n_, &c); + REQUIRE(nullptr != wres); CHECK(0 == strcmp(wres, FROG)); + free(wres); ncplane_at_yx_cell(n_, 1, 1, &c); CHECK(mbswidth(FROG) == 1 + cell_double_wide_p(&c)); //should be wide ncplane_at_yx_cell(n_, 0, 2, &c); @@ -146,8 +150,10 @@ TEST_CASE("Wide") { CHECK(0 == c.gcluster); // should be nothing } ncplane_at_yx_cell(n_, 0, 1, &c); - const char* wres = extended_gcluster(n_, &c); + char* wres = cell_strdup(n_, &c); + REQUIRE(nullptr != wres); CHECK(0 == strcmp(wres, SNAKE)); + free(wres); ncplane_at_yx_cell(n_, 0, 2, &c); CHECK(mbswidth(SNAKE) == 1 + cell_double_wide_p(&c)); // should be wide CHECK(0 == notcurses_render(nc_)); @@ -200,15 +206,19 @@ TEST_CASE("Wide") { CHECK(3 == x); cell c = CELL_TRIVIAL_INITIALIZER; ncplane_at_yx_cell(n_, 0, 0, &c); - const char* wres = extended_gcluster(n_, &c); + char* wres = cell_strdup(n_, &c); + REQUIRE(nullptr != wres); CHECK(0 == strcmp(wres, SNAKE)); + free(wres); ncplane_at_yx_cell(n_, 0, 1, &c); CHECK(mbswidth(SNAKE) == 1 + cell_double_wide_p(&c)); ncplane_at_yx_cell(n_, 0, 2, &c); CHECK(cc == c.gcluster); // should be 'X' ncplane_at_yx_cell(n_, 0, 3, &c); - wres = extended_gcluster(n_, &c); + wres = cell_strdup(n_, &c); + REQUIRE(nullptr != wres); CHECK(0 == strcmp(wres, SCORPION)); + free(wres); ncplane_at_yx_cell(n_, 0, 4, &c); CHECK(mbswidth(SCORPION) == 1 + cell_double_wide_p(&c)); CHECK(0 == notcurses_render(nc_)); @@ -224,14 +234,20 @@ TEST_CASE("Wide") { CHECK(0 == notcurses_render(nc_)); cell c = CELL_TRIVIAL_INITIALIZER; REQUIRE(0 < ncplane_at_yx_cell(ncp, 1, 0, &c)); - CHECK(!strcmp(cell_extended_gcluster(ncp, &c), "│")); + auto cstr = cell_strdup(ncp, &c); + REQUIRE(nullptr != cstr); + CHECK(!strcmp(cstr, "│")); + free(cstr); cell_release(ncp, &c); char* egc = notcurses_at_yx(nc_, 1, 0, &c.attrword, &c.channels); REQUIRE(egc); CHECK(!strcmp(egc, "│")); free(egc); REQUIRE(0 < ncplane_at_yx_cell(ncp, 1, 3, &c)); - CHECK(!strcmp(cell_extended_gcluster(ncp, &c), "│")); + cstr = cell_strdup(ncp, &c); + REQUIRE(nullptr != cstr); + CHECK(!strcmp(cstr, "│")); + free(cstr); cell_release(ncp, &c); egc = notcurses_at_yx(nc_, 1, 3, &c.attrword, &c.channels); REQUIRE(egc);