Use overloaded operator<< for enums if available (#232)
This commit is contained in:
@@ -1637,3 +1637,15 @@ TEST(LiteralsTest, NamedArg) {
|
||||
udl_a_w);
|
||||
}
|
||||
#endif // FMT_USE_USER_DEFINED_LITERALS
|
||||
|
||||
enum TestEnum {};
|
||||
std::ostream &operator<<(std::ostream &os, TestEnum) {
|
||||
return os << "TestEnum";
|
||||
}
|
||||
|
||||
enum TestEnum2 { A };
|
||||
|
||||
TEST(FormatTest, Enum) {
|
||||
EXPECT_EQ("TestEnum", fmt::format("{}", TestEnum()));
|
||||
EXPECT_EQ("0", fmt::format("{}", A));
|
||||
}
|
||||
|
||||
@@ -870,15 +870,21 @@ TEST(UtilTest, ReportWindowsError) {
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
TEST(UtilTest, IsConvertibleToInt) {
|
||||
EXPECT_TRUE(fmt::internal::IsConvertibleToInt<char>::value);
|
||||
EXPECT_FALSE(fmt::internal::IsConvertibleToInt<const char *>::value);
|
||||
enum TestEnum2 {};
|
||||
enum TestEnum3 {};
|
||||
std::ostream &operator<<(std::ostream &, TestEnum3);
|
||||
|
||||
TEST(UtilTest, ConvertToInt) {
|
||||
EXPECT_TRUE(fmt::internal::ConvertToInt<char>::enable_conversion);
|
||||
EXPECT_FALSE(fmt::internal::ConvertToInt<const char *>::enable_conversion);
|
||||
EXPECT_TRUE(fmt::internal::ConvertToInt<TestEnum2>::value);
|
||||
EXPECT_FALSE(fmt::internal::ConvertToInt<TestEnum3>::value);
|
||||
}
|
||||
|
||||
#if FMT_USE_ENUM_BASE
|
||||
enum TestEnum : char {TestValue};
|
||||
TEST(UtilTest, IsEnumConvertibleToInt) {
|
||||
EXPECT_TRUE(fmt::internal::IsConvertibleToInt<TestEnum>::value);
|
||||
EXPECT_TRUE(fmt::internal::ConvertToInt<TestEnum>::enable_conversion);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user