From 611e81ec2783aad06b10509e64d639addfc28f79 Mon Sep 17 00:00:00 2001 From: Ivan Shynkarenka Date: Mon, 19 Sep 2016 18:10:31 +0300 Subject: [PATCH] Add AgrList serialization/deserialization unit tests --- test/format-test.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/format-test.cc b/test/format-test.cc index 6d246b93..050ce6d6 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1653,3 +1653,31 @@ FMT_VARIADIC(void, custom_format, const char *) TEST(FormatTest, CustomArgFormatter) { custom_format("{}", 42); } + +std::string serialize_deserialize(const char *format_str, fmt::ArgList args) { + std::vector buffer; + args.serialize(buffer); + args = args.deserialize(buffer); + return fmt::format(format_str, args); +} +FMT_VARIADIC(std::string, serialize_deserialize, const char *) + +TEST(FormatTest, Serialization) { + EXPECT_EQ(serialize_deserialize("{0}, {1}, {2}", -1, 0, 1), "-1, 0, 1"); + EXPECT_EQ(serialize_deserialize("{0}, {1}, {2}", 'a', 'b', 'c'), "a, b, c"); + EXPECT_EQ(serialize_deserialize("{}, {}, {}", 'a', 'b', 'c'), "a, b, c"); + EXPECT_EQ(serialize_deserialize("{2}, {1}, {0}", 'a', 'b', 'c'), "c, b, a"); + EXPECT_EQ(serialize_deserialize("{0}{1}{0}", "abra", "cad"), "abracadabra"); + EXPECT_EQ(serialize_deserialize("{:<30}", "left aligned"), "left aligned "); + EXPECT_EQ(serialize_deserialize("{:>30}", "right aligned"), " right aligned"); + EXPECT_EQ(serialize_deserialize("{:^30}", "centered"), " centered "); + EXPECT_EQ(serialize_deserialize("{:*^30}", "centered"), "***********centered***********"); + EXPECT_EQ(serialize_deserialize("{:+f}; {:+f}", 3.14, -3.14), "+3.140000; -3.140000"); + EXPECT_EQ(serialize_deserialize("{: f}; {: f}", 3.14, -3.14), " 3.140000; -3.140000"); + EXPECT_EQ(serialize_deserialize("{:-f}; {:-f}", 3.14, -3.14), "3.140000; -3.140000"); + EXPECT_EQ(serialize_deserialize("int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42), "int: 42; hex: 2a; oct: 52; bin: 101010"); + EXPECT_EQ(serialize_deserialize("int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}", 42), "int: 42; hex: 0x2a; oct: 052; bin: 0b101010"); + EXPECT_EQ(serialize_deserialize("The date is {}", Date(2012, 12, 9)), "The date is 2012-12-9"); + EXPECT_EQ(serialize_deserialize("Elapsed time: {s:.2f} seconds", "s"_a = 1.23), "Elapsed time: 1.23 seconds"); + EXPECT_EQ(serialize_deserialize("The answer is {}"_format(42).c_str()), "The answer is 42"); +}