// Copyright (C) 2016-2018 T. Zachary Laine // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include template using term = boost::yap::terminal; template using term_ref = boost::yap::expression_ref &>; template using term_cref = boost::yap::expression_ref const &>; namespace yap = boost::yap; namespace bh = boost::hana; struct callable { int operator()() { return 42; } }; struct exception_1 {}; struct exception_2 {}; struct throwing_callable_1 { int operator()() { throw exception_1{}; return 0; } }; struct throwing_callable_2 { int operator()() { throw exception_2{}; return 0; } }; TEST(if_else, test) { { auto true_nothrow_throw_expr = if_else( term{{true}}, term{}(), term{}()); EXPECT_NO_THROW(yap::evaluate(true_nothrow_throw_expr)); EXPECT_EQ(yap::evaluate(true_nothrow_throw_expr), 42); } { auto false_nothrow_throw_expr = if_else( term{{false}}, term{}(), term{}()); EXPECT_THROW(yap::evaluate(false_nothrow_throw_expr), exception_1); } { auto true_throw1_throw2_expr = if_else( term{{true}}, term{}(), term{}()); EXPECT_THROW(yap::evaluate(true_throw1_throw2_expr), exception_1); } { auto false_throw1_throw2_expr = if_else( term{{false}}, term{}(), term{}()); EXPECT_THROW(yap::evaluate(false_throw1_throw2_expr), exception_2); } }