2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-19 04:22:13 +00:00

Parser might be explicitly tagged as backward

This commit is contained in:
denzor200
2023-09-03 02:12:25 +03:00
parent fcfca74355
commit dbbfa6ea7f
6 changed files with 162 additions and 16 deletions

View File

@@ -62,6 +62,8 @@ test-suite pfr_name_tests
[ run fields_names_constexpr.cpp : : : : ]
[ run fields_names_nonascii.cpp : : : <toolset>msvc:<cxxflags>"/utf-8" : ]
[ run fields_names_big.cpp : : : <toolset>msvc:<cxxflags>"/bigobj" : ]
[ run fields_names_correctly_configured_compiler.cpp : : : : ]
[ run fields_names_internal_parser.cpp : : : : ]
[ run print_name.cpp : : : <test-info>always_show_run_output ]
;

View File

@@ -0,0 +1,21 @@
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
//
// 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)
// Initial implementation by Bela Schaum, https://github.com/schaumb
// The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
//
#define BOOST_PFR_FUNCTION_SIGNATURE "dummy"
#define BOOST_PFR_CORE_NAME_PARSING (3,2,false,"")
#include <boost/pfr/core_name.hpp>
struct A { int field; };
int main() {
(void)boost::pfr::get_name<0, A>(); // Must be a compile time error
}

View File

@@ -0,0 +1,25 @@
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
//
// 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)
// Initial implementation by Bela Schaum, https://github.com/schaumb
// The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
//
#define BOOST_PFR_FUNCTION_SIGNATURE " *[field] "
#define BOOST_PFR_CORE_NAME_PARSING (3,2,false,"")
#include <boost/pfr/core_name.hpp>
#include <boost/core/lightweight_test.hpp>
struct A { int field; };
int main() {
BOOST_TEST_EQ( ((boost::pfr::get_name<0,A>())), "field");
return boost::report_errors();
}

View File

@@ -0,0 +1,58 @@
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
//
// 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)
// Initial implementation by Bela Schaum, https://github.com/schaumb
// The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
//
#include <boost/pfr/core_name.hpp>
#include <string_view>
#include <boost/core/lightweight_test.hpp>
namespace testing
{
constexpr std::string_view fake_func_name = " ******************** [fake_text1->fake_text2->fake_text3] **********";
void test_general()
{
namespace detail = boost::pfr::detail;
using detail::backward;
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, false, "").apply(fake_func_name), "fake_text1->fake_text2->fake_text3");
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, backward("->")).apply(fake_func_name), "fake_text3");
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, "->").apply(fake_func_name), "fake_text2->fake_text3");
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, true, backward("->")).apply(fake_func_name), "fake_text3");
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, true, "->").apply(fake_func_name), "fake_text2->fake_text3");
}
void test_undefided_parser()
{
namespace detail = boost::pfr::detail;
using detail::backward;
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, backward("")).apply(fake_func_name), "");
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, "").apply(fake_func_name), "");
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, true, backward("")).apply(fake_func_name), "");
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, true, "").apply(fake_func_name), "");
}
void test_identity_parser()
{
namespace detail = boost::pfr::detail;
using detail::backward;
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, false, backward("")).apply(fake_func_name), fake_func_name);
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, false, "").apply(fake_func_name), fake_func_name);
}
}
int main() {
testing::test_general();
testing::test_undefided_parser();
testing::test_identity_parser();
return boost::report_errors();
}