Skip to content

Commit 459cf9e

Browse files
committed
[New] Test both BOMed UTF-16-LE & UTF-16-BE are ok to be converted to UTF-8
1 parent 5dbb603 commit 459cf9e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

test/archlinux/aur_poc/test_unicodecvt.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,24 @@ TEST_CASE("String to utf-8 vs stringview to utf-8", "[S]")
2929
CHECK(bux::to_utf8(u32str) == (const char*)u8"一律轉成 utf-8");
3030

3131
char16_t u16str[] = u"一律轉成 utf-8";
32+
auto bomed_u16str = bux::BOM(u16str);
3233
#ifndef _WIN32
3334
static constinit const char *const CHSETS_UTF16LE[] = {"UTF-16LE", "UTF16LE", "UCS-2LE", "USC2LE", 0};
3435
CHECK(bux::to_utf8(u16str, 0, CHSETS_UTF16LE) == (const char*)u8"一律轉成 utf-8");
3536

3637
static constinit const char *const CHSETS_UTF16[] = {"UCS-2", "UTF-16", "USC2", "UTF16", 0};
3738
CHECK(bux::to_utf8(u16str, 0, CHSETS_UTF16) == (const char*)u8"一律轉成 utf-8");
39+
CHECK(bux::to_utf8(bomed_u16str) == (const char*)u8"一律轉成 utf-8");
3840
#endif
3941
CHECK(bux::to_utf8(u16str) == (const char*)u8"一律轉成 utf-8");
4042
for (auto &ch: u16str)
4143
ch = std::byteswap(ch);
44+
for (auto &ch: bomed_u16str)
45+
ch = std::byteswap(ch);
4246
#ifndef _WIN32
4347
static constinit const char *const CHSETS_UTF16BE[] = {"UTF-16BE", "UTF16BE", "UCS-2BE", "USC2BE", 0};
4448
CHECK(bux::to_utf8(u16str, 0, CHSETS_UTF16BE) == (const char*)u8"一律轉成 utf-8");
49+
CHECK(bux::to_utf8(bomed_u16str) == (const char*)u8"一律轉成 utf-8");
4550
#endif
4651
CHECK(bux::to_utf8(u16str) == (const char*)u8"一律轉成 utf-8");
4752

test/test_unicodecvt.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,24 @@ TEST_CASE("String to utf-8 vs stringview to utf-8", "[S]")
2929
CHECK(bux::to_utf8(u32str) == (const char*)u8"一律轉成 utf-8");
3030

3131
char16_t u16str[] = u"一律轉成 utf-8";
32+
auto bomed_u16str = bux::BOM(u16str);
3233
#ifndef _WIN32
3334
static constinit const char *const CHSETS_UTF16LE[] = {"UTF-16LE", "UTF16LE", "UCS-2LE", "USC2LE", 0};
3435
CHECK(bux::to_utf8(u16str, 0, CHSETS_UTF16LE) == (const char*)u8"一律轉成 utf-8");
3536

3637
static constinit const char *const CHSETS_UTF16[] = {"UCS-2", "UTF-16", "USC2", "UTF16", 0};
3738
CHECK(bux::to_utf8(u16str, 0, CHSETS_UTF16) == (const char*)u8"一律轉成 utf-8");
39+
CHECK(bux::to_utf8(bomed_u16str) == (const char*)u8"一律轉成 utf-8");
3840
#endif
3941
CHECK(bux::to_utf8(u16str) == (const char*)u8"一律轉成 utf-8");
4042
for (auto &ch: u16str)
4143
ch = std::byteswap(ch);
44+
for (auto &ch: bomed_u16str)
45+
ch = std::byteswap(ch);
4246
#ifndef _WIN32
4347
static constinit const char *const CHSETS_UTF16BE[] = {"UTF-16BE", "UTF16BE", "UCS-2BE", "USC2BE", 0};
4448
CHECK(bux::to_utf8(u16str, 0, CHSETS_UTF16BE) == (const char*)u8"一律轉成 utf-8");
49+
CHECK(bux::to_utf8(bomed_u16str) == (const char*)u8"一律轉成 utf-8");
4550
#endif
4651
CHECK(bux::to_utf8(u16str) == (const char*)u8"一律轉成 utf-8");
4752

0 commit comments

Comments
 (0)