| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 EXPECT_TRUE(iter == map.end()); | 646 EXPECT_TRUE(iter == map.end()); |
| 647 | 647 |
| 648 int oneThirty = map.take(Pair(MoveOnly(13), -13)); | 648 int oneThirty = map.take(Pair(MoveOnly(13), -13)); |
| 649 EXPECT_EQ(130, oneThirty); | 649 EXPECT_EQ(130, oneThirty); |
| 650 iter = map.find(Pair(MoveOnly(13), -13)); | 650 iter = map.find(Pair(MoveOnly(13), -13)); |
| 651 EXPECT_TRUE(iter == map.end()); | 651 EXPECT_TRUE(iter == map.end()); |
| 652 | 652 |
| 653 map.clear(); | 653 map.clear(); |
| 654 } | 654 } |
| 655 | 655 |
| 656 bool isOneTwoThree(const HashMap<int, int>& map) { |
| 657 return map.size() == 3 && map.contains(1) && map.contains(2) && |
| 658 map.contains(3) && map.get(1) == 11 && map.get(2) == 22 && |
| 659 map.get(3) == 33; |
| 660 }; |
| 661 |
| 662 HashMap<int, int> returnOneTwoThree() { |
| 663 return {{1, 11}, {2, 22}, {3, 33}}; |
| 664 }; |
| 665 |
| 666 TEST(HashMapTest, InitializerList) { |
| 667 HashMap<int, int> empty({}); |
| 668 EXPECT_TRUE(empty.isEmpty()); |
| 669 |
| 670 HashMap<int, int> one({{1, 11}}); |
| 671 EXPECT_EQ(one.size(), 1u); |
| 672 EXPECT_TRUE(one.contains(1)); |
| 673 EXPECT_EQ(one.get(1), 11); |
| 674 |
| 675 HashMap<int, int> oneTwoThree({{1, 11}, {2, 22}, {3, 33}}); |
| 676 EXPECT_EQ(oneTwoThree.size(), 3u); |
| 677 EXPECT_TRUE(oneTwoThree.contains(1)); |
| 678 EXPECT_TRUE(oneTwoThree.contains(2)); |
| 679 EXPECT_TRUE(oneTwoThree.contains(3)); |
| 680 EXPECT_EQ(oneTwoThree.get(1), 11); |
| 681 EXPECT_EQ(oneTwoThree.get(2), 22); |
| 682 EXPECT_EQ(oneTwoThree.get(3), 33); |
| 683 |
| 684 // Put some jank so we can check if the assignments can clear them later. |
| 685 empty.add(9999, 99999); |
| 686 one.add(9999, 99999); |
| 687 oneTwoThree.add(9999, 99999); |
| 688 |
| 689 empty = {}; |
| 690 EXPECT_TRUE(empty.isEmpty()); |
| 691 |
| 692 one = {{1, 11}}; |
| 693 EXPECT_EQ(one.size(), 1u); |
| 694 EXPECT_TRUE(one.contains(1)); |
| 695 EXPECT_EQ(one.get(1), 11); |
| 696 |
| 697 oneTwoThree = {{1, 11}, {2, 22}, {3, 33}}; |
| 698 EXPECT_EQ(oneTwoThree.size(), 3u); |
| 699 EXPECT_TRUE(oneTwoThree.contains(1)); |
| 700 EXPECT_TRUE(oneTwoThree.contains(2)); |
| 701 EXPECT_TRUE(oneTwoThree.contains(3)); |
| 702 EXPECT_EQ(oneTwoThree.get(1), 11); |
| 703 EXPECT_EQ(oneTwoThree.get(2), 22); |
| 704 EXPECT_EQ(oneTwoThree.get(3), 33); |
| 705 |
| 706 // Other ways of construction: as a function parameter and in a return |
| 707 // statement. |
| 708 EXPECT_TRUE(isOneTwoThree({{1, 11}, {2, 22}, {3, 33}})); |
| 709 EXPECT_TRUE(isOneTwoThree(returnOneTwoThree())); |
| 710 } |
| 711 |
| 656 } // anonymous namespace | 712 } // anonymous namespace |
| 657 | 713 |
| 658 } // namespace WTF | 714 } // namespace WTF |
| OLD | NEW |