summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/ArrayRefTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-07-27 01:11:19 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-07-27 01:11:19 +0000
commit3ea985b3758b6b8ca33a54e82d6fedc77ed53f9e (patch)
tree880d13180a3519c3cbc1514b1c051fcdaae48128 /llvm/unittests/ADT/ArrayRefTest.cpp
parentb72a2fdd722af7f56d4811ea403cf04521d71f35 (diff)
downloadbcm5719-llvm-3ea985b3758b6b8ca33a54e82d6fedc77ed53f9e.tar.gz
bcm5719-llvm-3ea985b3758b6b8ca33a54e82d6fedc77ed53f9e.zip
[ADT] Add a remarkbly useful little helper routine to ArrayRef for
checking whether the ArrayRef is equal to an explicit list of arguments. This is particularly easy to implement even without variadic templates because ArrayRef happens to be homogeneously typed. As a consequence we can use a "clever" wrapper type and default arguments to capture in a single method many arguments as well as *how many* arguments the user specified. Thanks to Dave Blaikie for helping me pull together this little helper. Suggestions for how to improve or generalize it are of course welcome. I'll be using it immediately in my follow-up patch. =D llvm-svn: 214041
Diffstat (limited to 'llvm/unittests/ADT/ArrayRefTest.cpp')
-rw-r--r--llvm/unittests/ADT/ArrayRefTest.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp
index 293afc6ea37..83a012d0cb1 100644
--- a/llvm/unittests/ADT/ArrayRefTest.cpp
+++ b/llvm/unittests/ADT/ArrayRefTest.cpp
@@ -36,5 +36,27 @@ TEST(ArrayRefTest, DropBack) {
EXPECT_TRUE(AR1.drop_back().equals(AR2));
}
+TEST(ArrayRefTest, Equals) {
+ static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8};
+ ArrayRef<int> AR1(A1);
+ EXPECT_TRUE(AR1.equals(1, 2, 3, 4, 5, 6, 7, 8));
+ EXPECT_FALSE(AR1.equals(8, 1, 2, 4, 5, 6, 6, 7));
+ EXPECT_FALSE(AR1.equals(2, 4, 5, 6, 6, 7, 8, 1));
+ EXPECT_FALSE(AR1.equals(0, 1, 2, 4, 5, 6, 6, 7));
+ EXPECT_FALSE(AR1.equals(1, 2, 42, 4, 5, 6, 7, 8));
+ EXPECT_FALSE(AR1.equals(42, 2, 3, 4, 5, 6, 7, 8));
+ EXPECT_FALSE(AR1.equals(1, 2, 3, 4, 5, 6, 7, 42));
+ EXPECT_FALSE(AR1.equals(1, 2, 3, 4, 5, 6, 7));
+ EXPECT_FALSE(AR1.equals(1, 2, 3, 4, 5, 6, 7, 8, 9));
+
+ ArrayRef<int> AR1a = AR1.drop_back();
+ EXPECT_TRUE(AR1a.equals(1, 2, 3, 4, 5, 6, 7));
+ EXPECT_FALSE(AR1a.equals(1, 2, 3, 4, 5, 6, 7, 8));
+
+ ArrayRef<int> AR1b = AR1a.slice(2, 4);
+ EXPECT_TRUE(AR1b.equals(3, 4, 5, 6));
+ EXPECT_FALSE(AR1b.equals(2, 3, 4, 5, 6));
+ EXPECT_FALSE(AR1b.equals(3, 4, 5, 6, 7));
+}
} // end anonymous namespace
OpenPOWER on IntegriCloud