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.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/test-unicode.cpp b/src/test-unicode.cpp
index 5529d2c..692dfac 100644
--- a/src/test-unicode.cpp
+++ b/src/test-unicode.cpp
@@ -130,11 +130,14 @@ void test_is_valid_utf(std::tuple<Ts...>& t)
{
typedef typename std::tuple_element<i,typename std::remove_reference<decltype(t)>::type>::type T;
- // test
+ // test via basic type
bool result { unicode::is_valid_utf<typename T::value_type>(std::get<i>(t)) };
-
BOOST_CHECK_MESSAGE(result == true, "is_valid_utf w/ " << typeid(T).name() << "(" << i << ", " << std::get<i>(t) << "), got " << result);
+ // test via Facet
+ result = unicode::is_valid_utf<typename unicode::Encoding<typename T::value_type>::Facet>(std::get<i>(t));
+ BOOST_CHECK_MESSAGE(result == true, "is_valid_utf w/ " << typeid(typename unicode::Encoding<typename T::value_type>::Facet).name() << "(" << i << ", " << std::get<i>(t) << "), got " << result);
+
// iterate over other combinations
if constexpr (i + 1 < std::tuple_size<typename std::remove_reference<decltype(t)>::type>::value)
test_is_valid_utf<i + 1>(t);
@@ -194,6 +197,8 @@ template<typename T, typename Collection, size_t index = 0>
void test_is_valid_utf_failure(std::basic_string<T>& s)
{
BOOST_CHECK_MESSAGE(unicode::is_valid_utf<T>(s) == false, "Expected bad UTF at index: " << index << ", " << typeid(T).name());
+
+ BOOST_CHECK_MESSAGE(unicode::is_valid_utf<typename unicode::Encoding<T>::Facet>(s) == false, "Expected bad UTF at index: " << index << ", " << typeid(typename unicode::Encoding<T>::Facet).name());
// iterate over remaining types
if constexpr (index + 1 < std::tuple_size<Collection>::value)
@@ -331,6 +336,13 @@ BOOST_AUTO_TEST_CASE(convert)
BOOST_CHECK((unicode::convert<char32_t,char16_t>(U"abc")) == std::u16string{u"abc"});
}
+BOOST_AUTO_TEST_CASE(is_valid_utf)
+{
+ BOOST_CHECK(unicode::is_valid_utf<char16_t>(u"äöü"));
+
+ BOOST_CHECK(unicode::is_valid_utf<unicode::UTF_8>(u8"äöü"));
+}
+
BOOST_AUTO_TEST_CASE(string_u8string)
{
std::string a{"\xc3\xa4"};