summaryrefslogtreecommitdiff
path: root/unittests/ADT/StringMapTest.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 10:51:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 10:51:19 +0000
commiteb11fae6d08f479c0799db45860a98af528fa6e7 (patch)
tree44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /unittests/ADT/StringMapTest.cpp
parentb8a2042aa938069e862750553db0e4d82d25822c (diff)
Notes
Diffstat (limited to 'unittests/ADT/StringMapTest.cpp')
-rw-r--r--unittests/ADT/StringMapTest.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp
index b5c63695ff35..1f5c4f031642 100644
--- a/unittests/ADT/StringMapTest.cpp
+++ b/unittests/ADT/StringMapTest.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Support/DataTypes.h"
#include "gtest/gtest.h"
+#include <limits>
#include <tuple>
using namespace llvm;
@@ -278,7 +279,7 @@ TEST_F(StringMapTest, IterMapKeys) {
Map["D"] = 3;
auto Keys = to_vector<4>(Map.keys());
- std::sort(Keys.begin(), Keys.end());
+ llvm::sort(Keys.begin(), Keys.end());
SmallVector<StringRef, 4> Expected = {"A", "B", "C", "D"};
EXPECT_EQ(Expected, Keys);
@@ -292,7 +293,7 @@ TEST_F(StringMapTest, IterSetKeys) {
Set.insert("D");
auto Keys = to_vector<4>(Set.keys());
- std::sort(Keys.begin(), Keys.end());
+ llvm::sort(Keys.begin(), Keys.end());
SmallVector<StringRef, 4> Expected = {"A", "B", "C", "D"};
EXPECT_EQ(Expected, Keys);
@@ -492,4 +493,43 @@ TEST(StringMapCustomTest, EmplaceTest) {
EXPECT_EQ(42, Map["abcd"].Data);
}
+// Test that StringMapEntryBase can handle size_t wide sizes.
+TEST(StringMapCustomTest, StringMapEntryBaseSize) {
+ size_t LargeValue;
+
+ // Test that the entry can represent max-unsigned.
+ if (sizeof(size_t) <= sizeof(unsigned))
+ LargeValue = std::numeric_limits<unsigned>::max();
+ else
+ LargeValue = std::numeric_limits<unsigned>::max() + 1ULL;
+ StringMapEntryBase LargeBase(LargeValue);
+ EXPECT_EQ(LargeValue, LargeBase.getKeyLength());
+
+ // Test that the entry can hold at least max size_t.
+ LargeValue = std::numeric_limits<size_t>::max();
+ StringMapEntryBase LargerBase(LargeValue);
+ LargeValue = std::numeric_limits<size_t>::max();
+ EXPECT_EQ(LargeValue, LargerBase.getKeyLength());
+}
+
+// Test that StringMapEntry can handle size_t wide sizes.
+TEST(StringMapCustomTest, StringMapEntrySize) {
+ size_t LargeValue;
+
+ // Test that the entry can represent max-unsigned.
+ if (sizeof(size_t) <= sizeof(unsigned))
+ LargeValue = std::numeric_limits<unsigned>::max();
+ else
+ LargeValue = std::numeric_limits<unsigned>::max() + 1ULL;
+ StringMapEntry<int> LargeEntry(LargeValue);
+ StringRef Key = LargeEntry.getKey();
+ EXPECT_EQ(LargeValue, Key.size());
+
+ // Test that the entry can hold at least max size_t.
+ LargeValue = std::numeric_limits<size_t>::max();
+ StringMapEntry<int> LargerEntry(LargeValue);
+ Key = LargerEntry.getKey();
+ EXPECT_EQ(LargeValue, Key.size());
+}
+
} // end anonymous namespace