Lolly 1.4.27
Loading...
Searching...
No Matches
unicode_test.cpp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : unicode_test.cpp
4 * DESCRIPTION: tests on unicode
5 * COPYRIGHT : (C) 2023 Darcy Shen
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12#include "a_lolly_test.hpp"
14
20
21#if defined(OS_MINGW) || defined(OS_WIN)
22using lolly::data::wchar_to_utf8;
23#endif
24
25TEST_CASE ("unicode_get_range") {
26 string_eq (unicode_get_range ((int) 'a'), "ascii");
27 string_eq (unicode_get_range (0x2460), "enclosed_alphanumerics"); // ①
28 string_eq (unicode_get_range (0x24ff), "enclosed_alphanumerics"); // ⓿
29}
30
31TEST_CASE ("cjk_unified_ideographs") {
32 CHECK (is_cjk_unified_ideographs ("<#4E2D>"));
33 CHECK (has_cjk_unified_ideographs ("<#4E2D>"));
34 CHECK (has_cjk_unified_ideographs ("bib-<#4E2D>"));
35 CHECK (!is_cjk_unified_ideographs ("bib-<#4E2D>"));
36}
37
38#if defined(OS_MINGW) || defined(OS_WIN)
39TEST_CASE ("wchar to utf8") { string_eq (wchar_to_utf8 (L"中"), "中"); }
40#endif
41
42TEST_CASE ("utf16 to utf8") {
43 string t= "";
44 string_eq (utf16_to_utf8 ("\x4E\x2D"), "中");
45 t << '\x00' << '\x61';
46 string_eq (utf16_to_utf8 (t), "a");
47 t= "";
48 t << '\x00' << '\x61' << '\x00' << '\x62';
49 string_eq (utf16_to_utf8 (t), "ab");
50 t= "";
51 t << '\x00';
52 string_eq (utf16_to_utf8 (t), "");
53 t= "";
54 t << '\x00' << '\x61' << '\x00';
55 string_eq (utf16_to_utf8 (t), "a");
56}
57
58TEST_CASE ("utf8 to utf16") {
59 string t= "";
60 t << '\x4E' << '\x2D';
61 string_eq (utf8_to_utf16 ("中"), t);
62 t= "";
63 t << '\x00' << '\x61';
64 string_eq (utf8_to_utf16 ("a"), t);
65 t= "";
66 t << '\x00' << '\x61' << '\x00' << '\x62';
67 string_eq (utf8_to_utf16 ("ab"), t);
68}
blackbox t[13]
The list class represents a linked list.
Definition list.hpp:48
void string_eq(string left, string right)
string unicode_get_range(int code)
Definition unicode.cpp:99
bool is_cjk_unified_ideographs(string s)
Checks if a string contains only CJK Unified Ideographs.
Definition unicode.cpp:117
string utf16_to_utf8(string s_u16)
Convert UTF-16 string to UTF-8 string.
Definition unicode.cpp:155
string utf8_to_utf16(string s_u8)
Convert UTF-8 string to UTF-16 string.
Definition unicode.cpp:208
bool has_cjk_unified_ideographs(string s)
Checks if a string contains any CJK Unified Ideographs.
Definition unicode.cpp:136
TEST_CASE("test for operator+= and advance()")