From 07ed0a721f66a5333b8ca01cbccc3e2675d97322 Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Thu, 15 Aug 2013 14:49:47 -0700 Subject: [PATCH] Fix overeager assertion Summary: Also important spelling mistakes. @override-unit-failures Test Plan: string_test Reviewed By: tjackson@fb.com FB internal diff: D930037 --- folly/String-inl.h | 2 +- folly/test/StringTest.cpp | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/folly/String-inl.h b/folly/String-inl.h index c608398a..e61ef332 100644 --- a/folly/String-inl.h +++ b/folly/String-inl.h @@ -300,7 +300,7 @@ template<> struct OutputConverter { template void internalSplit(DelimT delim, StringPiece sp, OutputIterator out, bool ignoreEmpty) { - assert(sp.start() != nullptr); + assert(sp.empty() || sp.start() != nullptr); const char* s = sp.start(); const size_t strSize = sp.size(); diff --git a/folly/test/StringTest.cpp b/folly/test/StringTest.cpp index b0ff972b..aac79a8a 100644 --- a/folly/test/StringTest.cpp +++ b/folly/test/StringTest.cpp @@ -481,6 +481,13 @@ void splitTest() { EXPECT_EQ(parts[2], "c"); parts.clear(); + folly::split(',', StringPiece("a,b,c"), parts); + EXPECT_EQ(parts.size(), 3); + EXPECT_EQ(parts[0], "a"); + EXPECT_EQ(parts[1], "b"); + EXPECT_EQ(parts[2], "c"); + parts.clear(); + folly::split(',', string("a,b,c"), parts); EXPECT_EQ(parts.size(), 3); EXPECT_EQ(parts[0], "a"); @@ -559,16 +566,25 @@ void splitTest() { EXPECT_EQ(parts[0], ""); parts.clear(); + folly::split("a", StringPiece(), parts, true); + EXPECT_EQ(parts.size(), 0); + parts.clear(); + + folly::split("a", StringPiece(), parts); + EXPECT_EQ(parts.size(), 1); + EXPECT_EQ(parts[0], ""); + parts.clear(); + folly::split("a", "abcdefg", parts, true); EXPECT_EQ(parts.size(), 1); EXPECT_EQ(parts[0], "bcdefg"); parts.clear(); - orig = "All, , your bases, are , , belong to us"; + orig = "All, , your base, are , , belong to us"; folly::split(", ", orig, parts, true); EXPECT_EQ(parts.size(), 4); EXPECT_EQ(parts[0], "All"); - EXPECT_EQ(parts[1], "your bases"); + EXPECT_EQ(parts[1], "your base"); EXPECT_EQ(parts[2], "are "); EXPECT_EQ(parts[3], "belong to us"); parts.clear(); @@ -576,7 +592,7 @@ void splitTest() { EXPECT_EQ(parts.size(), 6); EXPECT_EQ(parts[0], "All"); EXPECT_EQ(parts[1], ""); - EXPECT_EQ(parts[2], "your bases"); + EXPECT_EQ(parts[2], "your base"); EXPECT_EQ(parts[3], "are "); EXPECT_EQ(parts[4], ""); EXPECT_EQ(parts[5], "belong to us"); @@ -689,11 +705,11 @@ void piecesTest() { EXPECT_EQ(pieces[0], "bcdefg"); pieces.clear(); - orig = "All, , your bases, are , , belong to us"; + orig = "All, , your base, are , , belong to us"; folly::split(", ", orig, pieces, true); EXPECT_EQ(pieces.size(), 4); EXPECT_EQ(pieces[0], "All"); - EXPECT_EQ(pieces[1], "your bases"); + EXPECT_EQ(pieces[1], "your base"); EXPECT_EQ(pieces[2], "are "); EXPECT_EQ(pieces[3], "belong to us"); pieces.clear(); @@ -701,7 +717,7 @@ void piecesTest() { EXPECT_EQ(pieces.size(), 6); EXPECT_EQ(pieces[0], "All"); EXPECT_EQ(pieces[1], ""); - EXPECT_EQ(pieces[2], "your bases"); + EXPECT_EQ(pieces[2], "your base"); EXPECT_EQ(pieces[3], "are "); EXPECT_EQ(pieces[4], ""); EXPECT_EQ(pieces[5], "belong to us"); -- 2.34.1