From d793262beba3a113bed4c728b572a78583b43277 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 7 Jan 2023 13:59:10 -0500 Subject: AK+Everywhere: Make UTF-16 to UTF-8 converter fallible This could fail to allocate the underlying storage needed to store the UTF-8 data. Propagate this error. --- Tests/AK/TestUtf16.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Tests/AK/TestUtf16.cpp') diff --git a/Tests/AK/TestUtf16.cpp b/Tests/AK/TestUtf16.cpp index 56b2057e17..174c959e7a 100644 --- a/Tests/AK/TestUtf16.cpp +++ b/Tests/AK/TestUtf16.cpp @@ -56,14 +56,14 @@ TEST_CASE(encode_utf8) DeprecatedString utf8_string("Привет, мир! 😀 γειά σου κόσμος こんにちは世界"); auto string = MUST(AK::utf8_to_utf16(utf8_string)); Utf16View view { string }; - EXPECT_EQ(view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes), utf8_string); - EXPECT_EQ(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No), utf8_string); + EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes)), utf8_string); + EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No)), utf8_string); } { auto encoded = Array { (u16)0xd83d }; Utf16View view { encoded }; - EXPECT_EQ(view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes), "\xed\xa0\xbd"sv); - EXPECT_EQ(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No), "\ufffd"sv); + EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes)), "\xed\xa0\xbd"sv); + EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No)), "\ufffd"sv); } } @@ -269,14 +269,14 @@ TEST_CASE(substring_view) view = view.substring_view(7, 2); EXPECT(view.length_in_code_units() == 2); - EXPECT_EQ(view.to_utf8(), "😀"sv); + EXPECT_EQ(MUST(view.to_utf8()), "😀"sv); } { Utf16View view { string }; view = view.substring_view(7, 1); EXPECT(view.length_in_code_units() == 1); - EXPECT_EQ(view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes), "\xed\xa0\xbd"sv); - EXPECT_EQ(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No), "\ufffd"sv); + EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes)), "\xed\xa0\xbd"sv); + EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No)), "\ufffd"sv); } } -- cgit v1.2.3