summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/ArrayRefTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/ADT/ArrayRefTest.cpp')
-rw-r--r--llvm/unittests/ADT/ArrayRefTest.cpp44
1 files changed, 44 insertions, 0 deletions
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<int> AR1(TheNumbers);
+ ArrayRef<int> 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<int>(),
+ AR1.drop_while([](const int &N) { return N > 0; }));
+}
+
+TEST(ArrayRefTest, DropUntil) {
+ static const int TheNumbers[] = {1, 3, 5, 8, 10, 11};
+ ArrayRef<int> AR1(TheNumbers);
+ ArrayRef<int> Expected = AR1.drop_front(3);
+ EXPECT_EQ(Expected, AR1.drop_until([](const int &N) { return N % 2 == 0; }));
+
+ EXPECT_EQ(ArrayRef<int>(),
+ 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<int> 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<int> AR1(TheNumbers);
+ ArrayRef<int> Expected = AR1.take_front(3);
+ EXPECT_EQ(Expected, AR1.take_while([](const int &N) { return N % 2 == 1; }));
+
+ EXPECT_EQ(ArrayRef<int>(),
+ 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<int> AR1(TheNumbers);
+ ArrayRef<int> 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<int>(),
+ 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<int> AR1(A1);
OpenPOWER on IntegriCloud