stdex
Additional custom or not Standard C++ covered algorithms
Loading...
Searching...
No Matches
unicode.cpp
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2023 Amebis
4*/
5
6#include "pch.h"
7
8using namespace std;
9#ifdef _WIN32
10using namespace Microsoft::VisualStudio::CppUnitTestFramework;
11#endif
12
13namespace UnitTests
14{
15 TEST_CLASS(unicode)
16 {
17 public:
18 TEST_METHOD(str2wstr)
19 {
20 Assert::AreEqual(
21 L"This is a test.",
22 stdex::str2wstr("This is a test.", stdex::charset_id::utf8).c_str());
23 Assert::AreEqual(
24 L"Th\u00ed\u0161 i\u22c5 a te\u0073\u0304t. 😀😅",
25 stdex::str2wstr("Thíš i⋅ a tes̄t. 😀😅", stdex::charset_id::utf8).c_str());
26 Assert::AreEqual(
27 L"",
28 stdex::str2wstr("test", 0, stdex::charset_id::utf8).c_str());
29 Assert::AreEqual(
30 L"",
31 stdex::str2wstr(nullptr, 0, stdex::charset_id::utf8).c_str());
32 }
33
34 TEST_METHOD(wstr2str)
35 {
36 Assert::AreEqual(
37 "This is a test.",
38 stdex::wstr2str(L"This is a test.", stdex::charset_id::utf8).c_str());
39 Assert::AreEqual(
40 "Th\xc3\xad\xc5\xa1 i\xe2\x8b\x85 a tes\xcc\x84t. \xf0\x9f\x98\x80\xf0\x9f\x98\x85",
41 stdex::wstr2str(L"Thíš i⋅ a tes̄t. 😀😅", stdex::charset_id::utf8).c_str());
42 Assert::AreEqual(
43 "",
44 stdex::wstr2str(L"test", 0, stdex::charset_id::utf8).c_str());
45 Assert::AreEqual(
46 "",
47 stdex::wstr2str(nullptr, 0, stdex::charset_id::utf8).c_str());
48 }
49 };
50}