mirror of
https://github.com/boostorg/yap.git
synced 2026-02-24 16:42:09 +00:00
Add first real standalone test, of print().
This commit is contained in:
18
test/CMakeLists.txt
Normal file
18
test/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
include(CTest)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -VV -C ${CMAKE_CFG_INTDIR})
|
||||
|
||||
include_directories(
|
||||
${CMAKE_HOME_DIRECTORY}
|
||||
${CMAKE_HOME_DIRECTORY}/googletest-release-1.8.0/googletest/include
|
||||
)
|
||||
|
||||
macro(add_test_executable name)
|
||||
add_executable(${name} ${name}.cpp)
|
||||
target_link_libraries(${name} gtest gtest_main)
|
||||
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name} --gtest_catch_exceptions=1)
|
||||
endmacro()
|
||||
|
||||
add_test_executable(print)
|
||||
138
test/print.cpp
Normal file
138
test/print.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
#include "expression.hpp"
|
||||
|
||||
#define BOOST_PROTO17_STREAM_OPERATORS
|
||||
#include "print.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
template <typename T>
|
||||
using term = boost::proto17::terminal<T>;
|
||||
|
||||
namespace bp17 = boost::proto17;
|
||||
|
||||
|
||||
TEST(print, test_print)
|
||||
{
|
||||
term<double> unity{1.0};
|
||||
int i_ = 42;
|
||||
term<int &&> i{std::move(i_)};
|
||||
bp17::expression<
|
||||
bp17::expr_kind::plus,
|
||||
term<double>,
|
||||
term<int &&>
|
||||
> expr = unity + std::move(i);
|
||||
bp17::expression<
|
||||
bp17::expr_kind::plus,
|
||||
term<double>,
|
||||
bp17::expression<
|
||||
bp17::expr_kind::plus,
|
||||
term<double>,
|
||||
term<int &&>
|
||||
>
|
||||
> unevaluated_expr = unity + std::move(expr);
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
bp17::print(oss, unity);
|
||||
EXPECT_EQ(oss.str(), R"(term<double>[=1]
|
||||
)");
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
bp17::print(oss, expr);
|
||||
EXPECT_EQ(oss.str(), R"(expr<+>
|
||||
term<double>[=1]
|
||||
term<int &&>[=42]
|
||||
)");
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
bp17::print(oss, unevaluated_expr);
|
||||
EXPECT_EQ(oss.str(), R"(expr<+>
|
||||
term<double>[=1]
|
||||
expr<+>
|
||||
term<double>[=1]
|
||||
term<int &&>[=42]
|
||||
)");
|
||||
}
|
||||
|
||||
struct thing {};
|
||||
term<thing> a_thing(thing{});
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
bp17::print(oss, a_thing);
|
||||
EXPECT_EQ(oss.str(), R"(term<print_test_print_Test::TestBody()::thing>[=<<unprintable-value>>]
|
||||
)");
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::proto17::literals;
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << (0_p + unity);
|
||||
EXPECT_EQ(oss.str(), R"(expr<+>
|
||||
placeholder<0>
|
||||
term<double>[=1]
|
||||
)");
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << (2_p + 3_p);
|
||||
EXPECT_EQ(oss.str(), R"(expr<+>
|
||||
placeholder<2>
|
||||
placeholder<3>
|
||||
)");
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << (unity + 1_p);
|
||||
EXPECT_EQ(oss.str(), R"(expr<+>
|
||||
term<double>[=1]
|
||||
placeholder<1>
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << unity;
|
||||
EXPECT_EQ(oss.str(), R"(term<double>[=1]
|
||||
)");
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << expr;
|
||||
EXPECT_EQ(oss.str(), R"(expr<+>
|
||||
term<double>[=1]
|
||||
term<int &&>[=42]
|
||||
)");
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << unevaluated_expr;
|
||||
EXPECT_EQ(oss.str(), R"(expr<+>
|
||||
term<double>[=1]
|
||||
expr<+>
|
||||
term<double>[=1]
|
||||
term<int &&>[=42]
|
||||
)");
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << a_thing;
|
||||
EXPECT_EQ(oss.str(), R"(term<print_test_print_Test::TestBody()::thing>[=<<unprintable-value>>]
|
||||
)");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user