From 5a09fcc35eee90e7e85b0256cccc4b398e976fc0 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 21 Jul 2017 14:27:30 -0700 Subject: [PATCH] Some basic unit tests for string truncation --- unit.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unit.cpp b/unit.cpp index 2a1a151..24c3fb1 100644 --- a/unit.cpp +++ b/unit.cpp @@ -10,3 +10,11 @@ TEST_CASE("UTF-8 enforcement", "[utf8]") { REQUIRE(check_utf8("๐Ÿ‘‹๐ŸŒ") == std::string("")); REQUIRE(check_utf8("Hola m\xF3n") == std::string("\"Hola m\xF3n\" is not valid UTF-8 (0xF3 0x6E)")); } + +TEST_CASE("UTF-8 truncation", "[trunc]") { + REQUIRE(truncate16("0123456789abcdefghi", 16) == std::string("0123456789abcdef")); + REQUIRE(truncate16("0123456789รฉรฎรดรผรฉรฎรดรผรง", 16) == std::string("0123456789รฉรฎรดรผรฉรฎ")); + REQUIRE(truncate16("0123456789๐Ÿ˜€๐Ÿ˜ฌ๐Ÿ˜๐Ÿ˜‚๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜…๐Ÿ˜†", 16) == std::string("0123456789๐Ÿ˜€๐Ÿ˜ฌ๐Ÿ˜")); + REQUIRE(truncate16("0123456789๐Ÿ˜€๐Ÿ˜ฌ๐Ÿ˜๐Ÿ˜‚๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜…๐Ÿ˜†", 17) == std::string("0123456789๐Ÿ˜€๐Ÿ˜ฌ๐Ÿ˜")); + REQUIRE(truncate16("0123456789ใ‚ใ„ใ†ใˆใŠใ‹ใใใ‘ใ“ใ•", 16) == std::string("0123456789ใ‚ใ„ใ†ใˆใŠใ‹")); +}