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

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

Issue 1998543003: WTF: Add support for std::initializer_list in HashSet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify assignment. Created 4 years, 7 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 | « third_party/WebKit/Source/wtf/HashSet.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/HashSetTest.cpp
diff --git a/third_party/WebKit/Source/wtf/HashSetTest.cpp b/third_party/WebKit/Source/wtf/HashSetTest.cpp
index ca6555fa21cb0bf45cb3b47ad69628caf6fe625e..d9497665690d32ea8281ac30f338f85a09a785e2 100644
--- a/third_party/WebKit/Source/wtf/HashSetTest.cpp
+++ b/third_party/WebKit/Source/wtf/HashSetTest.cpp
@@ -447,6 +447,60 @@ TEST(HashSetTest, UniquePtr)
}
}
+bool isOneTwoThree(const HashSet<int>& set)
+{
+ return set.size() == 3 && set.contains(1) && set.contains(2) && set.contains(3);
+}
+
+HashSet<int> returnOneTwoThree()
+{
+ return {1, 2, 3};
+}
+
+TEST(HashSetTest, InitializerList)
+{
+ HashSet<int> empty({});
+ EXPECT_TRUE(empty.isEmpty());
+
+ HashSet<int> one({1});
+ EXPECT_EQ(1u, one.size());
+ EXPECT_TRUE(one.contains(1));
+
+ HashSet<int> oneTwoThree({1, 2, 3});
+ EXPECT_EQ(3u, oneTwoThree.size());
+ EXPECT_TRUE(oneTwoThree.contains(1));
+ EXPECT_TRUE(oneTwoThree.contains(2));
+ EXPECT_TRUE(oneTwoThree.contains(3));
+
+ // Put some jank so we can check if the assignments later can clear them.
+ empty.add(9999);
+ one.add(9999);
+ oneTwoThree.add(9999);
+
+ empty = {};
+ EXPECT_TRUE(empty.isEmpty());
+
+ one = {1};
+ EXPECT_EQ(1u, one.size());
+ EXPECT_TRUE(one.contains(1));
+
+ oneTwoThree = {1, 2, 3};
+ EXPECT_EQ(3u, oneTwoThree.size());
+ EXPECT_TRUE(oneTwoThree.contains(1));
+ EXPECT_TRUE(oneTwoThree.contains(2));
+ EXPECT_TRUE(oneTwoThree.contains(3));
+
+ oneTwoThree = {3, 1, 1, 2, 1, 1, 3};
+ EXPECT_EQ(3u, oneTwoThree.size());
+ EXPECT_TRUE(oneTwoThree.contains(1));
+ EXPECT_TRUE(oneTwoThree.contains(2));
+ EXPECT_TRUE(oneTwoThree.contains(3));
+
+ // Other ways of construction: as a function parameter and in a return statement.
+ EXPECT_TRUE(isOneTwoThree({1, 2, 3}));
+ EXPECT_TRUE(isOneTwoThree(returnOneTwoThree()));
+}
+
} // anonymous namespace
} // namespace WTF
« no previous file with comments | « third_party/WebKit/Source/wtf/HashSet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698