|
10 | 10 | #include "CountCopyAndMove.h"
|
11 | 11 | #include "llvm/ADT/DenseMapInfo.h"
|
12 | 12 | #include "llvm/ADT/DenseMapInfoVariant.h"
|
| 13 | +#include "llvm/ADT/STLForwardCompat.h" |
13 | 14 | #include "llvm/ADT/SmallSet.h"
|
14 | 15 | #include "llvm/ADT/StringRef.h"
|
15 | 16 | #include "gmock/gmock.h"
|
@@ -249,6 +250,25 @@ TYPED_TEST(DenseMapTest, CopyConstructorNotSmallTest) {
|
249 | 250 | EXPECT_EQ(this->getValue(Key), copyMap[this->getKey(Key)]);
|
250 | 251 | }
|
251 | 252 |
|
| 253 | +// Test range constructors. |
| 254 | +TYPED_TEST(DenseMapTest, RangeConstructorTest) { |
| 255 | + using KeyAndValue = |
| 256 | + std::pair<typename TypeParam::key_type, typename TypeParam::mapped_type>; |
| 257 | + KeyAndValue PlainArray[] = {{this->getKey(0), this->getValue(0)}, |
| 258 | + {this->getKey(1), this->getValue(1)}}; |
| 259 | + |
| 260 | + TypeParam MapFromRange(llvm::from_range, PlainArray); |
| 261 | + EXPECT_EQ(2u, MapFromRange.size()); |
| 262 | + EXPECT_EQ(this->getValue(0), MapFromRange[this->getKey(0)]); |
| 263 | + EXPECT_EQ(this->getValue(1), MapFromRange[this->getKey(1)]); |
| 264 | + |
| 265 | + TypeParam MapFromInitList({{this->getKey(0), this->getValue(1)}, |
| 266 | + {this->getKey(1), this->getValue(2)}}); |
| 267 | + EXPECT_EQ(2u, MapFromInitList.size()); |
| 268 | + EXPECT_EQ(this->getValue(1), MapFromInitList[this->getKey(0)]); |
| 269 | + EXPECT_EQ(this->getValue(2), MapFromInitList[this->getKey(1)]); |
| 270 | +} |
| 271 | + |
252 | 272 | // Test copying from a default-constructed map.
|
253 | 273 | TYPED_TEST(DenseMapTest, CopyConstructorFromDefaultTest) {
|
254 | 274 | TypeParam copyMap(this->Map);
|
@@ -726,6 +746,15 @@ TEST(DenseMapCustomTest, FindAsTest) {
|
726 | 746 | EXPECT_TRUE(map.find_as("d") == map.end());
|
727 | 747 | }
|
728 | 748 |
|
| 749 | +TEST(DenseMapCustomTest, SmallDenseMapFromRange) { |
| 750 | + std::pair<int, StringRef> PlainArray[] = {{0, "0"}, {1, "1"}, {2, "2"}}; |
| 751 | + SmallDenseMap<int, StringRef> M(llvm::from_range, PlainArray); |
| 752 | + EXPECT_EQ(3u, M.size()); |
| 753 | + using testing::Pair; |
| 754 | + EXPECT_THAT(M, testing::UnorderedElementsAre(Pair(0, "0"), Pair(1, "1"), |
| 755 | + Pair(2, "2"))); |
| 756 | +} |
| 757 | + |
729 | 758 | TEST(DenseMapCustomTest, SmallDenseMapInitializerList) {
|
730 | 759 | SmallDenseMap<int, int> M = {{0, 0}, {0, 1}, {1, 2}};
|
731 | 760 | EXPECT_EQ(2u, M.size());
|
|
0 commit comments