diff options
Diffstat (limited to 'test/base')
-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); |