From eaf0ada683f43d0f889af4ec7bf651b701f73873 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Tue, 22 Nov 2016 23:22:19 +0000 Subject: Add some searching functions for ArrayRef. Differential Revision: https://reviews.llvm.org/D26999 llvm-svn: 287722 --- llvm/unittests/ADT/ArrayRefTest.cpp | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'llvm/unittests/ADT') diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp index ca75800f092..65b4cbcd668 100644 --- a/llvm/unittests/ADT/ArrayRefTest.cpp +++ b/llvm/unittests/ADT/ArrayRefTest.cpp @@ -102,6 +102,28 @@ TEST(ArrayRefTest, DropFront) { EXPECT_EQ(1U, AR3.drop_front(AR3.size() - 1).size()); } +TEST(ArrayRefTest, DropWhile) { + static const int TheNumbers[] = {1, 3, 5, 8, 10, 11}; + ArrayRef AR1(TheNumbers); + ArrayRef Expected = AR1.drop_front(3); + EXPECT_EQ(Expected, AR1.drop_while([](const int &N) { return N % 2 == 1; })); + + EXPECT_EQ(AR1, AR1.drop_while([](const int &N) { return N < 0; })); + EXPECT_EQ(ArrayRef(), + AR1.drop_while([](const int &N) { return N > 0; })); +} + +TEST(ArrayRefTest, DropUntil) { + static const int TheNumbers[] = {1, 3, 5, 8, 10, 11}; + ArrayRef AR1(TheNumbers); + ArrayRef Expected = AR1.drop_front(3); + EXPECT_EQ(Expected, AR1.drop_until([](const int &N) { return N % 2 == 0; })); + + EXPECT_EQ(ArrayRef(), + AR1.drop_until([](const int &N) { return N < 0; })); + EXPECT_EQ(AR1, AR1.drop_until([](const int &N) { return N > 0; })); +} + TEST(ArrayRefTest, TakeBack) { static const int TheNumbers[] = {4, 8, 15, 16, 23, 42}; ArrayRef AR1(TheNumbers); @@ -116,6 +138,28 @@ TEST(ArrayRefTest, TakeFront) { EXPECT_TRUE(AR1.take_front(2).equals(AR2)); } +TEST(ArrayRefTest, TakeWhile) { + static const int TheNumbers[] = {1, 3, 5, 8, 10, 11}; + ArrayRef AR1(TheNumbers); + ArrayRef Expected = AR1.take_front(3); + EXPECT_EQ(Expected, AR1.take_while([](const int &N) { return N % 2 == 1; })); + + EXPECT_EQ(ArrayRef(), + AR1.take_while([](const int &N) { return N < 0; })); + EXPECT_EQ(AR1, AR1.take_while([](const int &N) { return N > 0; })); +} + +TEST(ArrayRefTest, TakeUntil) { + static const int TheNumbers[] = {1, 3, 5, 8, 10, 11}; + ArrayRef AR1(TheNumbers); + ArrayRef Expected = AR1.take_front(3); + EXPECT_EQ(Expected, AR1.take_until([](const int &N) { return N % 2 == 0; })); + + EXPECT_EQ(AR1, AR1.take_until([](const int &N) { return N < 0; })); + EXPECT_EQ(ArrayRef(), + AR1.take_until([](const int &N) { return N > 0; })); +} + TEST(ArrayRefTest, Equals) { static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8}; ArrayRef AR1(A1); -- cgit v1.2.3