Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Unified Diff: third_party/WebKit/Source/wtf/HashMapTest.cpp

Issue 2042453002: Fix wtf::PairHashTraits to support types with isEmptyValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/HashTraits.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/HashMapTest.cpp
diff --git a/third_party/WebKit/Source/wtf/HashMapTest.cpp b/third_party/WebKit/Source/wtf/HashMapTest.cpp
index 25207ff7afd2e2f2ab0100351813f1891662da6a..f8b97ed0214f7085949dcfd1d696008d01b9a8f7 100644
--- a/third_party/WebKit/Source/wtf/HashMapTest.cpp
+++ b/third_party/WebKit/Source/wtf/HashMapTest.cpp
@@ -608,6 +608,67 @@ TEST(HashMapTest, UniquePtrAsValue)
}
}
+TEST(HashMapTest, MoveOnlyPairKeyType)
+{
+ using Pair = std::pair<MoveOnly, int>;
+ using TheMap = HashMap<Pair, int>;
+ TheMap map;
+ {
+ TheMap::AddResult addResult = map.add(Pair(MoveOnly(1), -1), 10);
+ EXPECT_TRUE(addResult.isNewEntry);
+ EXPECT_EQ(1, addResult.storedValue->key.first.value());
+ EXPECT_EQ(-1, addResult.storedValue->key.second);
+ EXPECT_EQ(10, addResult.storedValue->value);
+ }
+ auto iter = map.find(Pair(MoveOnly(1), -1));
+ ASSERT_TRUE(iter != map.end());
+ EXPECT_EQ(1, iter->key.first.value());
+ EXPECT_EQ(-1, iter->key.second);
+ EXPECT_EQ(10, iter->value);
+
+ iter = map.find(Pair(MoveOnly(1), 0));
+ EXPECT_TRUE(iter == map.end());
+
+ for (int i = 2; i < 32; ++i) {
+ TheMap::AddResult addResult = map.add(Pair(MoveOnly(i), -i), i * 10);
+ EXPECT_TRUE(addResult.isNewEntry);
+ EXPECT_EQ(i, addResult.storedValue->key.first.value());
+ EXPECT_EQ(-i, addResult.storedValue->key.second);
+ EXPECT_EQ(i * 10, addResult.storedValue->value);
+ }
+
+ iter = map.find(Pair(MoveOnly(1), -1));
+ ASSERT_TRUE(iter != map.end());
+ EXPECT_EQ(1, iter->key.first.value());
+ EXPECT_EQ(-1, iter->key.second);
+ EXPECT_EQ(10, iter->value);
+
+ iter = map.find(Pair(MoveOnly(7), -7));
+ ASSERT_TRUE(iter != map.end());
+ EXPECT_EQ(7, iter->key.first.value());
+ EXPECT_EQ(-7, iter->key.second);
+ EXPECT_EQ(70, iter->value);
+
+ {
+ TheMap::AddResult addResult = map.set(Pair(MoveOnly(9), -9), 999);
+ EXPECT_FALSE(addResult.isNewEntry);
+ EXPECT_EQ(9, addResult.storedValue->key.first.value());
+ EXPECT_EQ(-9, addResult.storedValue->key.second);
+ EXPECT_EQ(999, addResult.storedValue->value);
+ }
+
+ map.remove(Pair(MoveOnly(11), -11));
+ iter = map.find(Pair(MoveOnly(11), -11));
+ EXPECT_TRUE(iter == map.end());
+
+ int oneThirty = map.take(Pair(MoveOnly(13), -13));
+ EXPECT_EQ(130, oneThirty);
+ iter = map.find(Pair(MoveOnly(13), -13));
+ EXPECT_TRUE(iter == map.end());
+
+ map.clear();
+}
+
} // anonymous namespace
} // namespace WTF
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/HashTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698