diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-10-17 21:50:24 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-10-17 21:50:24 +0800 |
| commit | 728d592f4075ae78b67dab6911ada05875a470a3 (patch) | |
| tree | 57a7232ea0a984b0344bc63a593c1dee65072d2f /test/base/StringUtilTest.cpp | |
| parent | 045462a6aed2796976a2f5cf0042f9a0ac1493f7 (diff) | |
| download | cru-728d592f4075ae78b67dab6911ada05875a470a3.tar.gz cru-728d592f4075ae78b67dab6911ada05875a470a3.tar.bz2 cru-728d592f4075ae78b67dab6911ada05875a470a3.zip | |
Fix macOS build.
Diffstat (limited to 'test/base/StringUtilTest.cpp')
| -rw-r--r-- | test/base/StringUtilTest.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
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 <catch2/catch_test_macros.hpp> +#include <string_view> 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<int>("123"); REQUIRE(r1.valid); |
