Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify CompileTimeFormattingTest tests by reordering arguments of EXPECT_EQ #2044

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 12 additions & 38 deletions test/compile-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ 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);
}

std::array<char, max_string_length> buffer{};
};

Expand All @@ -192,51 +191,26 @@ consteval auto test_format(auto format, const Args&... args) {
}

TEST(CompileTimeFormattingTest, Bool) {
{
constexpr auto result = test_format<5>(FMT_COMPILE("{}"), true);
EXPECT_EQ(result, "true");
}
{
constexpr auto result = test_format<6>(FMT_COMPILE("{}"), false);
EXPECT_EQ(result, "false");
}
EXPECT_EQ("true", test_format<5>(FMT_COMPILE("{}"), true));
EXPECT_EQ("false", test_format<6>(FMT_COMPILE("{}"), false));
}

TEST(CompileTimeFormattingTest, Integer) {
{
constexpr auto result = test_format<3>(FMT_COMPILE("{}"), 42);
EXPECT_EQ(result, "42");
}
{
constexpr auto result = test_format<4>(FMT_COMPILE("{}"), 420);
EXPECT_EQ(result, "420");
}
{
constexpr auto result = test_format<6>(FMT_COMPILE("{} {}"), 42, 42);
EXPECT_EQ(result, "42 42");
}
{
constexpr auto result =
test_format<6>(FMT_COMPILE("{} {}"), uint32_t{42}, uint64_t{42});
EXPECT_EQ(result, "42 42");
}
EXPECT_EQ("42", test_format<3>(FMT_COMPILE("{}"), 42));
EXPECT_EQ("420", test_format<4>(FMT_COMPILE("{}"), 420));
EXPECT_EQ("42 42", test_format<6>(FMT_COMPILE("{} {}"), 42, 42));
EXPECT_EQ("42 42",
test_format<6>(FMT_COMPILE("{} {}"), uint32_t{42}, uint64_t{42}));
}

TEST(CompileTimeFormattingTest, String) {
{
constexpr auto result = test_format<3>(FMT_COMPILE("{}"), "42");
EXPECT_EQ(result, "42");
}
{
constexpr auto result =
test_format<17>(FMT_COMPILE("{} is {}"), "The answer", "42");
EXPECT_EQ(result, "The answer is 42");
}
EXPECT_EQ("42", test_format<3>(FMT_COMPILE("{}"), "42"));
EXPECT_EQ("The answer is 42",
test_format<17>(FMT_COMPILE("{} is {}"), "The answer", "42"));
}

TEST(CompileTimeFormattingTest, Combination) {
constexpr auto result =
test_format<18>(FMT_COMPILE("{}, {}, {}"), 420, true, "answer");
EXPECT_EQ(result, "420, true, answer");
EXPECT_EQ("420, true, answer",
test_format<18>(FMT_COMPILE("{}, {}, {}"), 420, true, "answer"));
}
#endif