#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);
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));
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;
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));
}
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)));
}
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.
}
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;
}
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);
}
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));
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());
}
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");
+}