From 3d7a431811748c5aa1f49c35436696fc3f05de5d Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 5 Feb 2021 14:10:53 +0100 Subject: Documentation, support validation via Traits --- src/test-unicode.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') 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& t) { typedef typename std::tuple_element::type>::type T; - // test + // test via basic type bool result { unicode::is_valid_utf(std::get(t)) }; - BOOST_CHECK_MESSAGE(result == true, "is_valid_utf w/ " << typeid(T).name() << "(" << i << ", " << std::get(t) << "), got " << result); + // test via Facet + result = unicode::is_valid_utf::Facet>(std::get(t)); + BOOST_CHECK_MESSAGE(result == true, "is_valid_utf w/ " << typeid(typename unicode::Encoding::Facet).name() << "(" << i << ", " << std::get(t) << "), got " << result); + // iterate over other combinations if constexpr (i + 1 < std::tuple_size::type>::value) test_is_valid_utf(t); @@ -194,6 +197,8 @@ template void test_is_valid_utf_failure(std::basic_string& s) { BOOST_CHECK_MESSAGE(unicode::is_valid_utf(s) == false, "Expected bad UTF at index: " << index << ", " << typeid(T).name()); + + BOOST_CHECK_MESSAGE(unicode::is_valid_utf::Facet>(s) == false, "Expected bad UTF at index: " << index << ", " << typeid(typename unicode::Encoding::Facet).name()); // iterate over remaining types if constexpr (index + 1 < std::tuple_size::value) @@ -331,6 +336,13 @@ BOOST_AUTO_TEST_CASE(convert) BOOST_CHECK((unicode::convert(U"abc")) == std::u16string{u"abc"}); } +BOOST_AUTO_TEST_CASE(is_valid_utf) +{ + BOOST_CHECK(unicode::is_valid_utf(u"äöü")); + + BOOST_CHECK(unicode::is_valid_utf(u8"äöü")); +} + BOOST_AUTO_TEST_CASE(string_u8string) { std::string a{"\xc3\xa4"}; -- cgit v1.2.3