23 using namespace folly;
33 snprintf(buf2,
sizeof(buf2),
"%jo", static_cast<uintmax_t>(u)),
47 snprintf(buf2,
sizeof(buf2),
"%jx", static_cast<uintmax_t>(u)),
65 tmp.push_back(u & 1 ?
'1' :
'0');
67 repr.assign(tmp.rbegin(), tmp.rend());
74 for (
unsigned i = 0;
i < (1u << 16) + 2;
i++) {
80 for (
unsigned i = 0;
i < (1u << 16) + 2;
i++) {
86 for (
unsigned i = 0;
i < (1u << 16) + 2;
i++) {
97 "hello world hello 42",
sformat(
"{0} {1} {0} {2}",
"hello",
"world", 42));
116 std::vector<int> v1{10, 20, 30};
121 const std::vector<int> v2 = v1;
132 const int p[] = {10, 20, 30};
148 std::map<int, std::string>
m{{10,
"hello"}, {20,
"world"}};
158 std::map<std::string, std::string> m2{{
"hello",
"world"}};
169 EXPECT_FALSE(
true) <<
"svformat should throw on missing key";
188 std::pair<int, std::string> p{42,
"hello"};
195 std::tuple<int, std::string, int>
t{42,
"hello", 23};
201 std::ostringstream os;
202 os <<
format(
"{} {}", 42, 23);
207 format(&s,
"{} {}", 42, 23);
208 format(&s,
" hello {:X<7}",
"world");
234 EXPECT_EQ(
"100000. !== 100000",
sformat(
"{:.} !== {:.}", 100000.0, 100000));
244 std::vector<std::map<std::string, std::string>>
v = {
253 TEST(Format, separatorDecimalInteger) {
292 TEST(Format, separatorNumber) {
316 char* end_ptr = str + snprintf(str,
sizeof(str),
"%s", a_str);
332 testGrouping(
"9223372036854775807",
"9,223,372,036,854,775,807");
333 testGrouping(
"18446744073709551615",
"18,446,744,073,709,551,615");
352 template <
class FormatCallback>
355 folly::format(
"<key={}, value={}>", kv_.key, kv_.value), arg, cb);
365 KeyValue kv{
"hello", 42};
384 #define EXPECT_THROW_STR(code, type, str) \ 386 bool caught = false; \ 389 } catch (const type& e) { \ 391 EXPECT_TRUE(strstr(e.what(), (str)) != nullptr) \ 392 << "Expected message [" << (str) << "], actual message [" \ 394 } catch (const std::exception& e) { \ 396 ADD_FAILURE() << "Caught different exception type; expected " #type \ 398 << folly::demangle(typeid(e)); \ 401 ADD_FAILURE() << "Caught unknown exception type; expected " #type; \ 404 ADD_FAILURE() << "Expected exception " #type ", caught nothing"; \ 408 #define EXPECT_FORMAT_ERROR(code, str) \ 409 EXPECT_THROW_STR(code, folly::BadFormatArg, (str)) 415 sformat(
"{0[0]}", &o),
"No formatter available for this type");
422 auto&& saved =
format(
"{} {}", 3, 4);
427 std::vector<int> ints{1, 2, 3, 4, 5};
431 std::map<std::string, int>
map{{
"hello", 0}, {
"world", 1}};
437 TEST(Format, BogusFormatString) {
445 sformat(
"{0} {} {1}", 0, 1, 2),
446 "may not have both default and explicit arg indexes");
448 sformat(
"{:*}", 1.2),
"dynamic field width argument must be integral");
450 sformat(
"{} {:*}",
"hi"),
"argument index out of range, max=1");
453 "cannot provide width arg index without value arg index");
456 "cannot provide value arg index without width arg index");
458 std::vector<int>
v{1, 2, 3};
460 svformat(
"{:*}",
v),
"dynamic field width not supported in vformat()");
467 template <
bool containerMode,
class...
Args>
470 template <
bool containerMode,
class...
Args>
473 TestExtendingFormatter<containerMode, Args...>,
483 template <
size_t K,
class Callback>
487 result.append(
s.data(),
s.size());
489 this->
template getFormatValue<K>().
format(arg, appender);
490 result =
sformat(
"{{{}}}", result);
499 template <
class...
A>
503 template <
class...
Args>
506 fmt, std::forward<Args>(args)...)
514 "I {really love} nesting");
517 "I also have an {affinity} for nesting");
520 "Extending {} in {}",
522 "another formatter"),
523 "Extending {a {formatter}} in {another formatter}");
527 constexpr
StringPiece kStr =
"A long string that should go on the heap";
528 auto fmt =
format(
"{}", kStr.str());
537 explicit NoncopyableInt(
int v) :
value(v) {}
550 template <
class FormatCallback>
556 const NoncopyableInt&
v_;
565 auto fmt =
format(
"{}", v);
573 auto fmt =
format(
"{}", NoncopyableInt(1));
TestExtendingFormatter(StringPiece &str, Args &&...args)
#define ASSERT_STREQ(s1, s2)
#define EXPECT_THROW(statement, expected_exception)
#define ASSERT_LT(val1, val2)
std::string sformat(StringPiece fmt, Args &&...args)
size_t uintToBinary(char *buffer, size_t bufLen, Uint v)
#define EXPECT_EQ(val1, val2)
size_t uintToHexLower(char *buffer, size_t bufLen, Uint v)
size_t uintToOctal(char *buffer, size_t bufLen, Uint v)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
detail::DefaultValueWrapper< Container, Value > defaulted(const Container &c, const Value &v)
const size_t kMaxHexLength
#define EXPECT_STREQ(s1, s2)
FloatingPoint< float > Float
static map< string, int > m
size_t uintToHex(char *buffer, size_t bufLen, Uint v, std::array< std::array< char, 2 >, 256 > const &repr)
void insertThousandsGroupingUnsafe(char *start_buffer, char **end_buffer)
std::string svformat(StringPiece fmt, Container &&container)
#define EXPECT_NE(val1, val2)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
#define EXPECT_FALSE(condition)
const size_t kMaxBinaryLength
Range< const char * > StringPiece
#define EXPECT_LT(val1, val2)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
void doFormatArg(FormatArg &arg, Callback &cb) const
const size_t kMaxOctalLength