mirror of
https://github.com/boostorg/pfr.git
synced 2026-01-19 04:22:13 +00:00
Do not require Python to run tests
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
# The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
|
||||
#
|
||||
|
||||
import python ;
|
||||
import testing ;
|
||||
import ../../config/checks/config : requires ;
|
||||
|
||||
@@ -43,13 +42,6 @@ project
|
||||
[ check-target-builds ../core_name//compiler_supports_cxx20_address_of_non_static_member_tplarg : : [ check-target-builds ../core_name//compiler_supports_cxx20_nontype_tplarg : : <build>no ] ]
|
||||
;
|
||||
|
||||
|
||||
|
||||
actions invoke_python_generator
|
||||
{
|
||||
python $(>) > $(<)
|
||||
}
|
||||
|
||||
test-suite pfr_name_tests
|
||||
:
|
||||
[ run print_name.cpp : : : <test-info>always_show_run_output ]
|
||||
@@ -57,14 +49,7 @@ test-suite pfr_name_tests
|
||||
|
||||
for local source_file in [ glob ./run/*.cpp ]
|
||||
{
|
||||
pfr_name_tests += [ run $(source_file) : : : : ] ;
|
||||
}
|
||||
|
||||
for local source_file in [ glob ./run/*.py ]
|
||||
{
|
||||
local cpp_source_file = $(source_file[1]:B) ;
|
||||
make $(cpp_source_file) : $(source_file) : @invoke_python_generator ;
|
||||
pfr_name_tests += [ run $(cpp_source_file) : : : <toolset>msvc:<cxxflags>"/utf-8" <toolset>msvc:<cxxflags>"/bigobj" : ] ;
|
||||
pfr_name_tests += [ run $(source_file) : : : <toolset>msvc:<cxxflags>"/utf-8" <toolset>msvc:<cxxflags>"/bigobj" : ] ;
|
||||
}
|
||||
|
||||
for local source_file in [ glob ./compile-fail/*.cpp ]
|
||||
|
||||
170
test/core_name/run/fields_names_big.cpp
Normal file
170
test/core_name/run/fields_names_big.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov, Antony Polukhin.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// Generated by misc/generate_fields_names_big.cpp.py
|
||||
|
||||
#include <boost/pfr/core_name.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace testing {
|
||||
|
||||
template <class... Types>
|
||||
auto make_stdarray(const Types&... t) {
|
||||
return std::array<std::common_type_t<Types...>, sizeof...(Types)>{t...};
|
||||
}
|
||||
|
||||
struct Aggregate1 {
|
||||
int EXuT_0EBItazIzOuovbOSyOYGqbJw1uQ;
|
||||
|
||||
};
|
||||
struct Aggregate2 {
|
||||
int SnihXdx4VbVTcwKm2PGOy8gBYi;
|
||||
int l_hKC0UCDgf9akyA6pr1IG;
|
||||
|
||||
};
|
||||
struct Aggregate3 {
|
||||
int GWYXwjwOCC5uOWkmZjrjk95yaOQbVfUbSJRCoQoRyPXjzp7x2c7WMwvck0JeOg;
|
||||
int xdtwasd3bFi2mErdk64LyyWKcOb5gudT50eCBMUHraYYmd8Yxp9M0pO1DmDHWQZ4LEshxseqUjzoTeuwnVwA6uvStNpN0ZtZ;
|
||||
int shqTJk7vA32s2DQB5o7TyecNLMHLUogzWYO_NwRsgX;
|
||||
|
||||
};
|
||||
struct Aggregate4 {
|
||||
int ofYcwHz8V6YMDPsHqyIB5TVZckFc3cK0Da;
|
||||
int HiGE0sOlKCO;
|
||||
int F5Nrv0LUdUSmrzLgPmtENIEe5uJQyRXC0owDVh9IjRBdA_aSEqiMx_EhWXEkbddK5MCgCv223s9EXlMc55ByxpG6XYbXS6nHywEy;
|
||||
int emjjbXYK;
|
||||
|
||||
};
|
||||
struct Aggregate5 {
|
||||
int M0u7SIZSVWJ0KqQygT_6npmZv1XzZI5dJcwjQuqq6lIdlSJSpnAKhOg82qyVywwNq3cvvmnmAv7;
|
||||
int SXEUFB6z;
|
||||
int tDxT;
|
||||
int sV2m6xg3MxKN1Xln2dXyBh8rkF7lUUfHIK8nK4FRzru2DXeT;
|
||||
int ycEXe3x03PvbXqFJzOKMq8i4XLAZfyY2i4HONhv1Wx_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
void test_get_name_1() {
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate1>())), "EXuT_0EBItazIzOuovbOSyOYGqbJw1uQ");
|
||||
|
||||
}
|
||||
void test_get_name_2() {
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate2>())), "SnihXdx4VbVTcwKm2PGOy8gBYi");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<1, Aggregate2>())), "l_hKC0UCDgf9akyA6pr1IG");
|
||||
|
||||
}
|
||||
void test_get_name_3() {
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate3>())), "GWYXwjwOCC5uOWkmZjrjk95yaOQbVfUbSJRCoQoRyPXjzp7x2c7WMwvck0JeOg");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<1, Aggregate3>())), "xdtwasd3bFi2mErdk64LyyWKcOb5gudT50eCBMUHraYYmd8Yxp9M0pO1DmDHWQZ4LEshxseqUjzoTeuwnVwA6uvStNpN0ZtZ");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<2, Aggregate3>())), "shqTJk7vA32s2DQB5o7TyecNLMHLUogzWYO_NwRsgX");
|
||||
|
||||
}
|
||||
void test_get_name_4() {
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate4>())), "ofYcwHz8V6YMDPsHqyIB5TVZckFc3cK0Da");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<1, Aggregate4>())), "HiGE0sOlKCO");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<2, Aggregate4>())), "F5Nrv0LUdUSmrzLgPmtENIEe5uJQyRXC0owDVh9IjRBdA_aSEqiMx_EhWXEkbddK5MCgCv223s9EXlMc55ByxpG6XYbXS6nHywEy");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<3, Aggregate4>())), "emjjbXYK");
|
||||
|
||||
}
|
||||
void test_get_name_5() {
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate5>())), "M0u7SIZSVWJ0KqQygT_6npmZv1XzZI5dJcwjQuqq6lIdlSJSpnAKhOg82qyVywwNq3cvvmnmAv7");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<1, Aggregate5>())), "SXEUFB6z");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<2, Aggregate5>())), "tDxT");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<3, Aggregate5>())), "sV2m6xg3MxKN1Xln2dXyBh8rkF7lUUfHIK8nK4FRzru2DXeT");
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<4, Aggregate5>())), "ycEXe3x03PvbXqFJzOKMq8i4XLAZfyY2i4HONhv1Wx_");
|
||||
|
||||
}
|
||||
|
||||
|
||||
void test_names_as_array_1() {
|
||||
const auto expected = make_stdarray(
|
||||
std::string_view{"EXuT_0EBItazIzOuovbOSyOYGqbJw1uQ"}
|
||||
|
||||
);
|
||||
const auto value = boost::pfr::names_as_array<Aggregate1>();
|
||||
BOOST_TEST_EQ(expected.size(), value.size());
|
||||
for (std::size_t i=0;i<expected.size();++i) {
|
||||
BOOST_TEST_EQ(value[i], expected[i]);
|
||||
}
|
||||
}
|
||||
void test_names_as_array_2() {
|
||||
const auto expected = make_stdarray(
|
||||
std::string_view{"SnihXdx4VbVTcwKm2PGOy8gBYi"}
|
||||
, std::string_view{"l_hKC0UCDgf9akyA6pr1IG"}
|
||||
|
||||
);
|
||||
const auto value = boost::pfr::names_as_array<Aggregate2>();
|
||||
BOOST_TEST_EQ(expected.size(), value.size());
|
||||
for (std::size_t i=0;i<expected.size();++i) {
|
||||
BOOST_TEST_EQ(value[i], expected[i]);
|
||||
}
|
||||
}
|
||||
void test_names_as_array_3() {
|
||||
const auto expected = make_stdarray(
|
||||
std::string_view{"GWYXwjwOCC5uOWkmZjrjk95yaOQbVfUbSJRCoQoRyPXjzp7x2c7WMwvck0JeOg"}
|
||||
, std::string_view{"xdtwasd3bFi2mErdk64LyyWKcOb5gudT50eCBMUHraYYmd8Yxp9M0pO1DmDHWQZ4LEshxseqUjzoTeuwnVwA6uvStNpN0ZtZ"}
|
||||
, std::string_view{"shqTJk7vA32s2DQB5o7TyecNLMHLUogzWYO_NwRsgX"}
|
||||
|
||||
);
|
||||
const auto value = boost::pfr::names_as_array<Aggregate3>();
|
||||
BOOST_TEST_EQ(expected.size(), value.size());
|
||||
for (std::size_t i=0;i<expected.size();++i) {
|
||||
BOOST_TEST_EQ(value[i], expected[i]);
|
||||
}
|
||||
}
|
||||
void test_names_as_array_4() {
|
||||
const auto expected = make_stdarray(
|
||||
std::string_view{"ofYcwHz8V6YMDPsHqyIB5TVZckFc3cK0Da"}
|
||||
, std::string_view{"HiGE0sOlKCO"}
|
||||
, std::string_view{"F5Nrv0LUdUSmrzLgPmtENIEe5uJQyRXC0owDVh9IjRBdA_aSEqiMx_EhWXEkbddK5MCgCv223s9EXlMc55ByxpG6XYbXS6nHywEy"}
|
||||
, std::string_view{"emjjbXYK"}
|
||||
|
||||
);
|
||||
const auto value = boost::pfr::names_as_array<Aggregate4>();
|
||||
BOOST_TEST_EQ(expected.size(), value.size());
|
||||
for (std::size_t i=0;i<expected.size();++i) {
|
||||
BOOST_TEST_EQ(value[i], expected[i]);
|
||||
}
|
||||
}
|
||||
void test_names_as_array_5() {
|
||||
const auto expected = make_stdarray(
|
||||
std::string_view{"M0u7SIZSVWJ0KqQygT_6npmZv1XzZI5dJcwjQuqq6lIdlSJSpnAKhOg82qyVywwNq3cvvmnmAv7"}
|
||||
, std::string_view{"SXEUFB6z"}
|
||||
, std::string_view{"tDxT"}
|
||||
, std::string_view{"sV2m6xg3MxKN1Xln2dXyBh8rkF7lUUfHIK8nK4FRzru2DXeT"}
|
||||
, std::string_view{"ycEXe3x03PvbXqFJzOKMq8i4XLAZfyY2i4HONhv1Wx_"}
|
||||
|
||||
);
|
||||
const auto value = boost::pfr::names_as_array<Aggregate5>();
|
||||
BOOST_TEST_EQ(expected.size(), value.size());
|
||||
for (std::size_t i=0;i<expected.size();++i) {
|
||||
BOOST_TEST_EQ(value[i], expected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace testing
|
||||
|
||||
int main() {
|
||||
testing::test_get_name_1();
|
||||
testing::test_get_name_2();
|
||||
testing::test_get_name_3();
|
||||
testing::test_get_name_4();
|
||||
testing::test_get_name_5();
|
||||
|
||||
testing::test_names_as_array_1();
|
||||
testing::test_names_as_array_2();
|
||||
testing::test_names_as_array_3();
|
||||
testing::test_names_as_array_4();
|
||||
testing::test_names_as_array_5();
|
||||
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
40
test/core_name/run/fields_names_nonascii.cpp
Normal file
40
test/core_name/run/fields_names_nonascii.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov, Antony Polukhin.
|
||||
//
|
||||
// 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 <boost/pfr/core_name.hpp>
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace testing {
|
||||
|
||||
struct Aggregate {
|
||||
int _πривет_мир;
|
||||
};
|
||||
|
||||
void test_get_name() {
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate>())), "_πривет_мир");
|
||||
}
|
||||
|
||||
void test_names_as_array() {
|
||||
const auto expected = std::array<std::string_view, 1>{
|
||||
"_πривет_мир"
|
||||
};
|
||||
const auto value = boost::pfr::names_as_array<Aggregate>();
|
||||
BOOST_TEST_EQ(expected.size(), value.size());
|
||||
for (std::size_t i=0;i<expected.size();++i) {
|
||||
BOOST_TEST_EQ(value[i], expected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace testing
|
||||
|
||||
int main() {
|
||||
testing::test_get_name();
|
||||
testing::test_names_as_array();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
# 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
|
||||
#
|
||||
|
||||
############################################################################################################################
|
||||
|
||||
import sys
|
||||
import string
|
||||
import random
|
||||
|
||||
# a bigger value might lead to compiler out of heap space error on MSVC
|
||||
STRUCT_COUNT = 50
|
||||
MAX_FIELD_COUNT = 50
|
||||
|
||||
MAIN_TEMPLATE = """#include <boost/pfr/core_name.hpp>
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace testing {
|
||||
|
||||
template <class... Types>
|
||||
auto make_stdarray(const Types&... t) {
|
||||
return std::array<std::common_type_t<Types...>, sizeof...(Types)>{t...};
|
||||
}
|
||||
|
||||
%STRUCTS_LIST%
|
||||
|
||||
%TEST_GET_NAME_DEFINITIONS_LIST%
|
||||
|
||||
%TEST_GET_NAMES_AS_ARRAY_DEFINITIONS_LIST%
|
||||
|
||||
|
||||
} // namespace testing
|
||||
|
||||
int main() {
|
||||
%TEST_GET_NAME_CALLS_LIST%
|
||||
%TEST_GET_NAMES_AS_ARRAY_CALLS_LIST%
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
"""
|
||||
|
||||
STRUCT_TEMPLATE = """struct Aggregate%STRUCT_ID% {
|
||||
%FIELD_DEFINITIONS_LIST%
|
||||
};
|
||||
"""
|
||||
|
||||
STRUCT_FIELD_DEFINITION_TEMPLATE = """int %FIELD_NAME%;
|
||||
"""
|
||||
|
||||
TEST_GET_NAME_TEMPLATE = """void test_get_name_%TEST_ID%() {
|
||||
%CHECKERS_LIST%
|
||||
}
|
||||
"""
|
||||
|
||||
TEST_GET_NAME_CHECKER_TEMPLATE = """BOOST_TEST_EQ( ((boost::pfr::get_name<%FIELD_ID%, Aggregate%STRUCT_ID%>())), "%FIELD_NAME%");
|
||||
"""
|
||||
|
||||
TEST_GET_NAMES_AS_ARRAY_TEMPLATE = """void test_names_as_array_%TEST_ID%() {
|
||||
const auto expected = make_stdarray(
|
||||
%FIELD_NAMES_LIST%
|
||||
);
|
||||
const auto value = boost::pfr::names_as_array<Aggregate%STRUCT_ID%>();
|
||||
BOOST_TEST_EQ(expected.size(), value.size());
|
||||
for (std::size_t i=0;i<expected.size();++i) {
|
||||
BOOST_TEST_EQ(value[i], expected[i]);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FIELD_NAME_TEMPLATE = """std::string_view{"%FIELD_NAME%"}
|
||||
"""
|
||||
|
||||
TEST_GET_NAME_CALL_TEMPLATE = """testing::test_get_name_%TEST_ID%();
|
||||
"""
|
||||
|
||||
TEST_GET_NAMES_AS_ARRAY_CALL_TEMPLATE = """testing::test_names_as_array_%TEST_ID%();
|
||||
"""
|
||||
|
||||
############################################################################################################################
|
||||
|
||||
field_names = {
|
||||
"alignas": True,
|
||||
"alignof": True,
|
||||
"and": True,
|
||||
"and_eq": True,
|
||||
"asm": True,
|
||||
"atomic_cancel": True,
|
||||
"atomic_commit": True,
|
||||
"atomic_noexcept": True,
|
||||
"auto": True,
|
||||
"bitand": True,
|
||||
"bitor": True,
|
||||
"bool": True,
|
||||
"break": True,
|
||||
"case": True,
|
||||
"catch": True,
|
||||
"char": True,
|
||||
"char8_t": True,
|
||||
"char16_t": True,
|
||||
"char32_t": True,
|
||||
"class": True,
|
||||
"compl": True,
|
||||
"concept": True,
|
||||
"const": True,
|
||||
"consteval": True,
|
||||
"constexpr": True,
|
||||
"constinit": True,
|
||||
"const_cast": True,
|
||||
"continue": True,
|
||||
"co_await": True,
|
||||
"co_return": True,
|
||||
"co_yield": True,
|
||||
"decltype": True,
|
||||
"default": True,
|
||||
"delete": True,
|
||||
"do": True,
|
||||
"double": True,
|
||||
"dynamic_cast": True,
|
||||
"else": True,
|
||||
"enum": True,
|
||||
"explicit": True,
|
||||
"export": True,
|
||||
"extern": True,
|
||||
"false": True,
|
||||
"float": True,
|
||||
"for": True,
|
||||
"friend": True,
|
||||
"goto": True,
|
||||
"if": True,
|
||||
"inline": True,
|
||||
"int": True,
|
||||
"long": True,
|
||||
"mutable": True,
|
||||
"namespace": True,
|
||||
"new": True,
|
||||
"noexcept": True,
|
||||
"not": True,
|
||||
"not_eq": True,
|
||||
"nullptr": True,
|
||||
"operator": True,
|
||||
"or": True,
|
||||
"or_eq": True,
|
||||
"private": True,
|
||||
"protected": True,
|
||||
"public": True,
|
||||
"reflexpr": True,
|
||||
"register": True,
|
||||
"reinterpret_cast": True,
|
||||
"requires": True,
|
||||
"return": True,
|
||||
"short": True,
|
||||
"signed": True,
|
||||
"sizeof": True,
|
||||
"static": True,
|
||||
"static_assert": True,
|
||||
"static_cast": True,
|
||||
"struct": True,
|
||||
"switch": True,
|
||||
"synchronized": True,
|
||||
"template": True,
|
||||
"this": True,
|
||||
"thread_local": True,
|
||||
"throw": True,
|
||||
"true": True,
|
||||
"try": True,
|
||||
"typedef": True,
|
||||
"typeid": True,
|
||||
"typename": True,
|
||||
"union": True,
|
||||
"unsigned": True,
|
||||
"using": True,
|
||||
"virtual": True,
|
||||
"void": True,
|
||||
"volatile": True,
|
||||
"wchar_t": True,
|
||||
"while": True,
|
||||
"xor": True,
|
||||
"xor_eq": True
|
||||
}
|
||||
field_names_by_id = {}
|
||||
|
||||
def generate_new_field_name():
|
||||
result = ''
|
||||
name_len = random.randint(1,100)
|
||||
result += random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_")
|
||||
for i in range(name_len-1):
|
||||
result += random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789")
|
||||
return result
|
||||
|
||||
def generate_field_name(struct_id, field_id):
|
||||
key = (struct_id, field_id)
|
||||
if not key in field_names_by_id:
|
||||
new_name = generate_new_field_name()
|
||||
while new_name in field_names:
|
||||
new_name = generate_new_field_name()
|
||||
field_names[new_name] = True
|
||||
field_names_by_id[key] = new_name
|
||||
return field_names_by_id[key]
|
||||
|
||||
def generate_struct(struct_id):
|
||||
field_definitions = ''
|
||||
fields_count = struct_id
|
||||
for i in range(fields_count):
|
||||
field_definitions += STRUCT_FIELD_DEFINITION_TEMPLATE.replace('%FIELD_NAME%', generate_field_name(struct_id, i))
|
||||
return STRUCT_TEMPLATE.replace('%FIELD_DEFINITIONS_LIST%', field_definitions).replace('%STRUCT_ID%', str(struct_id))
|
||||
|
||||
def generate_structs_list():
|
||||
result = ''
|
||||
for i in range(STRUCT_COUNT):
|
||||
result += generate_struct(i+1)
|
||||
return result
|
||||
|
||||
def generate_test_get_name_definition(struct_id):
|
||||
checkers_list = ''
|
||||
fields_count = struct_id
|
||||
for i in range(fields_count):
|
||||
checkers_list += TEST_GET_NAME_CHECKER_TEMPLATE.replace('%FIELD_ID%', str(i)).replace('%STRUCT_ID%', str(struct_id)).replace('%FIELD_NAME%', generate_field_name(struct_id, i))
|
||||
return TEST_GET_NAME_TEMPLATE.replace('%TEST_ID%', str(struct_id)).replace('%CHECKERS_LIST%', checkers_list)
|
||||
|
||||
def generate_test_get_name_definitions_list():
|
||||
result = ''
|
||||
for i in range(STRUCT_COUNT):
|
||||
result += generate_test_get_name_definition(i+1)
|
||||
return result
|
||||
|
||||
def generate_test_names_as_array_definition(struct_id):
|
||||
field_names_list = FIELD_NAME_TEMPLATE.replace('%FIELD_NAME%', generate_field_name(struct_id, 0))
|
||||
fields_count = struct_id
|
||||
for i in range(1, fields_count):
|
||||
field_names_list += ', ' + FIELD_NAME_TEMPLATE.replace('%FIELD_NAME%', generate_field_name(struct_id, i))
|
||||
return TEST_GET_NAMES_AS_ARRAY_TEMPLATE.replace('%TEST_ID%', str(struct_id)).replace('%FIELD_NAMES_LIST%', field_names_list).replace('%STRUCT_ID%', str(struct_id))
|
||||
|
||||
def generate_test_names_as_array_definitions_list():
|
||||
result = ''
|
||||
for i in range(STRUCT_COUNT):
|
||||
result += generate_test_names_as_array_definition(i+1)
|
||||
return result
|
||||
|
||||
def generate_test_get_name_calls_list():
|
||||
result = ''
|
||||
for i in range(STRUCT_COUNT):
|
||||
result += TEST_GET_NAME_CALL_TEMPLATE.replace('%TEST_ID%', str(i+1))
|
||||
return result
|
||||
|
||||
def generate_test_names_as_array_calls_list():
|
||||
result = ''
|
||||
for i in range(STRUCT_COUNT):
|
||||
result += TEST_GET_NAMES_AS_ARRAY_CALL_TEMPLATE.replace('%TEST_ID%', str(i+1))
|
||||
return result
|
||||
|
||||
print(MAIN_TEMPLATE.replace('%STRUCTS_LIST%', generate_structs_list()).replace('%TEST_GET_NAME_DEFINITIONS_LIST%', generate_test_get_name_definitions_list()).replace('%TEST_GET_NAMES_AS_ARRAY_DEFINITIONS_LIST%', generate_test_names_as_array_definitions_list()).replace('%TEST_GET_NAME_CALLS_LIST%', generate_test_get_name_calls_list()).replace('%TEST_GET_NAMES_AS_ARRAY_CALLS_LIST%', generate_test_names_as_array_calls_list()))
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
# 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
|
||||
#
|
||||
|
||||
############################################################################################################################
|
||||
|
||||
import sys
|
||||
import string
|
||||
|
||||
TEMPLATE = """#include <boost/pfr/core_name.hpp>
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace testing {
|
||||
|
||||
struct Aggregate {
|
||||
int _%ARG%;
|
||||
};
|
||||
|
||||
void test_get_name() {
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate>())), "_%ARG%");
|
||||
}
|
||||
|
||||
void test_names_as_array() {
|
||||
const auto expected = std::array<std::string_view, 1>{
|
||||
"_%ARG%"
|
||||
};
|
||||
const auto value = boost::pfr::names_as_array<Aggregate>();
|
||||
BOOST_TEST_EQ(expected.size(), value.size());
|
||||
for (std::size_t i=0;i<expected.size();++i) {
|
||||
BOOST_TEST_EQ(value[i], expected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace testing
|
||||
|
||||
int main() {
|
||||
testing::test_get_name();
|
||||
testing::test_names_as_array();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
"""
|
||||
|
||||
############################################################################################################################
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
print(TEMPLATE.replace('%ARG%', (b'\xcf\x80').decode('utf-8')))
|
||||
Reference in New Issue
Block a user