From 40bc8c7955e486b654704a1a3d2472977ecc439f Mon Sep 17 00:00:00 2001 From: patrick96 Date: Wed, 10 May 2023 16:18:23 +0200 Subject: [PATCH] Test utf8_to_ucs4 error correction --- tests/unit_tests/utils/string.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/unit_tests/utils/string.cpp b/tests/unit_tests/utils/string.cpp index 428e648f..e95be7c4 100644 --- a/tests/unit_tests/utils/string.cpp +++ b/tests/unit_tests/utils/string.cpp @@ -266,4 +266,19 @@ TEST_P(Utf8ToUCS4InvalidTest, correctness) { EXPECT_FALSE(success); EXPECT_EQ(0, result_list.size()); } + +/** + * Tests that the conversion works with partially valid strings and that invalid parts are dropped. + */ +TEST(String, utf8ToUCS4Partial) { + string_util::unicode_charlist result_list{}; + string str = "\xe0\x70\x80"; // a valid ascii character between two invalid characters + bool success = string_util::utf8_to_ucs4(str, result_list); + EXPECT_FALSE(success); + EXPECT_EQ(1, result_list.size()); + + EXPECT_EQ(0x70, result_list[0].codepoint); + EXPECT_EQ(1, result_list[0].offset); + EXPECT_EQ(1, result_list[0].length); +} // }}}