mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
add libunistring unit tests #906
This commit is contained in:
parent
f2d92b0f05
commit
af80914efe
@ -575,6 +575,7 @@ target_include_directories(notcurses-tester
|
|||||||
)
|
)
|
||||||
target_link_libraries(notcurses-tester
|
target_link_libraries(notcurses-tester
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
unistring
|
||||||
notcurses++
|
notcurses++
|
||||||
"${TERMINFO_LIBRARIES}"
|
"${TERMINFO_LIBRARIES}"
|
||||||
)
|
)
|
||||||
|
@ -33,6 +33,7 @@ const char* oiio_version(void);
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <unictype.h>
|
||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
#include "notcurses/notcurses.h"
|
#include "notcurses/notcurses.h"
|
||||||
#include "egcpool.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.
|
// increment y by 1 and rotate the framebuffer up one line. x moves to 0.
|
||||||
void scroll_down(ncplane* n);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,22 +1,4 @@
|
|||||||
#include "internal.h"
|
#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'
|
// print the first 'bytes' bytes of 'text' to 'n', using alignment 'align'
|
||||||
// and requiring 'cols' columns, relative to the current cursor position.
|
// and requiring 'cols' columns, relative to the current cursor position.
|
||||||
|
44
tests/libunistring.cpp
Normal file
44
tests/libunistring.cpp
Normal 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_));
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user