// 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 template using term = boost::yap::terminal; template using ref = boost::yap::expression_ref; namespace yap = boost::yap; namespace bh = boost::hana; TEST(expression_function, test_lvalue) { term number = {{42}}; auto fn = yap::make_expression_function(number); auto fn_copy = fn; EXPECT_EQ(fn(), 42); EXPECT_EQ(fn_copy(), 42); yap::value(number) = 21; EXPECT_EQ(fn(), 21); EXPECT_EQ(fn_copy(), 21); } TEST(expression_function, test_rvalue) { term number = {{42}}; auto fn = yap::make_expression_function(std::move(number)); auto fn_copy = fn; EXPECT_EQ(fn(), 42); EXPECT_EQ(fn_copy(), 42); yap::value(number) = 21; EXPECT_EQ(fn(), 42); EXPECT_EQ(fn_copy(), 42); } TEST(expression_function, test_move_only_rvalue) { term> number = {{std::unique_ptr(new int(42))}}; auto fn = yap::make_expression_function(std::move(number)); EXPECT_EQ(*fn(), 42); auto fn_2 = std::move(fn); EXPECT_EQ(*fn_2(), 42); yap::value(number) = std::unique_ptr(new int(21)); EXPECT_EQ(*fn_2(), 42); }