6
6
7
7
\*******************************************************************/
8
8
9
- #include < cassert>
9
+ #include < testing-utils/catch.hpp>
10
+
10
11
#include < vector>
11
12
#include < string>
12
13
#include < codecvt>
13
- #include < iomanip>
14
- #include < iostream>
15
14
#include < locale>
16
15
17
16
#include < util/unicode.h>
18
17
19
18
// This unit test compares our implementation with codecvt implementation,
20
19
// checking bit-by-bit equivalence of results.
21
20
22
- bool paranoid_wstr_equals (const std::wstring &a, const std::wstring &b)
21
+ static bool paranoid_wstr_equals (const std::wstring &a, const std::wstring &b)
23
22
{
24
23
if (a.size () != b.size ())
25
24
return false ;
@@ -35,7 +34,10 @@ bool paranoid_wstr_equals(const std::wstring &a, const std::wstring &b)
35
34
}
36
35
37
36
// helper print function, can be called for debugging problem
38
- void wstr_print (const std::wstring &a, const std::wstring &b)
37
+ #if 0
38
+ #include <iostream>
39
+
40
+ static void wstr_print(const std::wstring &a, const std::wstring &b)
39
41
{
40
42
int endi=(a.size()>b.size())?a.size():b.size();
41
43
const unsigned char
@@ -49,19 +51,20 @@ void wstr_print(const std::wstring &a, const std::wstring &b)
49
51
}
50
52
std::cout << '\n';
51
53
}
54
+ #endif
52
55
53
- void compare_utf8_to_utf16_big_endian (std::string& in)
56
+ static bool compare_utf8_to_utf16_big_endian (const std::string & in)
54
57
{
55
58
std::wstring s1=utf8_to_utf16_big_endian (in);
56
59
57
60
typedef std::codecvt_utf8_utf16<wchar_t > codecvt_utf8_utf16t;
58
61
std::wstring_convert<codecvt_utf8_utf16t> converter;
59
62
std::wstring s2=converter.from_bytes (in);
60
63
61
- assert ( paranoid_wstr_equals (s1, s2) );
64
+ return paranoid_wstr_equals (s1, s2);
62
65
}
63
66
64
- void compare_utf8_to_utf16_little_endian (std::string& in)
67
+ static bool compare_utf8_to_utf16_little_endian (const std::string & in)
65
68
{
66
69
std::wstring s1=utf8_to_utf16_little_endian (in);
67
70
@@ -72,23 +75,33 @@ void compare_utf8_to_utf16_little_endian(std::string& in)
72
75
std::wstring_convert<codecvt_utf8_utf16t> converter;
73
76
std::wstring s2=converter.from_bytes (in);
74
77
75
- assert (paranoid_wstr_equals (s1, s2));
78
+ return paranoid_wstr_equals (s1, s2);
79
+ }
80
+
81
+ TEST_CASE (" unicode1" , " [core][util][unicode]" )
82
+ {
83
+ const std::string s = u8" \u0070\u00DF\u00E0\u00EF\u00F0\u00F7\u00F8 " ;
84
+ REQUIRE (compare_utf8_to_utf16_big_endian (s));
85
+ REQUIRE (compare_utf8_to_utf16_little_endian (s));
86
+ }
87
+
88
+ TEST_CASE (" unicode2" , " [core][util][unicode]" )
89
+ {
90
+ const std::string s = u8" $¢€𐍈" ;
91
+ REQUIRE (compare_utf8_to_utf16_big_endian (s));
92
+ REQUIRE (compare_utf8_to_utf16_little_endian (s));
76
93
}
77
94
78
- int main ( )
95
+ TEST_CASE ( " unicode3 " , " [core][util][unicode] " )
79
96
{
80
- std::string s;
81
- s=u8" \u0070\u00DF\u00E0\u00EF\u00F0\u00F7\u00F8 " ;
82
- compare_utf8_to_utf16_big_endian (s);
83
- compare_utf8_to_utf16_little_endian (s);
84
- s=u8" $¢€𐍈" ;
85
- compare_utf8_to_utf16_big_endian (s);
86
- compare_utf8_to_utf16_little_endian (s);
87
- s=u8" 𐐏𤭢" ;
88
- compare_utf8_to_utf16_big_endian (s);
89
- compare_utf8_to_utf16_little_endian (s);
90
- s=u8" дȚȨɌṡʒʸͼἨѶݔݺ→⅒⅀▤▞╢◍⛳⻥龍ンㄗㄸ" ;
91
- compare_utf8_to_utf16_big_endian (s);
92
- compare_utf8_to_utf16_little_endian (s);
97
+ const std::string s = u8" 𐐏𤭢" ;
98
+ REQUIRE (compare_utf8_to_utf16_big_endian (s));
99
+ REQUIRE (compare_utf8_to_utf16_little_endian (s));
93
100
}
94
101
102
+ TEST_CASE (" unicode4" , " [core][util][unicode]" )
103
+ {
104
+ const std::string s = u8" дȚȨɌṡʒʸͼἨѶݔݺ→⅒⅀▤▞╢◍⛳⻥龍ンㄗㄸ" ;
105
+ REQUIRE (compare_utf8_to_utf16_big_endian (s));
106
+ REQUIRE (compare_utf8_to_utf16_little_endian (s));
107
+ }
0 commit comments