add libunistring unit tests #906

This commit is contained in:
nick black 2020-08-24 15:30:17 -04:00
parent f2d92b0f05
commit af80914efe
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
4 changed files with 63 additions and 18 deletions

View File

@ -575,6 +575,7 @@ target_include_directories(notcurses-tester
)
target_link_libraries(notcurses-tester
PRIVATE
unistring
notcurses++
"${TERMINFO_LIBRARIES}"
)

View File

@ -33,6 +33,7 @@ const char* oiio_version(void);
#include <pthread.h>
#include <termios.h>
#include <stdbool.h>
#include <unictype.h>
#include <langinfo.h>
#include "notcurses/notcurses.h"
#include "egcpool.h"
@ -921,6 +922,23 @@ pool_load(egcpool* pool, cell* c, const char* gcluster){
// increment y by 1 and rotate the framebuffer up one line. x moves to 0.
void scroll_down(ncplane* n);
static inline bool
islinebreak(wchar_t wchar){
// UC_LINE_SEPARATOR + UC_PARAGRAPH_SEPARATOR
if(wchar == L'\n' || wchar == L'\v' || wchar == L'\f'){
return true;
}
const uint32_t mask = UC_CATEGORY_MASK_Zl | UC_CATEGORY_MASK_Zp;
return uc_is_general_category_withtable(wchar, mask);
}
static inline bool
iswordbreak(wchar_t wchar){
const uint32_t mask = UC_CATEGORY_MASK_Z |
UC_CATEGORY_MASK_Zs;
return uc_is_general_category_withtable(wchar, mask);
}
#ifdef __cplusplus
}
#endif

View File

@ -1,22 +1,4 @@
#include "internal.h"
#include <unictype.h>
static bool
islinebreak(wchar_t wchar){
// UC_LINE_SEPARATOR + UC_PARAGRAPH_SEPARATOR
if(wchar == '\n'){
return true;
}
const uint32_t mask = UC_CATEGORY_MASK_Zl | UC_CATEGORY_MASK_Zp;
return uc_is_general_category_withtable(wchar, mask);
}
static bool
iswordbreak(wchar_t wchar){
const uint32_t mask = UC_CATEGORY_MASK_Z |
UC_CATEGORY_MASK_Zs;
return uc_is_general_category_withtable(wchar, mask);
}
// print the first 'bytes' bytes of 'text' to 'n', using alignment 'align'
// and requiring 'cols' columns, relative to the current cursor position.

44
tests/libunistring.cpp Normal file
View File

@ -0,0 +1,44 @@
#include "main.h"
#include "internal.h"
// some simple tests to ensure the libunistring we've compiled/linked against
// behaves as expected.
TEST_CASE("Libunistring") {
auto nc_ = testing_notcurses();
if(!nc_){
return;
}
ncplane* ncp_ = notcurses_stdplane(nc_);
REQUIRE(ncp_);
SUBCASE("WordbreakChars") {
const wchar_t breakers[] = {
L'\u0020', // space
L'\u2000', // en quad
L'\u2001', // em quad
L'\u2002', // en quad
L'\u2003', // em quad
L'\u2004', // three-per-em space
0
}, *b;
for(b = breakers ; *b ; ++b){
CHECK(iswordbreak(*b));
}
}
SUBCASE("LinebreakChars") {
const wchar_t breakers[] = {
L'\u000a', // linefeed
L'\u000b', // vertical tab
L'\u000c', // formfeed
0
}, *b;
for(b = breakers ; *b ; ++b){
CHECK(islinebreak(*b));
}
}
CHECK(0 == notcurses_stop(nc_));
}