| 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 bool isOneTwoThree(const Vector<int>& vector) |
| 619 { |
| 620 return vector.size() == 3 && vector[0] == 1 && vector[1] == 2 && vector[2] =
= 3; |
| 621 } |
| 622 |
| 623 Vector<int> returnOneTwoThree() |
| 624 { |
| 625 return {1, 2, 3}; |
| 626 } |
| 627 |
| 628 TEST(VectorTest, InitializerList) |
| 629 { |
| 630 Vector<int> empty({}); |
| 631 EXPECT_TRUE(empty.isEmpty()); |
| 632 |
| 633 Vector<int> one({1}); |
| 634 ASSERT_EQ(1u, one.size()); |
| 635 EXPECT_EQ(1, one[0]); |
| 636 |
| 637 Vector<int> oneTwoThree({1, 2, 3}); |
| 638 ASSERT_EQ(3u, oneTwoThree.size()); |
| 639 EXPECT_EQ(1, oneTwoThree[0]); |
| 640 EXPECT_EQ(2, oneTwoThree[1]); |
| 641 EXPECT_EQ(3, oneTwoThree[2]); |
| 642 |
| 643 // Put some jank so we can check if the assignments later can clear them. |
| 644 empty.append(9999); |
| 645 one.append(9999); |
| 646 oneTwoThree.append(9999); |
| 647 |
| 648 empty = {}; |
| 649 EXPECT_TRUE(empty.isEmpty()); |
| 650 |
| 651 one = {1}; |
| 652 ASSERT_EQ(1u, one.size()); |
| 653 EXPECT_EQ(1, one[0]); |
| 654 |
| 655 oneTwoThree = {1, 2, 3}; |
| 656 ASSERT_EQ(3u, oneTwoThree.size()); |
| 657 EXPECT_EQ(1, oneTwoThree[0]); |
| 658 EXPECT_EQ(2, oneTwoThree[1]); |
| 659 EXPECT_EQ(3, oneTwoThree[2]); |
| 660 |
| 661 // Other ways of construction: as a function parameter and in a return state
ment. |
| 662 EXPECT_TRUE(isOneTwoThree({1, 2, 3})); |
| 663 EXPECT_TRUE(isOneTwoThree(returnOneTwoThree())); |
| 664 |
| 665 // The tests below correspond to the cases in the "if" branch in operator=(s
td::initializer_list<T>). |
| 666 |
| 667 // Shrinking. |
| 668 Vector<int, 1> vector1(3); // capacity = 3. |
| 669 vector1 = {1, 2}; |
| 670 ASSERT_EQ(2u, vector1.size()); |
| 671 EXPECT_EQ(1, vector1[0]); |
| 672 EXPECT_EQ(2, vector1[1]); |
| 673 |
| 674 // Expanding. |
| 675 Vector<int, 1> vector2(3); |
| 676 vector2 = {1, 2, 3, 4}; |
| 677 ASSERT_EQ(4u, vector2.size()); |
| 678 EXPECT_EQ(1, vector2[0]); |
| 679 EXPECT_EQ(2, vector2[1]); |
| 680 EXPECT_EQ(3, vector2[2]); |
| 681 EXPECT_EQ(4, vector2[3]); |
| 682 |
| 683 // Exact match. |
| 684 Vector<int, 1> vector3(3); |
| 685 vector3 = {1, 2, 3}; |
| 686 ASSERT_EQ(3u, vector3.size()); |
| 687 EXPECT_EQ(1, vector3[0]); |
| 688 EXPECT_EQ(2, vector3[1]); |
| 689 EXPECT_EQ(3, vector3[2]); |
| 690 } |
| 691 |
| 618 } // anonymous namespace | 692 } // anonymous namespace |
| 619 | 693 |
| 620 } // namespace WTF | 694 } // namespace WTF |
| OLD | NEW |