/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
testIntegral2String<String, Ints...>();
}
+#if FOLLY_HAVE_INT128_T
+template <class String>
+void test128Bit2String() {
+ typedef unsigned __int128 Uint;
+ typedef __int128 Sint;
+
+ EXPECT_EQ(detail::digitsEnough<unsigned __int128>(), 39);
+
+ Uint value = 123;
+ EXPECT_EQ(to<String>(value), "123");
+ Sint svalue = 123;
+ EXPECT_EQ(to<String>(svalue), "123");
+ svalue = -123;
+ EXPECT_EQ(to<String>(svalue), "-123");
+
+ value = __int128(1) << 64;
+ EXPECT_EQ(to<String>(value), "18446744073709551616");
+
+ svalue = -(__int128(1) << 64);
+ EXPECT_EQ(to<String>(svalue), "-18446744073709551616");
+
+ value = 0;
+ EXPECT_EQ(to<String>(value), "0");
+
+ svalue = 0;
+ EXPECT_EQ(to<String>(svalue), "0");
+
+ // TODO: the following do not compile to<__int128> ...
+
+#if 0
+ value = numeric_limits<Uint>::min();
+ EXPECT_EQ(to<Uint>(to<String>(value)), value);
+ value = numeric_limits<Uint>::max();
+ EXPECT_EQ(to<Uint>(to<String>(value)), value);
+
+ svalue = numeric_limits<Sint>::min();
+ EXPECT_EQ(to<Sint>(to<String>(svalue)), svalue);
+ value = numeric_limits<Sint>::max();
+ EXPECT_EQ(to<Sint>(to<String>(svalue)), svalue);
+#endif
+}
+
+#endif
+
TEST(Conv, Integral2String) {
testIntegral2String<std::string, char, short, int, long>();
testIntegral2String<fbstring, char, short, int, long>();
+
+#if FOLLY_HAVE_INT128_T
+ test128Bit2String<std::string>();
+ test128Bit2String<fbstring>();
+#endif
}
template <class String>
EXPECT_EQ(s, "Lorem ipsum 1234 dolor amet 567.89.");
}
+template <class String>
+void testVariadicToDelim() {
+ String s;
+ toAppendDelim(":", &s);
+ toAppendDelim(
+ ":", "Lorem ipsum ", 1234, String(" dolor amet "), 567.89, '!', &s);
+ EXPECT_EQ(s, "Lorem ipsum :1234: dolor amet :567.89:!");
+
+ s = toDelim<String>(':');
+ EXPECT_TRUE(s.empty());
+
+ s = toDelim<String>(
+ ":", "Lorem ipsum ", nullptr, 1234, " dolor amet ", 567.89, '.');
+ EXPECT_EQ(s, "Lorem ipsum ::1234: dolor amet :567.89:.");
+}
+
TEST(Conv, NullString) {
string s1 = to<string>((char *) NULL);
EXPECT_TRUE(s1.empty());
testVariadicTo<fbstring>();
}
+TEST(Conv, VariadicToDelim) {
+ testVariadicToDelim<string>();
+ testVariadicToDelim<fbstring>();
+}
+
template <class String>
void testDoubleToString() {
EXPECT_EQ(to<string>(0.0), "0");