| 1 | // Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov. |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | |
| 7 | // Initial implementation by Bela Schaum, https://github.com/schaumb |
| 8 | // The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669 |
| 9 | // |
| 10 | |
| 11 | #include <boost/pfr/core_name.hpp> |
| 12 | #include <string_view> |
| 13 | |
| 14 | #include <boost/core/lightweight_test.hpp> |
| 15 | |
| 16 | namespace testing { |
| 17 | |
| 18 | constexpr std::string_view fake_func_name = " ******************** [fake_text1->fake_text2->fake_text3] **********" ; |
| 19 | |
| 20 | void test_general() |
| 21 | { |
| 22 | namespace detail = boost::pfr::detail; |
| 23 | using detail::backward; |
| 24 | BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, "" ).apply(fake_func_name), "fake_text1->fake_text2->fake_text3" ); |
| 25 | BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, backward("->" )).apply(fake_func_name), "fake_text3" ); |
| 26 | BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, "->" ).apply(fake_func_name), "fake_text2->fake_text3" ); |
| 27 | BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, backward("->" )).apply(fake_func_name), "fake_text3" ); |
| 28 | BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, "->" ).apply(fake_func_name), "fake_text2->fake_text3" ); |
| 29 | } |
| 30 | |
| 31 | void test_identity_parser() |
| 32 | { |
| 33 | namespace detail = boost::pfr::detail; |
| 34 | using detail::backward; |
| 35 | BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, backward("" )).apply(fake_func_name), fake_func_name); |
| 36 | BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, "" ).apply(fake_func_name), fake_func_name); |
| 37 | } |
| 38 | |
| 39 | } // namespace testing |
| 40 | |
| 41 | int main() { |
| 42 | testing::test_general(); |
| 43 | testing::test_identity_parser(); |
| 44 | |
| 45 | return boost::report_errors(); |
| 46 | } |
| 47 | |
| 48 | |