simplify tests
This commit is contained in:
parent
6b7665c329
commit
af8bcb9fe5
@ -176,13 +176,7 @@ TEST(CompileTest, TextAndArg) {
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <size_t max_string_length> struct constexpr_buffer_helper {
|
||||
template <typename Func>
|
||||
constexpr constexpr_buffer_helper& modify(Func func) {
|
||||
func(buffer);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <size_t max_string_length> struct test_string {
|
||||
template <typename T> constexpr bool operator==(const T& rhs) const noexcept {
|
||||
return (std::string_view(rhs).compare(buffer.data()) == 0);
|
||||
}
|
||||
@ -190,69 +184,52 @@ template <size_t max_string_length> struct constexpr_buffer_helper {
|
||||
std::array<char, max_string_length> buffer{};
|
||||
};
|
||||
|
||||
template <size_t max_string_length, typename... Args>
|
||||
consteval auto test_format(auto format, const Args&... args) {
|
||||
test_string<max_string_length> string{};
|
||||
fmt::format_to(string.buffer.data(), format, args...);
|
||||
return string;
|
||||
}
|
||||
|
||||
TEST(CompileTimeFormattingTest, Bool) {
|
||||
{
|
||||
constexpr auto result =
|
||||
constexpr_buffer_helper<5>{}.modify([](auto& buffer) {
|
||||
fmt::format_to(buffer.data(), FMT_COMPILE("{}"), true);
|
||||
});
|
||||
constexpr auto result = test_format<5>(FMT_COMPILE("{}"), true);
|
||||
EXPECT_EQ(result, "true");
|
||||
}
|
||||
{
|
||||
constexpr auto result =
|
||||
constexpr_buffer_helper<6>{}.modify([](auto& buffer) {
|
||||
fmt::format_to(buffer.data(), FMT_COMPILE("{}"), false);
|
||||
});
|
||||
constexpr auto result = test_format<6>(FMT_COMPILE("{}"), false);
|
||||
EXPECT_EQ(result, "false");
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CompileTimeFormattingTest, Integer) {
|
||||
{
|
||||
constexpr auto result =
|
||||
constexpr_buffer_helper<3>{}.modify([](auto& buffer) {
|
||||
fmt::format_to(buffer.data(), FMT_COMPILE("{}"), 42);
|
||||
});
|
||||
constexpr auto result = test_format<3>(FMT_COMPILE("{}"), 42);
|
||||
EXPECT_EQ(result, "42");
|
||||
}
|
||||
{
|
||||
constexpr auto result =
|
||||
constexpr_buffer_helper<4>{}.modify([](auto& buffer) {
|
||||
fmt::format_to(buffer.data(), FMT_COMPILE("{}"), 420);
|
||||
});
|
||||
constexpr auto result = test_format<4>(FMT_COMPILE("{}"), 420);
|
||||
EXPECT_EQ(result, "420");
|
||||
}
|
||||
{
|
||||
constexpr auto result =
|
||||
constexpr_buffer_helper<6>{}.modify([](auto& buffer) {
|
||||
fmt::format_to(buffer.data(), FMT_COMPILE("{} {}"), 42, 42);
|
||||
});
|
||||
constexpr auto result = test_format<6>(FMT_COMPILE("{} {}"), 42, 42);
|
||||
EXPECT_EQ(result, "42 42");
|
||||
}
|
||||
{
|
||||
constexpr auto result =
|
||||
constexpr_buffer_helper<6>{}.modify([=](auto& buffer) {
|
||||
fmt::format_to(buffer.data(), FMT_COMPILE("{} {}"), uint32_t{42},
|
||||
uint64_t{42});
|
||||
});
|
||||
test_format<6>(FMT_COMPILE("{} {}"), uint32_t{42}, uint64_t{42});
|
||||
EXPECT_EQ(result, "42 42");
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CompileTimeFormattingTest, String) {
|
||||
{
|
||||
constexpr auto result =
|
||||
constexpr_buffer_helper<3>{}.modify([](auto& buffer) {
|
||||
fmt::format_to(buffer.data(), FMT_COMPILE("{}"), "42");
|
||||
});
|
||||
constexpr auto result = test_format<3>(FMT_COMPILE("{}"), "42");
|
||||
EXPECT_EQ(result, "42");
|
||||
}
|
||||
{
|
||||
constexpr auto result =
|
||||
constexpr_buffer_helper<17>{}.modify([](auto& buffer) {
|
||||
fmt::format_to(buffer.data(), FMT_COMPILE("{} is {}"), "The answer",
|
||||
"42");
|
||||
});
|
||||
test_format<17>(FMT_COMPILE("{} is {}"), "The answer", "42");
|
||||
EXPECT_EQ(result, "The answer is 42");
|
||||
}
|
||||
}
|
||||
@ -260,10 +237,7 @@ TEST(CompileTimeFormattingTest, String) {
|
||||
TEST(CompileTimeFormattingTest, Combination) {
|
||||
{
|
||||
constexpr auto result =
|
||||
constexpr_buffer_helper<18>{}.modify([](auto& buffer) {
|
||||
fmt::format_to(buffer.data(), FMT_COMPILE("{}, {}, {}"), 420, true,
|
||||
"answer");
|
||||
});
|
||||
test_format<18>(FMT_COMPILE("{}, {}, {}"), 420, true, "answer");
|
||||
EXPECT_EQ(result, "420, true, answer");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user