|
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | 9 | #include "llvm/ADT/MapVector.h" |
| 10 | +#include "llvm/ADT/ArrayRef.h" |
10 | 11 | #include "llvm/ADT/iterator_range.h" |
| 12 | +#include "gmock/gmock.h" |
11 | 13 | #include "gtest/gtest.h" |
12 | 14 | #include <memory> |
13 | 15 | #include <utility> |
@@ -267,6 +269,29 @@ TEST(MapVectorTest, NonCopyable) { |
267 | 269 | ASSERT_EQ(*MV.find(2)->second, 2); |
268 | 270 | } |
269 | 271 |
|
| 272 | +TEST(MapVectorTest, GetArrayRef) { |
| 273 | + MapVector<int, int> MV; |
| 274 | + |
| 275 | + // The underlying vector is empty to begin with. |
| 276 | + EXPECT_TRUE(MV.getArrayRef().empty()); |
| 277 | + |
| 278 | + // Test inserted element. |
| 279 | + MV.insert(std::make_pair(100, 99)); |
| 280 | + EXPECT_TRUE(MV.getArrayRef().equals({std::pair(100, 99)})); |
| 281 | + |
| 282 | + // Inserting a different element for an existing key won't change the |
| 283 | + // underlying vector. |
| 284 | + auto [Iter, Inserted] = MV.try_emplace(100, 98); |
| 285 | + EXPECT_FALSE(Inserted); |
| 286 | + EXPECT_EQ(Iter->second, 99); |
| 287 | + EXPECT_TRUE(MV.getArrayRef().equals({std::pair(100, 99)})); |
| 288 | + |
| 289 | + // Inserting a new element. Tests that elements are in order in the underlying |
| 290 | + // array. |
| 291 | + MV.insert(std::make_pair(99, 98)); |
| 292 | + EXPECT_TRUE(MV.getArrayRef().equals({std::pair(100, 99), std::pair(99, 98)})); |
| 293 | +} |
| 294 | + |
270 | 295 | template <class IntType> struct MapVectorMappedTypeTest : ::testing::Test { |
271 | 296 | using int_type = IntType; |
272 | 297 | }; |
|
0 commit comments