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

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

Issue 1985393002: WTF: Add support for std::initializer_list in Vector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/Vector.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/VectorTest.cpp
diff --git a/third_party/WebKit/Source/wtf/VectorTest.cpp b/third_party/WebKit/Source/wtf/VectorTest.cpp
index 6f047688c4b806d6c7f8d62abd34dc51e925e28a..ad44a47f9a1d1bf27f1f0a24f489e8f02b4d631c 100644
--- a/third_party/WebKit/Source/wtf/VectorTest.cpp
+++ b/third_party/WebKit/Source/wtf/VectorTest.cpp
@@ -615,6 +615,66 @@ TEST(VectorTest, UniquePtr)
EXPECT_EQ(-1, *vector[0]);
}
+TEST(VectorTest, InitializerList)
+{
+ Vector<int> empty({});
+ EXPECT_TRUE(empty.isEmpty());
+
+ Vector<int> one({1});
+ ASSERT_EQ(1u, one.size());
+ EXPECT_EQ(1, one[0]);
+
+ Vector<int> oneTwoThree({1, 2, 3});
+ ASSERT_EQ(3u, oneTwoThree.size());
+ EXPECT_EQ(1, oneTwoThree[0]);
+ EXPECT_EQ(2, oneTwoThree[1]);
+ EXPECT_EQ(3, oneTwoThree[2]);
+
+ // Put some jank so we can check if the assignments later can clear them.
+ empty.append(9999);
+ one.append(9999);
+ oneTwoThree.append(9999);
+
+ empty = {};
+ EXPECT_TRUE(empty.isEmpty());
+
+ one = {1};
+ ASSERT_EQ(1u, one.size());
+ EXPECT_EQ(1, one[0]);
+
+ oneTwoThree = {1, 2, 3};
+ ASSERT_EQ(3u, oneTwoThree.size());
+ EXPECT_EQ(1, oneTwoThree[0]);
+ EXPECT_EQ(2, oneTwoThree[1]);
+ EXPECT_EQ(3, oneTwoThree[2]);
+
+ // The tests below correspond to the cases in the "if" branch in operator=(std::initializer_list<T>).
+
+ // Shrinking.
+ Vector<int, 1> vector1(3); // capacity = 3.
+ vector1 = {1, 2};
+ ASSERT_EQ(2u, vector1.size());
+ EXPECT_EQ(1, vector1[0]);
+ EXPECT_EQ(2, vector1[1]);
+
+ // Expanding.
+ Vector<int, 1> vector2(3);
+ vector2 = {1, 2, 3, 4};
+ ASSERT_EQ(4u, vector2.size());
+ EXPECT_EQ(1, vector2[0]);
+ EXPECT_EQ(2, vector2[1]);
+ EXPECT_EQ(3, vector2[2]);
+ EXPECT_EQ(4, vector2[3]);
+
+ // Exact match.
+ Vector<int, 1> vector3(3);
+ vector3 = {1, 2, 3};
+ ASSERT_EQ(3u, vector3.size());
+ EXPECT_EQ(1, vector3[0]);
+ EXPECT_EQ(2, vector3[1]);
+ EXPECT_EQ(3, vector3[2]);
tzik 2016/05/18 05:52:55 Could you add cases for an initializer_list on ret
Yuta Kitamura 2016/05/18 06:55:22 Done.
+}
+
} // anonymous namespace
} // namespace WTF
« no previous file with comments | « third_party/WebKit/Source/wtf/Vector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698