PrettyType formatType = testCase.prettyType;
double x = testCase.realValue;
std::string testString = testCase.prettyString;
- double recoveredX;
+ double recoveredX = 0;
try{
recoveredX = prettyToDouble(testString, formatType);
} catch (std::range_error &ex){
for (double x = 1e-18; x < 1e40; x *= 1.9){
bool addSpace = static_cast<PrettyType> (i) == PRETTY_SI;
for (int it = 0; it < 2; ++it, addSpace = true){
- double recoveredX;
+ double recoveredX = 0;
try{
recoveredX = prettyToDouble(prettyPrint(x, formatType, addSpace),
formatType);
TEST(Split, fixed_convert) {
StringPiece a, d;
int b;
- double c;
+ double c = 0;
EXPECT_TRUE(folly::split(':', "a:13:14.7:b", a, b, c, d));
EXPECT_EQ("a", a);
EXPECT_EQ("", rtrimWhitespace("\r "));
}
+const folly::StringPiece kTestUTF8 = "This is \U0001F602 stuff!";
+
+TEST(UTF8StringPiece, valid_utf8) {
+ folly::StringPiece sp = kTestUTF8;
+ UTF8StringPiece utf8 = sp;
+ // utf8.size() not available since it's not a random-access range
+ EXPECT_EQ(16, utf8.walk_size());
+}
+
+TEST(UTF8StringPiece, valid_suffix) {
+ UTF8StringPiece utf8 = kTestUTF8.subpiece(8);
+ EXPECT_EQ(8, utf8.walk_size());
+}
+
+TEST(UTF8StringPiece, empty_mid_codepoint) {
+ UTF8StringPiece utf8 = kTestUTF8.subpiece(9, 0); // okay since it's empty
+ EXPECT_EQ(0, utf8.walk_size());
+}
+
+TEST(UTF8StringPiece, invalid_mid_codepoint) {
+ EXPECT_THROW(UTF8StringPiece(kTestUTF8.subpiece(9, 1)), std::out_of_range);
+}
+
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);