From b5e35922f1095a16fd4c7f8d2ec4b182df178dde Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 8 Feb 2024 14:04:15 +0100 Subject: [PATCH] string: revert emojis in unit test Actually, using ill-created locale was the cause sprintf returned EILSEQ on %ls inserts containing emoji. Signed-off-by: Simon Rozman --- UnitTests/string.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/UnitTests/string.cpp b/UnitTests/string.cpp index 10680c94a..ab2612c19 100644 --- a/UnitTests/string.cpp +++ b/UnitTests/string.cpp @@ -17,25 +17,26 @@ namespace UnitTests public: TEST_METHOD(sprintf) { - Assert::AreEqual(L"This is a test.", stdex::sprintf(L"This is %ls.", stdex::locale_default, L"a test").c_str()); - Assert::AreEqual(15, stdex::sprintf(L"This is %ls.", stdex::locale_default, L"a test").size()); - Assert::AreEqual("This is a test.", stdex::sprintf("This is %s.", stdex::locale_default, "a test").c_str()); - Assert::AreEqual(15, stdex::sprintf("This is %s.", stdex::locale_default, "a test").size()); + stdex::locale locale(stdex::create_locale(LC_ALL, "en_US.UTF-8")); - // swprintf functions return EILSEQ when %ls inserts contain emoji on Mac. 😢 - Assert::AreEqual(L"This is a tést.", stdex::sprintf(L"This is %ls.", stdex::locale_default, L"a tést").c_str()); - Assert::AreEqual("This is a 🐔Test🐮.", stdex::sprintf("This is %s.", stdex::locale_default, "a 🐔Test🐮").c_str()); + Assert::AreEqual(L"This is a test.", stdex::sprintf(L"This is %ls.", locale, L"a test").c_str()); + Assert::AreEqual(15, stdex::sprintf(L"This is %ls.", locale, L"a test").size()); + Assert::AreEqual("This is a test.", stdex::sprintf("This is %s.", locale, "a test").c_str()); + Assert::AreEqual(15, stdex::sprintf("This is %s.", locale, "a test").size()); + + Assert::AreEqual(L"This is a 🐔Test🐮.", stdex::sprintf(L"This is %ls.", locale, L"a 🐔Test🐮").c_str()); + Assert::AreEqual("This is a 🐔Test🐮.", stdex::sprintf("This is %s.", locale, "a 🐔Test🐮").c_str()); wstring wstr; std::string str; - for (size_t i = 0; i < 2000; i++) { - wstr += L"tést\r\n"; + for (size_t i = 0; i < 200; i++) { + wstr += L"🐔Test🐮\r\n"; str += "🐔Test🐮\r\n"; } - Assert::AreEqual(wstr.c_str(), stdex::sprintf(L"%ls", stdex::locale_default, wstr.data()).c_str()); - Assert::AreEqual(wstr.size(), stdex::sprintf(L"%ls", stdex::locale_default, wstr.data()).size()); - Assert::AreEqual(str.c_str(), stdex::sprintf("%s", stdex::locale_utf8, str.data()).c_str()); - Assert::AreEqual(str.size(), stdex::sprintf("%s", stdex::locale_utf8, str.data()).size()); + Assert::AreEqual(wstr.c_str(), stdex::sprintf(L"%ls", locale, wstr.data()).c_str()); + Assert::AreEqual(wstr.size(), stdex::sprintf(L"%ls", locale, wstr.data()).size()); + Assert::AreEqual(str.c_str(), stdex::sprintf("%s", locale, str.data()).c_str()); + Assert::AreEqual(str.size(), stdex::sprintf("%s", locale, str.data()).size()); } }; }