test that _sp includes nul bytes
authorChad Austin <chadaustin@fb.com>
Mon, 8 Jan 2018 19:12:18 +0000 (11:12 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 8 Jan 2018 19:15:36 +0000 (11:15 -0800)
Summary:
D6617812 wants to build a StringPiece from a literal with an
embedded nul. Add a test to verify that _sp is suitable for this use
case.

Reviewed By: yfeldblum

Differential Revision: D6651024

fbshipit-source-id: be4fb875762829fdb61c57fa72954fef286e9df0

folly/test/RangeTest.cpp

index b1298cacec7f659466ce85bdd9f990d169bd9338..42faf4dea14af05817c88cef57316889254ba343 100644 (file)
@@ -1428,3 +1428,8 @@ TEST(Range, LiteralSuffix) {
   constexpr Range<wchar_t const*> pieceW{L"hello", 5};
   EXPECT_EQ(literalPieceW, pieceW);
 }
   constexpr Range<wchar_t const*> pieceW{L"hello", 5};
   EXPECT_EQ(literalPieceW, pieceW);
 }
+
+TEST(Range, LiteralSuffixContainsNulBytes) {
+  constexpr auto literalPiece = "\0foo\0"_sp;
+  EXPECT_EQ(5u, literalPiece.size());
+}