summaryrefslogtreecommitdiffhomepage
path: root/src/test-unicode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test-unicode.cpp')
-rw-r--r--src/test-unicode.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/test-unicode.cpp b/src/test-unicode.cpp
index 41fcd20..0560c1b 100644
--- a/src/test-unicode.cpp
+++ b/src/test-unicode.cpp
@@ -3,19 +3,60 @@
#include <boost/test/included/unit_test.hpp>
#include <string>
+#include <tuple>
+#include <type_traits>
#include <unicode.h>
+std::tuple<std::basic_string<char8_t>, std::basic_string<char16_t>, std::basic_string<char32_t>> t {
+ u8"Täst", u"Täst", U"Täst"
+};
+
+template<size_t i = 0, size_t j = 0, typename... Ts>
+void test_utf_to_utf(std::tuple<Ts...>& t)
+{
+ typedef typename std::tuple_element<i,typename std::remove_reference<decltype(t)>::type>::type From;
+ typedef typename std::tuple_element<j,typename std::remove_reference<decltype(t)>::type>::type To;
+
+ // test
+ To result { unicode::utf_to_utf<typename From::value_type, typename To::value_type>(std::get<i>(t)) };
+
+ BOOST_CHECK(std::get<j>(t) == result);
+
+ //std::cout << std::to_string(std::tuple_size<typename std::remove_reference<decltype(t)>::type>::value) << "," << std::to_string(i) << "," << std::to_string(j) << std::endl;
+
+ // iterate over other combinations
+ if constexpr (i + 1 < std::tuple_size<typename std::remove_reference<decltype(t)>::type>::value)
+ test_utf_to_utf<i + 1, j>(t);
+ else if constexpr (j + 1 < std::tuple_size<typename std::remove_reference<decltype(t)>::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::utf8_to_utf16(u8)};
+ std::u16string u16{unicode::utf_to_utf<char8_t, char16_t>(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<char16_t, char8_t>(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
@@ -24,3 +65,7 @@ BOOST_AUTO_TEST_CASE(utf8_to_utf16)
// 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?