X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FRangeTest.cpp;h=42faf4dea14af05817c88cef57316889254ba343;hb=e229101b0e2fc1d9ccfbcb10be991cb62e19d32d;hp=e80bb6eae70beddcbc0cc704f022d610e084d97f;hpb=94b8816bbdca38914030842554cc955caee59063;p=folly.git diff --git a/folly/test/RangeTest.cpp b/folly/test/RangeTest.cpp index e80bb6ea..42faf4de 100644 --- a/folly/test/RangeTest.cpp +++ b/folly/test/RangeTest.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -1091,7 +1092,9 @@ template void testRangeFunc(C&& x, size_t n) { const auto& cx = x; // type, conversion checks - Range r1 = range(std::forward(x)); + using R1Iter = + _t>::value, int*, int const*>>; + Range r1 = range(std::forward(x)); Range r2 = range(std::forward(x)); Range r3 = range(cx); Range r5 = range(std::move(cx)); @@ -1177,6 +1180,57 @@ TEST(RangeFunc, ConstexprCollection) { EXPECT_EQ(2, numCollRangeSize); } +TEST(CRangeFunc, CArray) { + int numArray[4] = {3, 17, 1, 9}; + auto const numArrayRange = crange(numArray); + EXPECT_TRUE( + (std::is_same::value)); + EXPECT_THAT(numArrayRange, testing::ElementsAreArray(numArray)); +} + +TEST(CRangeFunc, StdArray) { + std::array numArray = {{3, 17, 1, 9}}; + auto const numArrayRange = crange(numArray); + EXPECT_TRUE( + (std::is_same::value)); + EXPECT_THAT(numArrayRange, testing::ElementsAreArray(numArray)); +} + +TEST(CRangeFunc, StdArrayZero) { + std::array numArray = {}; + auto const numArrayRange = crange(numArray); + EXPECT_TRUE( + (std::is_same::value)); + EXPECT_THAT(numArrayRange, testing::IsEmpty()); +} + +TEST(CRangeFunc, Collection) { + class IntCollection { + public: + constexpr IntCollection(int* d, size_t s) : data_(d), size_(s) {} + constexpr int* data() { + return data_; + } + constexpr int const* data() const { + return data_; + } + constexpr size_t size() const { + return size_; + } + + private: + int* data_; + size_t size_; + }; + int numArray[4] = {3, 17, 1, 9}; + auto numPtr = static_cast(numArray); + auto numColl = IntCollection(numPtr + 1, 2); + auto const numCollRange = crange(numColl); + EXPECT_TRUE( + (std::is_same::value)); + EXPECT_THAT(numCollRange, testing::ElementsAreArray({17, 1})); +} + std::string get_rand_str( size_t size, std::uniform_int_distribution<>& dist, @@ -1197,7 +1251,7 @@ bool operator==(MutableStringPiece mp, StringPiece sp) { bool operator==(StringPiece sp, MutableStringPiece mp) { return mp.compare(sp) == 0; } -} +} // namespace folly TEST(ReplaceAt, exhaustiveTest) { char input[] = "this is nice and long input"; @@ -1374,3 +1428,8 @@ TEST(Range, LiteralSuffix) { constexpr Range pieceW{L"hello", 5}; EXPECT_EQ(literalPieceW, pieceW); } + +TEST(Range, LiteralSuffixContainsNulBytes) { + constexpr auto literalPiece = "\0foo\0"_sp; + EXPECT_EQ(5u, literalPiece.size()); +}