forked from fmtlib/fmt
Generalize format_as
This commit is contained in:
@@ -673,24 +673,6 @@ FMT_END_NAMESPACE
|
||||
|
||||
enum class unformattable_scoped_enum {};
|
||||
|
||||
namespace test {
|
||||
enum class scoped_enum_as_int {};
|
||||
auto format_as(scoped_enum_as_int) -> int { return 42; }
|
||||
|
||||
enum class scoped_enum_as_string_view {};
|
||||
auto format_as(scoped_enum_as_string_view) -> fmt::string_view { return "foo"; }
|
||||
|
||||
enum class scoped_enum_as_string {};
|
||||
auto format_as(scoped_enum_as_string) -> std::string { return "foo"; }
|
||||
|
||||
struct struct_as_int {};
|
||||
auto format_as(struct_as_int) -> int { return 42; }
|
||||
|
||||
struct convertible_to_enum {
|
||||
operator scoped_enum_as_int() const { return {}; }
|
||||
};
|
||||
} // namespace test
|
||||
|
||||
TEST(core_test, is_formattable) {
|
||||
static_assert(!fmt::is_formattable<wchar_t>::value, "");
|
||||
#ifdef __cpp_char8_t
|
||||
@@ -729,7 +711,6 @@ TEST(core_test, is_formattable) {
|
||||
static_assert(!fmt::is_formattable<int(s::*)>::value, "");
|
||||
static_assert(!fmt::is_formattable<int (s::*)()>::value, "");
|
||||
static_assert(!fmt::is_formattable<unformattable_scoped_enum>::value, "");
|
||||
static_assert(fmt::is_formattable<test::scoped_enum_as_int>::value, "");
|
||||
static_assert(!fmt::is_formattable<unformattable_scoped_enum>::value, "");
|
||||
}
|
||||
|
||||
@@ -741,13 +722,6 @@ TEST(core_test, format_to) {
|
||||
EXPECT_EQ(s, "42");
|
||||
}
|
||||
|
||||
TEST(core_test, format_as) {
|
||||
EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_int()), "42");
|
||||
// EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_string_view()), "foo");
|
||||
// EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_string()), "foo");
|
||||
EXPECT_EQ(fmt::format("{}", test::struct_as_int()), "42");
|
||||
}
|
||||
|
||||
#ifdef __cpp_lib_byte
|
||||
TEST(core_test, format_byte) {
|
||||
EXPECT_EQ(fmt::format("{}", std::byte(42)), "42");
|
||||
|
@@ -2145,6 +2145,27 @@ TEST(format_test, back_insert_slicing) {
|
||||
EXPECT_EQ(fmt::format("{}", check_back_appender{}), "y");
|
||||
}
|
||||
|
||||
namespace test {
|
||||
enum class scoped_enum_as_int {};
|
||||
auto format_as(scoped_enum_as_int) -> int { return 42; }
|
||||
|
||||
enum class scoped_enum_as_string_view {};
|
||||
auto format_as(scoped_enum_as_string_view) -> fmt::string_view { return "foo"; }
|
||||
|
||||
enum class scoped_enum_as_string {};
|
||||
auto format_as(scoped_enum_as_string) -> std::string { return "foo"; }
|
||||
|
||||
struct struct_as_int {};
|
||||
auto format_as(struct_as_int) -> int { return 42; }
|
||||
} // namespace test
|
||||
|
||||
TEST(format_test, format_as) {
|
||||
EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_int()), "42");
|
||||
EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_string_view()), "foo");
|
||||
EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_string()), "foo");
|
||||
EXPECT_EQ(fmt::format("{}", test::struct_as_int()), "42");
|
||||
}
|
||||
|
||||
template <typename Char, typename T> bool check_enabled_formatter() {
|
||||
static_assert(std::is_default_constructible<fmt::formatter<T, Char>>::value,
|
||||
"");
|
||||
|
Reference in New Issue
Block a user