@@ -96,6 +96,27 @@ TEST_CASE(from_utf8)
9696 }
9797}
9898
99+ TEST_CASE (from_utf8_with_replacement_character)
100+ {
101+ auto string1 = Utf16String::from_utf8_with_replacement_character (" long string \xf4\x8f\xbf\xc0 " sv, Utf16String::WithBOMHandling::No); // U+110000
102+ EXPECT_EQ (string1, u" long string \ufffd\ufffd\ufffd\ufffd " sv);
103+
104+ auto string3 = Utf16String::from_utf8_with_replacement_character (" A valid string!" sv, Utf16String::WithBOMHandling::No);
105+ EXPECT_EQ (string3, " A valid string!" sv);
106+
107+ auto string4 = Utf16String::from_utf8_with_replacement_character (" " sv, Utf16String::WithBOMHandling::No);
108+ EXPECT_EQ (string4, " " sv);
109+
110+ auto string5 = Utf16String::from_utf8_with_replacement_character (" \xEF\xBB\xBF WHF!" sv, Utf16String::WithBOMHandling::Yes);
111+ EXPECT_EQ (string5, " WHF!" sv);
112+
113+ auto string6 = Utf16String::from_utf8_with_replacement_character (" \xEF\xBB\xBF WHF!" sv, Utf16String::WithBOMHandling::No);
114+ EXPECT_EQ (string6, u" \ufeff WHF!" sv);
115+
116+ auto string7 = Utf16String::from_utf8_with_replacement_character (" \xED\xA0\x80 WHF!" sv); // U+D800
117+ EXPECT_EQ (string7, u" \ufffd WHF!" sv);
118+ }
119+
99120TEST_CASE (from_utf16)
100121{
101122 {
@@ -235,6 +256,32 @@ TEST_CASE(from_utf32)
235256 }
236257}
237258
259+ TEST_CASE (from_code_point)
260+ {
261+ u32 code_point = 0 ;
262+
263+ for (; code_point < AK::UnicodeUtils::FIRST_SUPPLEMENTARY_PLANE_CODE_POINT; ++code_point) {
264+ auto string = Utf16String::from_code_point (code_point);
265+ EXPECT_EQ (string.length_in_code_units (), 1uz);
266+ EXPECT_EQ (string.length_in_code_points (), 1uz);
267+ EXPECT_EQ (string.code_point_at (0 ), code_point);
268+ EXPECT_EQ (string.code_unit_at (0 ), code_point);
269+ }
270+
271+ for (; code_point < AK::UnicodeUtils::FIRST_SUPPLEMENTARY_PLANE_CODE_POINT + 10'000 ; ++code_point) {
272+ auto string = Utf16String::from_code_point (code_point);
273+ EXPECT_EQ (string.length_in_code_units (), 2uz);
274+ EXPECT_EQ (string.length_in_code_points (), 1uz);
275+ EXPECT_EQ (string.code_point_at (0 ), code_point);
276+
277+ size_t i = 0 ;
278+ (void )AK::UnicodeUtils::code_point_to_utf16 (code_point, [&](auto code_unit) {
279+ EXPECT_EQ (string.code_unit_at (i++), code_unit);
280+ });
281+ EXPECT_EQ (i, 2uz);
282+ }
283+ }
284+
238285TEST_CASE (formatted)
239286{
240287 {
0 commit comments