85c8d8fbaeccd0bb30a55ba23b8fd01eb525436c
[folly.git] / folly / test / FormatTest.cpp
1 /*
2  * Copyright 2015 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <folly/Format.h>
18
19 #include <gflags/gflags.h>
20 #include <gtest/gtest.h>
21
22 #include <string>
23
24 using namespace folly;
25
26 template <class Uint>
27 void compareOctal(Uint u) {
28   char buf1[detail::kMaxOctalLength + 1];
29   buf1[detail::kMaxOctalLength] = '\0';
30   char* p = buf1 + detail::uintToOctal(buf1, detail::kMaxOctalLength, u);
31
32   char buf2[detail::kMaxOctalLength + 1];
33   EXPECT_LT(snprintf(buf2, sizeof(buf2), "%jo", static_cast<uintmax_t>(u)),
34             sizeof(buf2));
35
36   EXPECT_EQ(std::string(buf2), std::string(p));
37 }
38
39 template <class Uint>
40 void compareHex(Uint u) {
41   char buf1[detail::kMaxHexLength + 1];
42   buf1[detail::kMaxHexLength] = '\0';
43   char* p = buf1 + detail::uintToHexLower(buf1, detail::kMaxHexLength, u);
44
45   char buf2[detail::kMaxHexLength + 1];
46   EXPECT_LT(snprintf(buf2, sizeof(buf2), "%jx", static_cast<uintmax_t>(u)),
47             sizeof(buf2));
48
49   EXPECT_EQ(std::string(buf2), std::string(p));
50 }
51
52 template <class Uint>
53 void compareBinary(Uint u) {
54   char buf[detail::kMaxBinaryLength + 1];
55   buf[detail::kMaxBinaryLength] = '\0';
56   char* p = buf + detail::uintToBinary(buf, detail::kMaxBinaryLength, u);
57
58   std::string repr;
59   if (u == 0) {
60     repr = '0';
61   } else {
62     std::string tmp;
63     for (; u; u >>= 1) {
64       tmp.push_back(u & 1 ? '1' : '0');
65     }
66     repr.assign(tmp.rbegin(), tmp.rend());
67   }
68
69   EXPECT_EQ(repr, std::string(p));
70 }
71
72 TEST(Format, uintToOctal) {
73   for (unsigned i = 0; i < (1u << 16) + 2; i++) {
74     compareOctal(i);
75   }
76 }
77
78 TEST(Format, uintToHex) {
79   for (unsigned i = 0; i < (1u << 16) + 2; i++) {
80     compareHex(i);
81   }
82 }
83
84 TEST(Format, uintToBinary) {
85   for (unsigned i = 0; i < (1u << 16) + 2; i++) {
86     compareBinary(i);
87   }
88 }
89
90 TEST(Format, Simple) {
91   EXPECT_EQ("hello", sformat("hello"));
92   EXPECT_EQ("42", sformat("{}", 42));
93   EXPECT_EQ("42 42", sformat("{0} {0}", 42));
94   EXPECT_EQ("00042  23   42", sformat("{0:05} {1:3} {0:4}", 42, 23));
95   EXPECT_EQ("hello world hello 42",
96             sformat("{0} {1} {0} {2}", "hello", "world", 42));
97   EXPECT_EQ("XXhelloXX", sformat("{:X^9}", "hello"));
98   EXPECT_EQ("XXX42XXXX", sformat("{:X^9}", 42));
99   EXPECT_EQ("-0xYYYY2a", sformat("{:Y=#9x}", -42));
100   EXPECT_EQ("*", sformat("{}", '*'));
101   EXPECT_EQ("42", sformat("{}", 42));
102   EXPECT_EQ("0042", sformat("{:04}", 42));
103
104   EXPECT_EQ("hello  ", sformat("{:7}", "hello"));
105   EXPECT_EQ("hello  ", sformat("{:<7}", "hello"));
106   EXPECT_EQ("  hello", sformat("{:>7}", "hello"));
107
108   EXPECT_EQ("  hi", sformat("{:>*}", 4, "hi"));
109   EXPECT_EQ("   hi!", sformat("{:*}{}", 3, "", "hi!"));
110   EXPECT_EQ("    123", sformat("{:*}", 7, 123));
111   EXPECT_EQ("123    ", sformat("{:<*}", 7, 123));
112   EXPECT_EQ("----<=>----", sformat("{:-^*}", 11, "<=>"));
113   EXPECT_EQ("+++456+++", sformat("{2:+^*0}", 9, "unused", 456));
114
115   std::vector<int> v1 {10, 20, 30};
116   EXPECT_EQ("0020", sformat("{0[1]:04}", v1));
117   EXPECT_EQ("0020", svformat("{1:04}", v1));
118   EXPECT_EQ("10 20", svformat("{} {}", v1));
119
120   const std::vector<int> v2 = v1;
121   EXPECT_EQ("0020", sformat("{0[1]:04}", v2));
122   EXPECT_EQ("0020", svformat("{1:04}", v2));
123   EXPECT_THROW(sformat("{0[3]:04}", v2), std::out_of_range);
124   EXPECT_THROW(svformat("{3:04}", v2), std::out_of_range);
125   EXPECT_EQ("0020", sformat("{0[1]:04}", defaulted(v2, 42)));
126   EXPECT_EQ("0020", svformat("{1:04}", defaulted(v2, 42)));
127   EXPECT_EQ("0042", sformat("{0[3]:04}", defaulted(v2, 42)));
128   EXPECT_EQ("0042", svformat("{3:04}", defaulted(v2, 42)));
129
130   const int p[] = {10, 20, 30};
131   const int* q = p;
132   EXPECT_EQ("0020", sformat("{0[1]:04}", p));
133   EXPECT_EQ("0020", svformat("{1:04}", p));
134   EXPECT_EQ("0020", sformat("{0[1]:04}", q));
135   EXPECT_EQ("0020", svformat("{1:04}", q));
136   EXPECT_NE("", sformat("{}", q));
137
138   EXPECT_EQ("0x", sformat("{}", p).substr(0, 2));
139   EXPECT_EQ("10", svformat("{}", p));
140   EXPECT_EQ("0x", sformat("{}", q).substr(0, 2));
141   EXPECT_EQ("10", svformat("{}", q));
142   q = nullptr;
143   EXPECT_EQ("(null)", sformat("{}", q));
144
145   std::map<int, std::string> m { {10, "hello"}, {20, "world"} };
146   EXPECT_EQ("worldXX", sformat("{[20]:X<7}", m));
147   EXPECT_EQ("worldXX", svformat("{20:X<7}", m));
148   EXPECT_THROW(sformat("{[42]:X<7}", m), std::out_of_range);
149   EXPECT_THROW(svformat("{42:X<7}", m), std::out_of_range);
150   EXPECT_EQ("worldXX", sformat("{[20]:X<7}", defaulted(m, "meow")));
151   EXPECT_EQ("worldXX", svformat("{20:X<7}", defaulted(m, "meow")));
152   EXPECT_EQ("meowXXX", sformat("{[42]:X<7}", defaulted(m, "meow")));
153   EXPECT_EQ("meowXXX", svformat("{42:X<7}", defaulted(m, "meow")));
154
155   std::map<std::string, std::string> m2 { {"hello", "world"} };
156   EXPECT_EQ("worldXX", sformat("{[hello]:X<7}", m2));
157   EXPECT_EQ("worldXX", svformat("{hello:X<7}", m2));
158   EXPECT_THROW(sformat("{[none]:X<7}", m2), std::out_of_range);
159   EXPECT_THROW(svformat("{none:X<7}", m2), std::out_of_range);
160   EXPECT_EQ("worldXX", sformat("{[hello]:X<7}", defaulted(m2, "meow")));
161   EXPECT_EQ("worldXX", svformat("{hello:X<7}", defaulted(m2, "meow")));
162   EXPECT_EQ("meowXXX", sformat("{[none]:X<7}", defaulted(m2, "meow")));
163   EXPECT_EQ("meowXXX", svformat("{none:X<7}", defaulted(m2, "meow")));
164
165   // Test indexing in strings
166   EXPECT_EQ("61 62", sformat("{0[0]:x} {0[1]:x}", "abcde"));
167   EXPECT_EQ("61 62", svformat("{0:x} {1:x}", "abcde"));
168   EXPECT_EQ("61 62", sformat("{0[0]:x} {0[1]:x}", std::string("abcde")));
169   EXPECT_EQ("61 62", svformat("{0:x} {1:x}", std::string("abcde")));
170
171   // Test booleans
172   EXPECT_EQ("true", sformat("{}", true));
173   EXPECT_EQ("1", sformat("{:d}", true));
174   EXPECT_EQ("false", sformat("{}", false));
175   EXPECT_EQ("0", sformat("{:d}", false));
176
177   // Test pairs
178   {
179     std::pair<int, std::string> p {42, "hello"};
180     EXPECT_EQ("    42 hello ", sformat("{0[0]:6} {0[1]:6}", p));
181     EXPECT_EQ("    42 hello ", svformat("{:6} {:6}", p));
182   }
183
184   // Test tuples
185   {
186     std::tuple<int, std::string, int> t { 42, "hello", 23 };
187     EXPECT_EQ("    42 hello      23", sformat("{0[0]:6} {0[1]:6} {0[2]:6}", t));
188     EXPECT_EQ("    42 hello      23", svformat("{:6} {:6} {:6}", t));
189   }
190
191   // Test writing to stream
192   std::ostringstream os;
193   os << format("{} {}", 42, 23);
194   EXPECT_EQ("42 23", os.str());
195
196   // Test appending to string
197   std::string s;
198   format(&s, "{} {}", 42, 23);
199   format(&s, " hello {:X<7}", "world");
200   EXPECT_EQ("42 23 hello worldXX", s);
201 }
202
203 TEST(Format, Float) {
204   EXPECT_EQ("1", sformat("{}", 1.0));
205   EXPECT_EQ("0.1", sformat("{}", 0.1));
206   EXPECT_EQ("0.01", sformat("{}", 0.01));
207   EXPECT_EQ("0.001", sformat("{}", 0.001));
208   EXPECT_EQ("0.0001", sformat("{}", 0.0001));
209   EXPECT_EQ("1e-5", sformat("{}", 0.00001));
210   EXPECT_EQ("1e-6", sformat("{}", 0.000001));
211
212   EXPECT_EQ("10", sformat("{}", 10.0));
213   EXPECT_EQ("100", sformat("{}", 100.0));
214   EXPECT_EQ("1000", sformat("{}", 1000.0));
215   EXPECT_EQ("10000", sformat("{}", 10000.0));
216   EXPECT_EQ("100000", sformat("{}", 100000.0));
217   EXPECT_EQ("1e+6", sformat("{}", 1000000.0));
218   EXPECT_EQ("1e+7", sformat("{}", 10000000.0));
219
220   EXPECT_EQ("1.00", sformat("{:.2f}", 1.0));
221   EXPECT_EQ("0.10", sformat("{:.2f}", 0.1));
222   EXPECT_EQ("0.01", sformat("{:.2f}", 0.01));
223   EXPECT_EQ("0.00", sformat("{:.2f}", 0.001));
224
225   EXPECT_EQ("100000. !== 100000", sformat("{:.} !== {:.}", 100000.0, 100000));
226   EXPECT_EQ("100000.", sformat("{:.}", 100000.0));
227   EXPECT_EQ("1e+6", sformat("{:.}", 1000000.0));
228   EXPECT_EQ(" 100000.", sformat("{:8.}", 100000.0));
229   EXPECT_EQ("100000.", sformat("{:4.}", 100000.0));
230   EXPECT_EQ("  100000", sformat("{:8.8}", 100000.0));
231   EXPECT_EQ(" 100000.", sformat("{:8.8.}", 100000.0));
232 }
233
234 TEST(Format, MultiLevel) {
235   std::vector<std::map<std::string, std::string>> v = {
236     {
237       {"hello", "world"},
238     },
239   };
240
241   EXPECT_EQ("world", sformat("{[0.hello]}", v));
242 }
243
244 TEST(Format, separatorDecimalInteger) {
245   EXPECT_EQ("0", sformat("{:,d}", 0));
246   EXPECT_EQ("1", sformat("{:d}", 1));
247   EXPECT_EQ("1", sformat("{:,d}", 1));
248   EXPECT_EQ("1", sformat("{:,}", 1));
249   EXPECT_EQ("123", sformat("{:d}", 123));
250   EXPECT_EQ("123", sformat("{:,d}", 123));
251   EXPECT_EQ("123", sformat("{:,}", 123));
252   EXPECT_EQ("1234", sformat("{:d}", 1234));
253   EXPECT_EQ("1,234", sformat("{:,d}", 1234));
254   EXPECT_EQ("1,234", sformat("{:,}", 1234));
255   EXPECT_EQ("12345678", sformat("{:d}", 12345678));
256   EXPECT_EQ("12,345,678", sformat("{:,d}", 12345678));
257   EXPECT_EQ("12,345,678", sformat("{:,}", 12345678));
258   EXPECT_EQ("-1234", sformat("{:d}", -1234));
259   EXPECT_EQ("-1,234", sformat("{:,d}", -1234));
260   EXPECT_EQ("-1,234", sformat("{:,}", -1234));
261
262   int64_t max_int64_t = std::numeric_limits<int64_t>::max();
263   int64_t min_int64_t = std::numeric_limits<int64_t>::min();
264   uint64_t max_uint64_t = std::numeric_limits<uint64_t>::max();
265   EXPECT_EQ("9223372036854775807", sformat("{:d}", max_int64_t));
266   EXPECT_EQ("9,223,372,036,854,775,807", sformat("{:,d}", max_int64_t));
267   EXPECT_EQ("9,223,372,036,854,775,807", sformat("{:,}", max_int64_t));
268   EXPECT_EQ("-9223372036854775808", sformat("{:d}", min_int64_t));
269   EXPECT_EQ("-9,223,372,036,854,775,808", sformat("{:,d}", min_int64_t));
270   EXPECT_EQ("-9,223,372,036,854,775,808", sformat("{:,}", min_int64_t));
271   EXPECT_EQ("18446744073709551615", sformat("{:d}", max_uint64_t));
272   EXPECT_EQ("18,446,744,073,709,551,615", sformat("{:,d}", max_uint64_t));
273   EXPECT_EQ("18,446,744,073,709,551,615", sformat("{:,}", max_uint64_t));
274
275   EXPECT_EQ("  -1,234", sformat("{: 8,}", -1234));
276   EXPECT_EQ("-001,234", sformat("{:08,d}", -1234));
277   EXPECT_EQ("-00001,234", sformat("{:010,d}", -1234));
278   EXPECT_EQ(" -1,234 ", sformat("{:^ 8,d}", -1234));
279 }
280
281 // Note that sformat("{:n}", ...) uses the current locale setting to insert the
282 // appropriate number separator characters.
283 TEST(Format, separatorNumber) {
284   EXPECT_EQ("0", sformat("{:n}", 0));
285   EXPECT_EQ("1", sformat("{:n}", 1));
286   EXPECT_EQ("123", sformat("{:n}", 123));
287   EXPECT_EQ("1234", sformat("{:n}", 1234));
288   EXPECT_EQ("12345678", sformat("{:n}", 12345678));
289   EXPECT_EQ("-1234", sformat("{:n}", -1234));
290
291   int64_t max_int64_t = std::numeric_limits<int64_t>::max();
292   int64_t min_int64_t = std::numeric_limits<int64_t>::min();
293   uint64_t max_uint64_t = std::numeric_limits<uint64_t>::max();
294   EXPECT_EQ("9223372036854775807", sformat("{:n}", max_int64_t));
295   EXPECT_EQ("-9223372036854775808", sformat("{:n}", min_int64_t));
296   EXPECT_EQ("18446744073709551615", sformat("{:n}", max_uint64_t));
297
298   EXPECT_EQ("   -1234", sformat("{: 8n}", -1234));
299   EXPECT_EQ("-0001234", sformat("{:08n}", -1234));
300   EXPECT_EQ("-000001234", sformat("{:010n}", -1234));
301   EXPECT_EQ(" -1234  ", sformat("{:^ 8n}", -1234));
302 }
303
304 // insertThousandsGroupingUnsafe requires non-const params
305 static void testGrouping(const char* a_str, const char* expected) {
306   char str[256];
307   char* end_ptr = str + snprintf(str, sizeof(str), "%s", a_str);
308   ASSERT_LT(end_ptr, str + sizeof(str));
309   folly::detail::insertThousandsGroupingUnsafe(str, &end_ptr);
310   ASSERT_STREQ(expected, str);
311 }
312
313 TEST(Format, separatorUnit) {
314   testGrouping("0", "0");
315   testGrouping("1", "1");
316   testGrouping("12", "12");
317   testGrouping("123", "123");
318   testGrouping("1234", "1,234");
319   testGrouping("12345", "12,345");
320   testGrouping("123456", "123,456");
321   testGrouping("1234567", "1,234,567");
322   testGrouping("1234567890", "1,234,567,890");
323   testGrouping("9223372036854775807", "9,223,372,036,854,775,807");
324   testGrouping("18446744073709551615", "18,446,744,073,709,551,615");
325 }
326
327
328 namespace {
329
330 struct KeyValue {
331   std::string key;
332   int value;
333 };
334
335 }  // namespace
336
337 namespace folly {
338
339 template <> class FormatValue<KeyValue> {
340  public:
341   explicit FormatValue(const KeyValue& kv) : kv_(kv) { }
342
343   template <class FormatCallback>
344   void format(FormatArg& arg, FormatCallback& cb) const {
345     format_value::formatFormatter(
346         folly::format("<key={}, value={}>", kv_.key, kv_.value),
347         arg, cb);
348   }
349
350  private:
351   const KeyValue& kv_;
352 };
353
354 }  // namespace
355
356 TEST(Format, Custom) {
357   KeyValue kv { "hello", 42 };
358
359   EXPECT_EQ("<key=hello, value=42>", sformat("{}", kv));
360   EXPECT_EQ("<key=hello, value=42>", sformat("{:10}", kv));
361   EXPECT_EQ("<key=hello", sformat("{:.10}", kv));
362   EXPECT_EQ("<key=hello, value=42>XX", sformat("{:X<23}", kv));
363   EXPECT_EQ("XX<key=hello, value=42>", sformat("{:X>23}", kv));
364   EXPECT_EQ("<key=hello, value=42>", sformat("{0[0]}", &kv));
365   EXPECT_NE("", sformat("{}", &kv));
366 }
367
368 namespace {
369
370 struct Opaque {
371   int k;
372 };
373
374 } // namespace
375
376 #define EXPECT_THROW_STR(code, type, str) \
377   do { \
378     bool caught = false; \
379     try { \
380       code; \
381     } catch (const type& e) { \
382       caught = true; \
383       EXPECT_TRUE(strstr(e.what(), (str)) != nullptr) << \
384         "Expected message [" << (str) << "], actual message [" << \
385         e.what(); \
386     } catch (const std::exception& e) { \
387       caught = true; \
388       ADD_FAILURE() << "Caught different exception type; expected " #type \
389         ", caught " << folly::demangle(typeid(e)); \
390     } catch (...) { \
391       caught = true; \
392       ADD_FAILURE() << "Caught unknown exception type; expected " #type; \
393     } \
394     if (!caught) { \
395       ADD_FAILURE() << "Expected exception " #type ", caught nothing"; \
396     } \
397   } while (false)
398
399 #define EXPECT_FORMAT_ERROR(code, str) \
400   EXPECT_THROW_STR(code, folly::BadFormatArg, (str))
401
402 TEST(Format, Unformatted) {
403   Opaque o;
404   EXPECT_NE("", sformat("{}", &o));
405   EXPECT_FORMAT_ERROR(sformat("{0[0]}", &o),
406                       "No formatter available for this type");
407 }
408
409 TEST(Format, Nested) {
410   EXPECT_EQ("1 2 3 4", sformat("{} {} {}", 1, 2, format("{} {}", 3, 4)));
411   //
412   // not copyable, must hold temporary in scope instead.
413   auto&& saved = format("{} {}", 3, 4);
414   EXPECT_EQ("1 2 3 4", sformat("{} {} {}", 1, 2, saved));
415 }
416
417 TEST(Format, OutOfBounds) {
418   std::vector<int> ints{1, 2, 3, 4, 5};
419   EXPECT_EQ("1 3 5", sformat("{0[0]} {0[2]} {0[4]}", ints));
420   EXPECT_THROW(sformat("{[5]}", ints), std::out_of_range);
421
422   std::map<std::string, int> map{{"hello", 0}, {"world", 1}};
423   EXPECT_EQ("hello = 0", sformat("hello = {[hello]}", map));
424   EXPECT_THROW(sformat("{[nope]}", map), std::out_of_range);
425   EXPECT_THROW(svformat("{nope}", map), std::out_of_range);
426 }
427
428 TEST(Format, BogusFormatString) {
429   EXPECT_FORMAT_ERROR(sformat("}"), "single '}' in format string");
430   EXPECT_FORMAT_ERROR(sformat("foo}bar"), "single '}' in format string");
431   EXPECT_FORMAT_ERROR(sformat("foo{bar"), "missing ending '}'");
432   EXPECT_FORMAT_ERROR(sformat("{[test]"), "missing ending '}'");
433   EXPECT_FORMAT_ERROR(sformat("{-1.3}"), "argument index must be non-negative");
434   EXPECT_FORMAT_ERROR(sformat("{1.3}", 0, 1, 2), "index not allowed");
435   EXPECT_FORMAT_ERROR(sformat("{0} {} {1}", 0, 1, 2),
436                "may not have both default and explicit arg indexes");
437   EXPECT_FORMAT_ERROR(sformat("{:*}", 1.2),
438                       "dynamic field width argument must be integral");
439   EXPECT_FORMAT_ERROR(sformat("{} {:*}", "hi"),
440                       "argument index out of range, max=1");
441   EXPECT_FORMAT_ERROR(
442     sformat("{:*0}", 12, "ok"),
443     "cannot provide width arg index without value arg index"
444   );
445   EXPECT_FORMAT_ERROR(
446     sformat("{0:*}", 12, "ok"),
447     "cannot provide value arg index without width arg index"
448   );
449
450   std::vector<int> v{1, 2, 3};
451   EXPECT_FORMAT_ERROR(svformat("{:*}", v),
452                       "dynamic field width not supported in vformat()");
453
454   // This one fails in detail::enforceWhitespace(), which throws
455   // std::range_error
456   EXPECT_THROW_STR(sformat("{0[test}"), std::range_error,
457                    "Non-whitespace: [");
458 }
459
460 template <bool containerMode, class... Args>
461 class TestExtendingFormatter;
462
463 template <bool containerMode, class... Args>
464 class TestExtendingFormatter
465     : public BaseFormatter<TestExtendingFormatter<containerMode, Args...>,
466                            containerMode,
467                            Args...> {
468  private:
469   explicit TestExtendingFormatter(StringPiece& str, Args&&... args)
470       : BaseFormatter<TestExtendingFormatter<containerMode, Args...>,
471                       containerMode,
472                       Args...>(str, std::forward<Args>(args)...) {}
473
474   template <size_t K, class Callback>
475   void doFormatArg(FormatArg& arg, Callback& cb) const {
476     std::string result;
477     auto appender = [&result](StringPiece s) {
478       result.append(s.data(), s.size());
479     };
480     std::get<K>(this->values_).format(arg, appender);
481     result = sformat("{{{}}}", result);
482     cb(StringPiece(result));
483   }
484
485   friend class BaseFormatter<TestExtendingFormatter<containerMode, Args...>,
486                              containerMode,
487                              Args...>;
488
489   template <class... A>
490   friend std::string texsformat(StringPiece fmt, A&&... arg);
491 };
492
493 template <class... Args>
494 std::string texsformat(StringPiece fmt, Args&&... args) {
495   return TestExtendingFormatter<false, Args...>(
496       fmt, std::forward<Args>(args)...).str();
497 }
498
499 TEST(Format, Extending) {
500   EXPECT_EQ(texsformat("I {} brackets", "love"), "I {love} brackets");
501   EXPECT_EQ(texsformat("I {} nesting", sformat("really {}", "love")),
502             "I {really love} nesting");
503   EXPECT_EQ(
504       sformat("I also {} nesting", texsformat("have an {} for", "affinity")),
505       "I also have an {affinity} for nesting");
506   EXPECT_EQ(texsformat("Extending {} in {}",
507                        texsformat("a {}", "formatter"),
508                        "another formatter"),
509             "Extending {a {formatter}} in {another formatter}");
510 }
511
512 int main(int argc, char *argv[]) {
513   testing::InitGoogleTest(&argc, argv);
514   gflags::ParseCommandLineFlags(&argc, &argv, true);
515   return RUN_ALL_TESTS();
516 }