diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/win/string.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/test/win/string.cpp b/test/win/string.cpp index 4e25f8c0..3864b987 100644 --- a/test/win/string.cpp +++ b/test/win/string.cpp @@ -4,7 +4,7 @@ using cru::platform::win::k_code_point_end; -TEST(WinString, Utf8ShouldWork) { +TEST(WinString, Utf8Iterator) { using cru::platform::win::Utf8Iterator; std::string_view text = "aπ你🤣!"; Utf8Iterator i{text}; @@ -16,7 +16,7 @@ TEST(WinString, Utf8ShouldWork) { ASSERT_EQ(i.Next(), k_code_point_end); } -TEST(WinString, Utf16ShouldWork) { +TEST(WinString, Utf16Iterator) { using cru::platform::win::Utf16Iterator; std::wstring_view text = L"aπ你🤣!"; Utf16Iterator i{text}; @@ -28,3 +28,26 @@ TEST(WinString, Utf16ShouldWork) { ASSERT_EQ(i.Next(), k_code_point_end); } +TEST(WinString, IndexUtf8ToUtf16) { + using cru::platform::win::IndexUtf8ToUtf16; + std::string_view utf8_string = "aπ你🤣!"; + std::wstring_view utf16_string = L"aπ你🤣!"; + ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 0, utf16_string), 0); + ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 1, utf16_string), 1); + ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 3, utf16_string), 2); + ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 6, utf16_string), 3); + ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 10, utf16_string), 5); + ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 11, utf16_string), 6); +} + +TEST(WinString, IndexUtf16ToUtf8) { + using cru::platform::win::IndexUtf16ToUtf8; + std::string_view utf8_string = "aπ你🤣!"; + std::wstring_view utf16_string = L"aπ你🤣!"; + ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 0, utf8_string), 0); + ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 1, utf8_string), 1); + ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 2, utf8_string), 3); + ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 3, utf8_string), 6); + ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 5, utf8_string), 10); + ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 6, utf8_string), 11); +} |