1// Copyright 2021 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/describe/enum_to_string.hpp>
6#include <boost/describe/enum.hpp>
7#include <boost/core/lightweight_test.hpp>
8
9#if !defined(BOOST_DESCRIBE_CXX14)
10
11#include <boost/config/pragma_message.hpp>
12
13BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available")
14int main() {}
15
16#else
17
18enum E1 { v1 };
19BOOST_DESCRIBE_ENUM(E1, v1)
20
21enum class E2 { v2 };
22BOOST_DESCRIBE_ENUM(E2, v2)
23
24BOOST_DEFINE_ENUM(E3, v3)
25BOOST_DEFINE_ENUM_CLASS(E4, v4)
26
27int main()
28{
29 using boost::describe::enum_to_string;
30
31 BOOST_TEST_CSTR_EQ( enum_to_string( v1, "" ), "v1" );
32 BOOST_TEST_CSTR_EQ( enum_to_string( E2::v2, "" ), "v2" );
33 BOOST_TEST_CSTR_EQ( enum_to_string( static_cast<E2>( 14 ), "__def__" ), "__def__" );
34 BOOST_TEST_CSTR_EQ( enum_to_string( v3, "" ), "v3" );
35 BOOST_TEST_CSTR_EQ( enum_to_string( E4::v4, "" ), "v4" );
36 BOOST_TEST_EQ( enum_to_string( static_cast<E4>( 14 ), 0 ), static_cast<char const*>( 0 ) );
37
38 return boost::report_errors();
39}
40
41#endif // !defined(BOOST_DESCRIBE_CXX14)
42

source code of boost/libs/describe/test/enum_to_string_test.cpp