]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/fmt/test/args-test.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / fmt / test / args-test.cc
index a7421bc5299d092c2c49d5f4794aa4eb067dacd6..aa01fa4e08654dba65157d2f9b27c71458d79517 100644 (file)
@@ -7,10 +7,12 @@
 
 #include "fmt/args.h"
 
+#include <memory>
+
 #include "gtest/gtest.h"
 
 TEST(args_test, basic) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   store.push_back(42);
   store.push_back("abc1");
   store.push_back(1.5f);
@@ -19,7 +21,7 @@ TEST(args_test, basic) {
 
 TEST(args_test, strings_and_refs) {
   // Unfortunately the tests are compiled with old ABI so strings use COW.
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   char str[] = "1234567890";
   store.push_back(str);
   store.push_back(std::cref(str));
@@ -48,7 +50,7 @@ template <> struct formatter<custom_type> {
 FMT_END_NAMESPACE
 
 TEST(args_test, custom_format) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   auto c = custom_type();
   store.push_back(c);
   ++c.i;
@@ -77,7 +79,7 @@ template <> struct formatter<to_stringable> {
 FMT_END_NAMESPACE
 
 TEST(args_test, to_string_and_formatter) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   auto s = to_stringable();
   store.push_back(s);
   store.push_back(std::cref(s));
@@ -85,13 +87,13 @@ TEST(args_test, to_string_and_formatter) {
 }
 
 TEST(args_test, named_int) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   store.push_back(fmt::arg("a1", 42));
   EXPECT_EQ("42", fmt::vformat("{a1}", store));
 }
 
 TEST(args_test, named_strings) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   char str[] = "1234567890";
   store.push_back(fmt::arg("a1", str));
   store.push_back(fmt::arg("a2", std::cref(str)));
@@ -100,7 +102,7 @@ TEST(args_test, named_strings) {
 }
 
 TEST(args_test, named_arg_by_ref) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   char band[] = "Rolling Stones";
   store.push_back(fmt::arg("band", std::cref(band)));
   band[9] = 'c';  // Changing band affects the output.
@@ -108,7 +110,7 @@ TEST(args_test, named_arg_by_ref) {
 }
 
 TEST(args_test, named_custom_format) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   auto c = custom_type();
   store.push_back(fmt::arg("c1", c));
   ++c.i;
@@ -121,7 +123,7 @@ TEST(args_test, named_custom_format) {
 }
 
 TEST(args_test, clear) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   store.push_back(42);
 
   auto result = fmt::vformat("{}", store);
@@ -138,7 +140,7 @@ TEST(args_test, clear) {
 }
 
 TEST(args_test, reserve) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   store.reserve(2, 1);
   store.push_back(1.5f);
   store.push_back(fmt::arg("a1", 42));
@@ -163,7 +165,7 @@ template <> struct formatter<copy_throwable> {
 FMT_END_NAMESPACE
 
 TEST(args_test, throw_on_copy) {
-  auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
+  fmt::dynamic_format_arg_store<fmt::format_context> store;
   store.push_back(std::string("foo"));
   try {
     store.push_back(copy_throwable());
@@ -171,3 +173,14 @@ TEST(args_test, throw_on_copy) {
   }
   EXPECT_EQ(fmt::vformat("{}", store), "foo");
 }
+
+TEST(args_test, move_constructor) {
+  using store_type = fmt::dynamic_format_arg_store<fmt::format_context>;
+  auto store = std::unique_ptr<store_type>(new store_type());
+  store->push_back(42);
+  store->push_back(std::string("foo"));
+  store->push_back(fmt::arg("a1", "foo"));
+  auto moved_store = std::move(*store);
+  store.reset();
+  EXPECT_EQ(fmt::vformat("{} {} {a1}", moved_store), "42 foo foo");
+}