Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 EXPECT_EQ(3u, vector.size()); | 608 EXPECT_EQ(3u, vector.size()); |
| 609 vector.grow(4); | 609 vector.grow(4); |
| 610 ASSERT_EQ(4u, vector.size()); | 610 ASSERT_EQ(4u, vector.size()); |
| 611 EXPECT_TRUE(!vector[3]); | 611 EXPECT_TRUE(!vector[3]); |
| 612 vector.remove(3); | 612 vector.remove(3); |
| 613 vector[0] = Pointer(new int(-1)); | 613 vector[0] = Pointer(new int(-1)); |
| 614 ASSERT_EQ(3u, vector.size()); | 614 ASSERT_EQ(3u, vector.size()); |
| 615 EXPECT_EQ(-1, *vector[0]); | 615 EXPECT_EQ(-1, *vector[0]); |
| 616 } | 616 } |
| 617 | 617 |
| 618 TEST(VectorTest, InitializerList) | |
| 619 { | |
| 620 Vector<int> empty({}); | |
| 621 EXPECT_TRUE(empty.isEmpty()); | |
| 622 | |
| 623 Vector<int> one({1}); | |
| 624 ASSERT_EQ(1u, one.size()); | |
| 625 EXPECT_EQ(1, one[0]); | |
| 626 | |
| 627 Vector<int> oneTwoThree({1, 2, 3}); | |
| 628 ASSERT_EQ(3u, oneTwoThree.size()); | |
| 629 EXPECT_EQ(1, oneTwoThree[0]); | |
| 630 EXPECT_EQ(2, oneTwoThree[1]); | |
| 631 EXPECT_EQ(3, oneTwoThree[2]); | |
| 632 | |
| 633 // Put some jank so we can check if the assignments later can clear them. | |
| 634 empty.append(9999); | |
| 635 one.append(9999); | |
| 636 oneTwoThree.append(9999); | |
| 637 | |
| 638 empty = {}; | |
| 639 EXPECT_TRUE(empty.isEmpty()); | |
| 640 | |
| 641 one = {1}; | |
| 642 ASSERT_EQ(1u, one.size()); | |
| 643 EXPECT_EQ(1, one[0]); | |
| 644 | |
| 645 oneTwoThree = {1, 2, 3}; | |
| 646 ASSERT_EQ(3u, oneTwoThree.size()); | |
| 647 EXPECT_EQ(1, oneTwoThree[0]); | |
| 648 EXPECT_EQ(2, oneTwoThree[1]); | |
| 649 EXPECT_EQ(3, oneTwoThree[2]); | |
| 650 | |
| 651 // The tests below correspond to the cases in the "if" branch in operator=(s td::initializer_list<T>). | |
| 652 | |
| 653 // Shrinking. | |
| 654 Vector<int, 1> vector1(3); // capacity = 3. | |
| 655 vector1 = {1, 2}; | |
| 656 ASSERT_EQ(2u, vector1.size()); | |
| 657 EXPECT_EQ(1, vector1[0]); | |
| 658 EXPECT_EQ(2, vector1[1]); | |
| 659 | |
| 660 // Expanding. | |
| 661 Vector<int, 1> vector2(3); | |
| 662 vector2 = {1, 2, 3, 4}; | |
| 663 ASSERT_EQ(4u, vector2.size()); | |
| 664 EXPECT_EQ(1, vector2[0]); | |
| 665 EXPECT_EQ(2, vector2[1]); | |
| 666 EXPECT_EQ(3, vector2[2]); | |
| 667 EXPECT_EQ(4, vector2[3]); | |
| 668 | |
| 669 // Exact match. | |
| 670 Vector<int, 1> vector3(3); | |
| 671 vector3 = {1, 2, 3}; | |
| 672 ASSERT_EQ(3u, vector3.size()); | |
| 673 EXPECT_EQ(1, vector3[0]); | |
| 674 EXPECT_EQ(2, vector3[1]); | |
| 675 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.
| |
| 676 } | |
| 677 | |
| 618 } // anonymous namespace | 678 } // anonymous namespace |
| 619 | 679 |
| 620 } // namespace WTF | 680 } // namespace WTF |
| OLD | NEW |