Skip to content

Commit

Permalink
Added tests for UTF16BE SIMD
Browse files Browse the repository at this point in the history
  • Loading branch information
R533-Code committed Sep 18, 2024
1 parent ae3b21b commit 2248a15
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/dsa/test_unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
COLT_CONCAT(x, "End of tests!")
// clang-format on

struct MAKE_BE{};

template<size_t N>
const clt::Char16Other* operator+(MAKE_BE, const char16_t (&str)[N])
{
auto ret = new char16_t[N];
for (size_t i = 0; i < N; i++)
ret[i] = clt::bit::byteswap(str[i]);
return reinterpret_cast<clt::Char16Other*>(ret);
}

#define TEST_STRING8 TEST_STRING(u8)
#define TEST_STRING16 TEST_STRING(u)
#define TEST_STRING32 TEST_STRING(U)
Expand All @@ -68,6 +79,10 @@ TEST_CASE("Unicode Length")
REQUIRE( \
strlen(value) \
== simdutf::count_utf16(value, ((sizeof value) / sizeof(value[0]) - 1)));
#define TEST_STRLEN16OTHER(value) \
REQUIRE( \
strlen(MAKE_BE{} + value) \
== simdutf::count_utf16(value, ((sizeof value) / sizeof(value[0]) - 1)));

#define TEST_STRLEN32(value) \
REQUIRE(strlen(value) == (sizeof value) / sizeof(value[0]) - 1);
Expand All @@ -80,6 +95,10 @@ TEST_CASE("Unicode Length")
{
COLT_FOR_EACH(TEST_STRLEN16, TEST_STRING16);
}
SECTION("UTF16 Other")
{
COLT_FOR_EACH(TEST_STRLEN16OTHER, TEST_STRING16);
}
SECTION("UTF32")
{
COLT_FOR_EACH(TEST_STRLEN32, TEST_STRING32);
Expand Down Expand Up @@ -140,6 +159,8 @@ TEST_CASE("Unicode Size")

#define TEST_UNITLEN(value) \
REQUIRE(unitlen(value) == ((sizeof value) / sizeof(value[0]) - 1));
#define TEST_UNITLEN16OTHER(value) \
REQUIRE(unitlen(MAKE_BE{} + value) == ((sizeof value) / sizeof(value[0]) - 1));

SECTION("UTF8")
{
Expand All @@ -149,6 +170,10 @@ TEST_CASE("Unicode Size")
{
COLT_FOR_EACH(TEST_UNITLEN, TEST_STRING16);
}
SECTION("UTF16 Other")
{
COLT_FOR_EACH(TEST_UNITLEN16OTHER, TEST_STRING16);
}
SECTION("UTF32")
{
COLT_FOR_EACH(TEST_UNITLEN, TEST_STRING32);
Expand Down

0 comments on commit 2248a15

Please sign in to comment.