diff options
author | Zachary Turner <zturner@google.com> | 2017-03-21 23:45:03 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-03-21 23:45:03 +0000 |
commit | aece9951e5ce9b1225bd3458d55fac18254a0b76 (patch) | |
tree | 3692d3dd4f5d32edca5bcc834f30e1e19a9abab7 /llvm/unittests/ADT/StringMapTest.cpp | |
parent | 15b3e8a93a4040238f4f7655a7b23a2f50716af8 (diff) | |
download | bcm5719-llvm-aece9951e5ce9b1225bd3458d55fac18254a0b76.tar.gz bcm5719-llvm-aece9951e5ce9b1225bd3458d55fac18254a0b76.zip |
Resubmit "Improve StringMap iterator support."
The issue was trying to advance past the end of the iterator
when computing the end() iterator.
llvm-svn: 298461
Diffstat (limited to 'llvm/unittests/ADT/StringMapTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/StringMapTest.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp index 911c72d7496..d2b1c31805e 100644 --- a/llvm/unittests/ADT/StringMapTest.cpp +++ b/llvm/unittests/ADT/StringMapTest.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringSet.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/DataTypes.h" #include "gtest/gtest.h" @@ -269,6 +270,34 @@ TEST_F(StringMapTest, InsertRehashingPairTest) { EXPECT_EQ(42u, It->second); } +TEST_F(StringMapTest, IterMapKeys) { + StringMap<int> Map; + Map["A"] = 1; + Map["B"] = 2; + Map["C"] = 3; + Map["D"] = 3; + + auto Keys = to_vector<4>(Map.keys()); + std::sort(Keys.begin(), Keys.end()); + + SmallVector<StringRef, 4> Expected = {"A", "B", "C", "D"}; + EXPECT_EQ(Expected, Keys); +} + +TEST_F(StringMapTest, IterSetKeys) { + StringSet<> Set; + Set.insert("A"); + Set.insert("B"); + Set.insert("C"); + Set.insert("D"); + + auto Keys = to_vector<4>(Set.keys()); + std::sort(Keys.begin(), Keys.end()); + + SmallVector<StringRef, 4> Expected = {"A", "B", "C", "D"}; + EXPECT_EQ(Expected, Keys); +} + // Create a non-default constructable value struct StringMapTestStruct { StringMapTestStruct(int i) : i(i) {} |