Minor cleanup

This commit is contained in:
Victor Zverovich
2025-05-11 07:54:23 -07:00
parent 4999416e5c
commit 07885271a1
2 changed files with 34 additions and 42 deletions

View File

@ -413,37 +413,31 @@ TEST(std_test, format_shared_ptr) {
TEST(std_test, format_reference_wrapper) {
int num = 35;
EXPECT_EQ("35", fmt::to_string(std::cref(num)));
EXPECT_EQ("35", fmt::to_string(std::ref(num)));
EXPECT_EQ("35", fmt::format("{}", std::cref(num)));
EXPECT_EQ("35", fmt::format("{}", std::ref(num)));
EXPECT_EQ(fmt::to_string(std::cref(num)), "35");
EXPECT_EQ(fmt::to_string(std::ref(num)), "35");
EXPECT_EQ(fmt::format("{}", std::cref(num)), "35");
EXPECT_EQ(fmt::format("{}", std::ref(num)), "35");
}
// Regression test for https://github.com/fmtlib/fmt/issues/4424
struct type_with_format_as {
int x;
};
int format_as(const type_with_format_as& t) { return t.x; }
// Regression test for https://github.com/fmtlib/fmt/issues/4424.
struct type_with_format_as {};
int format_as(type_with_format_as) { return 20; }
TEST(std_test, format_reference_wrapper_with_format_as) {
type_with_format_as t{20};
EXPECT_EQ("20", fmt::to_string(std::cref(t)));
EXPECT_EQ("20", fmt::to_string(std::ref(t)));
EXPECT_EQ("20", fmt::format("{}", std::cref(t)));
EXPECT_EQ("20", fmt::format("{}", std::ref(t)));
type_with_format_as t;
EXPECT_EQ(fmt::to_string(std::cref(t)), "20");
EXPECT_EQ(fmt::to_string(std::ref(t)), "20");
EXPECT_EQ(fmt::format("{}", std::cref(t)), "20");
EXPECT_EQ(fmt::format("{}", std::ref(t)), "20");
}
struct type_with_format_as_string {
std::string str;
};
std::string format_as(const type_with_format_as_string& t) { return t.str; }
struct type_with_format_as_string {};
std::string format_as(type_with_format_as_string) { return "foo"; }
TEST(std_test, format_reference_wrapper_with_format_as_string) {
type_with_format_as_string t{"foo"};
EXPECT_EQ("foo", fmt::to_string(std::cref(t)));
EXPECT_EQ("foo", fmt::to_string(std::ref(t)));
EXPECT_EQ("foo", fmt::format("{}", std::cref(t)));
EXPECT_EQ("foo", fmt::format("{}", std::ref(t)));
type_with_format_as_string t;
EXPECT_EQ(fmt::to_string(std::cref(t)), "foo");
EXPECT_EQ(fmt::to_string(std::ref(t)), "foo");
EXPECT_EQ(fmt::format("{}", std::cref(t)), "foo");
EXPECT_EQ(fmt::format("{}", std::ref(t)), "foo");
}