From fad8b697dff7c7b47f034124ea6eef25e74bd7af Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 26 Jan 2021 22:05:08 +0100 Subject: Implement conversion and first tests --- src/test-unicode.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'src') 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 #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::utf8_to_utf16(u8)}; + 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 @@ -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? -- cgit v1.2.3