OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 4482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4493 array.PrintJSON(&js, true); | 4493 array.PrintJSON(&js, true); |
4494 elideSubstring("classes", js.ToCString(), buffer); | 4494 elideSubstring("classes", js.ToCString(), buffer); |
4495 elideSubstring("objects", buffer, buffer); | 4495 elideSubstring("objects", buffer, buffer); |
4496 elideSubstring("_InternalLinkedHashMap@", buffer, buffer); | 4496 elideSubstring("_InternalLinkedHashMap@", buffer, buffer); |
4497 EXPECT_STREQ( | 4497 EXPECT_STREQ( |
4498 "{\"type\":\"@Instance\"," | 4498 "{\"type\":\"@Instance\"," |
4499 "\"_vmType\":\"LinkedHashMap\"," | 4499 "\"_vmType\":\"LinkedHashMap\"," |
4500 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4500 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4501 "\"name\":\"_InternalLinkedHashMap\",\"_vmName\":\"\"}," | 4501 "\"name\":\"_InternalLinkedHashMap\",\"_vmName\":\"\"}," |
4502 "\"kind\":\"Map\"," | 4502 "\"kind\":\"Map\"," |
4503 "\"id\":\"\"}", | 4503 "\"id\":\"\"," |
| 4504 "\"length\":0}", |
4504 buffer); | 4505 buffer); |
4505 } | 4506 } |
4506 // UserTag reference | 4507 // UserTag reference |
4507 { | 4508 { |
4508 JSONStream js; | 4509 JSONStream js; |
4509 Instance& tag = Instance::Handle(isolate->default_tag()); | 4510 Instance& tag = Instance::Handle(isolate->default_tag()); |
4510 tag.PrintJSON(&js, true); | 4511 tag.PrintJSON(&js, true); |
4511 elideSubstring("classes", js.ToCString(), buffer); | 4512 elideSubstring("classes", js.ToCString(), buffer); |
4512 elideSubstring("objects", buffer, buffer); | 4513 elideSubstring("objects", buffer, buffer); |
4513 elideSubstring("_UserTag@", buffer, buffer); | 4514 elideSubstring("_UserTag@", buffer, buffer); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4699 | 4700 |
4700 // 2. Create an empty internalized LinkedHashMap in C++. | 4701 // 2. Create an empty internalized LinkedHashMap in C++. |
4701 Instance& dart_map = Instance::Handle(); | 4702 Instance& dart_map = Instance::Handle(); |
4702 dart_map ^= Api::UnwrapHandle(h_result); | 4703 dart_map ^= Api::UnwrapHandle(h_result); |
4703 LinkedHashMap& cc_map = LinkedHashMap::Handle(LinkedHashMap::NewDefault()); | 4704 LinkedHashMap& cc_map = LinkedHashMap::Handle(LinkedHashMap::NewDefault()); |
4704 | 4705 |
4705 // 3. Expect them to have identical structure. | 4706 // 3. Expect them to have identical structure. |
4706 CheckIdenticalHashStructure(dart_map, cc_map); | 4707 CheckIdenticalHashStructure(dart_map, cc_map); |
4707 } | 4708 } |
4708 | 4709 |
| 4710 |
| 4711 TEST_CASE(LinkedHashMap_iteration) { |
| 4712 const char* kScript = |
| 4713 "makeMap() {\n" |
| 4714 " var map = {'x': 3, 'y': 4, 'z': 5, 'w': 6};\n" |
| 4715 " map.remove('y');\n" |
| 4716 " map.remove('w');\n" |
| 4717 " return map;\n" |
| 4718 "}"; |
| 4719 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
| 4720 EXPECT_VALID(h_lib); |
| 4721 Library& lib = Library::Handle(); |
| 4722 lib ^= Api::UnwrapHandle(h_lib); |
| 4723 EXPECT(!lib.IsNull()); |
| 4724 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL); |
| 4725 EXPECT_VALID(h_result); |
| 4726 |
| 4727 Instance& dart_map = Instance::Handle(); |
| 4728 dart_map ^= Api::UnwrapHandle(h_result); |
| 4729 ASSERT(dart_map.IsLinkedHashMap()); |
| 4730 const LinkedHashMap& cc_map = LinkedHashMap::Cast(dart_map); |
| 4731 |
| 4732 EXPECT_EQ(2, cc_map.Length()); |
| 4733 |
| 4734 LinkedHashMap::Iterator iterator(cc_map); |
| 4735 Object& object = Object::Handle(); |
| 4736 |
| 4737 EXPECT(iterator.MoveNext()); |
| 4738 object = iterator.CurrentKey(); |
| 4739 EXPECT_STREQ("x", object.ToCString()); |
| 4740 object = iterator.CurrentValue(); |
| 4741 EXPECT_STREQ("3", object.ToCString()); |
| 4742 |
| 4743 EXPECT(iterator.MoveNext()); |
| 4744 object = iterator.CurrentKey(); |
| 4745 EXPECT_STREQ("z", object.ToCString()); |
| 4746 object = iterator.CurrentValue(); |
| 4747 EXPECT_STREQ("5", object.ToCString()); |
| 4748 |
| 4749 EXPECT(!iterator.MoveNext()); |
| 4750 } |
| 4751 |
4709 } // namespace dart | 4752 } // namespace dart |
OLD | NEW |