aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVictor Zverovich <victor.zverovich@gmail.com>2019-11-25 16:46:33 -0800
committerVictor Zverovich <victor.zverovich@gmail.com>2019-11-25 16:46:33 -0800
commit0d07db1234ad0c11f52153cbdf8bd989b5ec8535 (patch)
tree82887433972847445883adce70d11e507445873b /test
parentd19ed6716d7101474e87939fe1c29b1f9d46ffd7 (diff)
downloadfmtlib-0d07db1234ad0c11f52153cbdf8bd989b5ec8535.tar.gz
Fix handling of streamable and convertible to string types
Diffstat (limited to 'test')
-rw-r--r--test/core-test.cc13
-rw-r--r--test/ostream-test.cc25
2 files changed, 23 insertions, 15 deletions
diff --git a/test/core-test.cc b/test/core-test.cc
index dac40a0f..e2eec3ea 100644
--- a/test/core-test.cc
+++ b/test/core-test.cc
@@ -635,19 +635,6 @@ TEST(FormatterTest, FormatExplicitlyConvertibleToWStringView) {
EXPECT_EQ(L"foo",
fmt::format(L"{}", explicitly_convertible_to_wstring_view()));
}
-
-struct explicitly_convertible_to_string_like {
- template <typename String,
- typename = typename std::enable_if<std::is_constructible<
- String, const char*, std::size_t>::value>::type>
- explicit operator String() const {
- return String("foo", 3u);
- }
-};
-
-TEST(FormatterTest, FormatExplicitlyConvertibleToStringLike) {
- EXPECT_EQ("foo", fmt::format("{}", explicitly_convertible_to_string_like()));
-}
#endif
struct disabled_rvalue_conversion {
diff --git a/test/ostream-test.cc b/test/ostream-test.cc
index c0ed43d8..b06ec7df 100644
--- a/test/ostream-test.cc
+++ b/test/ostream-test.cc
@@ -243,8 +243,7 @@ TEST(FormatTest, UDL) {
}
#endif
-template <typename T>
-struct convertible {
+template <typename T> struct convertible {
T value;
explicit convertible(const T& val) : value(val) {}
operator T() const { return value; }
@@ -255,3 +254,25 @@ TEST(OStreamTest, DisableBuiltinOStreamOperators) {
EXPECT_EQ(L"42", fmt::format(L"{:d}", convertible<unsigned short>(42)));
EXPECT_EQ("foo", fmt::format("{}", convertible<const char*>("foo")));
}
+
+struct explicitly_convertible_to_string_like {
+ template <typename String,
+ typename = typename std::enable_if<std::is_constructible<
+ String, const char*, std::size_t>::value>::type>
+ explicit operator String() const {
+ return String("foo", 3u);
+ }
+};
+
+TEST(FormatterTest, FormatExplicitlyConvertibleToStringLike) {
+ EXPECT_EQ("foo", fmt::format("{}", explicitly_convertible_to_string_like()));
+}
+
+std::ostream& operator<<(std::ostream& os,
+ explicitly_convertible_to_string_like) {
+ return os << "bar";
+}
+
+TEST(FormatterTest, FormatExplicitlyConvertibleToStringLikeIgnoreInserter) {
+ EXPECT_EQ("foo", fmt::format("{}", explicitly_convertible_to_string_like()));
+} \ No newline at end of file