From 728d592f4075ae78b67dab6911ada05875a470a3 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 17 Oct 2025 21:50:24 +0800 Subject: Fix macOS build. --- test/base/StringUtilTest.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test/base/StringUtilTest.cpp') diff --git a/test/base/StringUtilTest.cpp b/test/base/StringUtilTest.cpp index 32fd0d88..fda30627 100644 --- a/test/base/StringUtilTest.cpp +++ b/test/base/StringUtilTest.cpp @@ -1,6 +1,7 @@ #include "cru/base/StringUtil.h" #include +#include using cru::Index; using namespace cru::string; @@ -127,6 +128,50 @@ TEST_CASE("StringUtil Utf16CodePointIterator", "[string]") { REQUIRE(code_points == expected_code_points); } +TEST_CASE("StringUtil Utf8IndexCodeUnitToCodePoint", "[string]") { + std::string_view text = "aπ你🤣!"; + Index current = text.size(); + REQUIRE(Utf8IndexCodeUnitToCodePoint(text.data(), text.size(), 0) == 0); + REQUIRE(Utf8IndexCodeUnitToCodePoint(text.data(), text.size(), 1) == 1); + REQUIRE(Utf8IndexCodeUnitToCodePoint(text.data(), text.size(), 3) == 2); + REQUIRE(Utf8IndexCodeUnitToCodePoint(text.data(), text.size(), 6) == 3); + REQUIRE(Utf8IndexCodeUnitToCodePoint(text.data(), text.size(), 10) == 4); + REQUIRE(Utf8IndexCodeUnitToCodePoint(text.data(), text.size(), 11) == 5); +} + +TEST_CASE("StringUtil Utf8IndexCodePointToCodeUnit", "[string]") { + std::string_view text = "aπ你🤣!"; + Index current = text.size(); + REQUIRE(Utf8IndexCodePointToCodeUnit(text.data(), text.size(), 0) == 0); + REQUIRE(Utf8IndexCodePointToCodeUnit(text.data(), text.size(), 1) == 1); + REQUIRE(Utf8IndexCodePointToCodeUnit(text.data(), text.size(), 2) == 3); + REQUIRE(Utf8IndexCodePointToCodeUnit(text.data(), text.size(), 3) == 6); + REQUIRE(Utf8IndexCodePointToCodeUnit(text.data(), text.size(), 4) == 10); + REQUIRE(Utf8IndexCodePointToCodeUnit(text.data(), text.size(), 5) == 11); +} + +TEST_CASE("StringUtil Utf16IndexCodeUnitToCodePoint", "[string]") { + std::u16string_view text = u"aπ你🤣!"; + Index current = text.size(); + REQUIRE(Utf16IndexCodeUnitToCodePoint(text.data(), text.size(), 0) == 0); + REQUIRE(Utf16IndexCodeUnitToCodePoint(text.data(), text.size(), 1) == 1); + REQUIRE(Utf16IndexCodeUnitToCodePoint(text.data(), text.size(), 2) == 2); + REQUIRE(Utf16IndexCodeUnitToCodePoint(text.data(), text.size(), 3) == 3); + REQUIRE(Utf16IndexCodeUnitToCodePoint(text.data(), text.size(), 5) == 4); + REQUIRE(Utf16IndexCodeUnitToCodePoint(text.data(), text.size(), 6) == 5); +} + +TEST_CASE("StringUtil Utf16IndexCodePointToCodeUnit", "[string]") { + std::u16string_view text = u"aπ你🤣!"; + Index current = text.size(); + REQUIRE(Utf16IndexCodePointToCodeUnit(text.data(), text.size(), 0) == 0); + REQUIRE(Utf16IndexCodePointToCodeUnit(text.data(), text.size(), 1) == 1); + REQUIRE(Utf16IndexCodePointToCodeUnit(text.data(), text.size(), 2) == 2); + REQUIRE(Utf16IndexCodePointToCodeUnit(text.data(), text.size(), 3) == 3); + REQUIRE(Utf16IndexCodePointToCodeUnit(text.data(), text.size(), 4) == 5); + REQUIRE(Utf16IndexCodePointToCodeUnit(text.data(), text.size(), 5) == 6); +} + TEST_CASE("ParseToNumber Work", "[string]") { auto r1 = ParseToNumber("123"); REQUIRE(r1.valid); -- cgit v1.2.3