| 598 | |
| 599 | template< class... Context > |
| 600 | static |
| 601 | void |
| 602 | testNonThrowing( Context const& ... ctx ) |
| 603 | { |
| 604 | // using result |
| 605 | { |
| 606 | // clang 3.8 seems to have some bug when dealing with a lot of |
| 607 | // template instantiations; this assert magically makes the problem |
| 608 | // go away, I assume, by instantiating the needed types beforehand |
| 609 | BOOST_CORE_STATIC_ASSERT(( |
| 610 | detail::conversion_round_trips< |
| 611 | mp11::mp_first< mp11::mp_list<Context..., int> >, |
| 612 | ::value_to_test_ns::T2, |
| 613 | detail::value_to_conversion |
| 614 | >::value)); |
| 615 | |
| 616 | auto res = try_value_to<::value_to_test_ns::T2>( |
| 617 | value(), ctx... ); |
| 618 | BOOST_TEST( res.has_error() ); |
| 619 | BOOST_TEST( res.error() == error::syntax ); |
| 620 | |
| 621 | res = try_value_to<::value_to_test_ns::T2>( |
| 622 | value("T2"), ctx... ); |
| 623 | BOOST_TEST( res.has_value() ); |
| 624 | } |
| 625 | // throwing overload falls back to nonthrowing customization |
| 626 | { |
| 627 | BOOST_TEST_THROWS( |
| 628 | value_to<::value_to_test_ns::T2>( value(), ctx... ), |
| 629 | system::system_error); |
| 630 | } |
| 631 | // nonthrowing overload falls back to throwing customization |
| 632 | { |
| 633 | auto res = try_value_to<::value_to_test_ns::T3>( |
| 634 | value(), ctx... ); |
| 635 | BOOST_TEST( res.has_error() ); |
| 636 | BOOST_TEST( res.error() == error::not_string ); |
| 637 | |
| 638 | res = try_value_to<::value_to_test_ns::T3>( |
| 639 | value(""), ctx... ); |
| 640 | BOOST_TEST( res.has_error() ); |
| 641 | BOOST_TEST( res.error() == error::exception ); |
| 642 | |
| 643 | res = try_value_to<::value_to_test_ns::T3>( |
| 644 | value("T3"), ctx... ); |
| 645 | BOOST_TEST( res.has_value() ); |
| 646 | } |
| 647 | // sequence |
| 648 | { |
| 649 | // wrong input type |
| 650 | { |
| 651 | auto res = try_value_to< std::vector<::value_to_test_ns::T2> >( |
| 652 | value("not an array"), ctx... ); |
| 653 | BOOST_TEST( res.has_error() ); |
| 654 | BOOST_TEST( res.error().has_location() ); |
| 655 | BOOST_TEST( res.error() == error::not_array ); |
| 656 | } |
| 657 | |