Skip to content

Commit

Permalink
Add more UTF-8 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Feb 7, 2025
1 parent 2ff7fb0 commit a44f0b0
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions test/utf8_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,46 @@
namespace devilution {
namespace {

TEST(DecodeFirstUtf8CodePointTest, OneByteCodePoint)
{
size_t len;
char32_t cp = DecodeFirstUtf8CodePoint("a", &len);
EXPECT_EQ(cp, U'a');
EXPECT_EQ(len, 1);
}

TEST(DecodeFirstUtf8CodePointTest, TwoByteCodePoint)
{
size_t len;
char32_t cp = DecodeFirstUtf8CodePoint("ж", &len);
EXPECT_EQ(cp, U'ж');
EXPECT_EQ(len, 2);
}

TEST(DecodeFirstUtf8CodePointTest, ThreeByteCodePoint)
{
size_t len;
char32_t cp = DecodeFirstUtf8CodePoint("", &len);
EXPECT_EQ(cp, U'');
EXPECT_EQ(len, 3);
}

TEST(DecodeFirstUtf8CodePointTest, FourByteCodePoint)
{
size_t len;
char32_t cp = DecodeFirstUtf8CodePoint("💡", &len);
EXPECT_EQ(cp, U'💡');
EXPECT_EQ(len, 4);
}

TEST(DecodeFirstUtf8CodePointTest, InvalidCodePoint)
{
size_t len;
char32_t cp = DecodeFirstUtf8CodePoint("\xc3\x28", &len);
EXPECT_EQ(cp, Utf8DecodeError);
EXPECT_EQ(len, 1);
}

TEST(AppendUtf8Test, OneByteCodePoint)
{
std::string s = "x";
Expand All @@ -30,8 +70,8 @@ TEST(AppendUtf8Test, ThreeByteCodePoint)
TEST(AppendUtf8Test, FourByteCodePoint)
{
std::string s;
AppendUtf8(U'', s);
EXPECT_EQ(s, "");
AppendUtf8(U'💡', s);
EXPECT_EQ(s, "💡");
}

TEST(Utf8CodeUnits, ValidCodePoints)
Expand Down

0 comments on commit a44f0b0

Please sign in to comment.