Add fmt::underlying for enum classes

This commit is contained in:
Victor Zverovich
2022-01-22 08:06:22 -08:00
parent 0014024a2c
commit 09fde7f4b8
3 changed files with 25 additions and 1 deletions
+7 -1
View File
@@ -1409,8 +1409,14 @@ TEST(format_test, format_pointer) {
EXPECT_EQ("0x0", fmt::format("{}", nullptr));
}
enum class color { red, green, blue };
TEST(format_test, format_enum_class) {
EXPECT_EQ(fmt::format("{}", fmt::underlying(color::red)), "0");
}
TEST(format_test, format_string) {
EXPECT_EQ("test", fmt::format("{0}", std::string("test")));
EXPECT_EQ(fmt::format("{0}", std::string("test")), "test");
EXPECT_THROW((void)fmt::format(fmt::runtime("{:x}"), std::string("test")),
fmt::format_error);
}