#define BOOST_TEST_MODULE unicode_test #include #include #include #include #include std::tuple, std::basic_string, std::basic_string> t { u8"Täst", u"Täst", U"Täst" }; template void test_utf_to_utf(std::tuple& t) { typedef typename std::tuple_element::type>::type From; typedef typename std::tuple_element::type>::type To; // test To result { unicode::utf_to_utf(std::get(t)) }; BOOST_CHECK(std::get(t) == result); //std::cout << std::to_string(std::tuple_size::type>::value) << "," << std::to_string(i) << "," << std::to_string(j) << std::endl; // iterate over other combinations if constexpr (i + 1 < std::tuple_size::type>::value) test_utf_to_utf(t); else if constexpr (j + 1 < std::tuple_size::type>::value) test_utf_to_utf<0, j + 1>(t); } BOOST_AUTO_TEST_CASE(utf_to_utf) { test_utf_to_utf(t); } BOOST_AUTO_TEST_CASE(utf8_to_utf16) { std::u8string u8{u8"ascii string1"}; std::u16string u16{unicode::utf_to_utf(u8)}; BOOST_CHECK(u16 == u"ascii string1"); } BOOST_AUTO_TEST_CASE(utf16_to_utf8) { std::u16string u16{u"ascii string1"}; std::u8string u8{unicode::utf_to_utf(u16)}; BOOST_CHECK(u8 == u8"ascii string1"); } // TODO: // UTF-8 // invalid bytes // an unexpected continuation byte // a non-continuation byte before the end of the character // the string ending before the end of the character (which can happen in simple string truncation) // an overlong encoding // a sequence that decodes to an invalid code point // // high and low surrogate halves used by UTF-16 (U+D800 through U+DFFF) and code points not encodable by UTF-16 (those after U+10FFFF) // // char8_t, char16_t, char32_t, char, wchar_t (UTF-16 on Windows, UTF-32 on Linux) // string, vector? // uint8_t, uint16_t, uint32_t?