/*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2015-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <folly/Format.h>
+#include <glog/logging.h>
+
+#include <folly/FBVector.h>
#include <folly/FileUtil.h>
-#include <folly/json.h>
+#include <folly/Portability.h>
#include <folly/dynamic.h>
-
-#include <glog/logging.h>
-#include <gflags/gflags.h>
-#include <gtest/gtest.h>
+#include <folly/json.h>
+#include <folly/portability/GTest.h>
+#include <folly/small_vector.h>
using namespace folly;
{
int fds[2];
CHECK_ERR(pipe(fds));
- SCOPE_EXIT { closeNoInt(fds[1]); };
+ SCOPE_EXIT {
+ // fclose on Windows automatically closes the underlying
+ // file descriptor.
+ if (!kIsWindows) {
+ closeNoInt(fds[1]);
+ }
+ };
{
FILE* fp = fdopen(fds[1], "wb");
PCHECK(fp);
EXPECT_EQ("(null)", sformat("{}", dynamic(nullptr)));
}
+namespace {
+
+template <class T>
+void testFormatSeq() {
+ T v{10, 20, 30};
+ EXPECT_EQ("30 10", sformat("{0[2]} {0[0]}", v));
+ EXPECT_EQ("0020", sformat("{0[1]:04}", v));
+ EXPECT_EQ("0020", svformat("{1:04}", v));
+ EXPECT_EQ("10 20", svformat("{} {}", v));
+ EXPECT_EQ("10 20 0030", svformat("{} {} {:04}", v));
+}
+
+} // namespace
+
+TEST(FormatOther, fbvector) {
+ testFormatSeq<fbvector<int>>();
+}
+
+TEST(FormatOther, small_vector) {
+ testFormatSeq<small_vector<int, 2>>();
+}
+
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);