OLD | NEW |
(Empty) | |
| 1 dart_library.library('corelib/map_from_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__map_from_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const collection = dart_sdk.collection; |
| 8 const dart = dart_sdk.dart; |
| 9 const dartx = dart_sdk.dartx; |
| 10 const expect$ = expect.expect; |
| 11 const map_from_test = Object.create(null); |
| 12 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 13 let dynamicAnddynamicTodynamic = () => (dynamicAnddynamicTodynamic = dart.cons
tFn(dart.definiteFunctionType(dart.dynamic, [dart.dynamic, dart.dynamic])))(); |
| 14 let dynamicToint = () => (dynamicToint = dart.constFn(dart.definiteFunctionTyp
e(core.int, [dart.dynamic])))(); |
| 15 map_from_test.main = function() { |
| 16 map_from_test.testWithConstMap(); |
| 17 map_from_test.testWithNonConstMap(); |
| 18 map_from_test.testWithHashMap(); |
| 19 map_from_test.testWithLinkedMap(); |
| 20 }; |
| 21 dart.fn(map_from_test.main, VoidTodynamic()); |
| 22 let const$; |
| 23 map_from_test.testWithConstMap = function() { |
| 24 let map = const$ || (const$ = dart.const(dart.map({b: 42, a: 43}))); |
| 25 let otherMap = core.Map.from(map); |
| 26 expect$.Expect.isTrue(core.Map.is(otherMap)); |
| 27 expect$.Expect.isTrue(collection.HashMap.is(otherMap)); |
| 28 expect$.Expect.isTrue(collection.LinkedHashMap.is(otherMap)); |
| 29 expect$.Expect.equals(2, otherMap[dartx.length]); |
| 30 expect$.Expect.equals(2, otherMap[dartx.keys][dartx.length]); |
| 31 expect$.Expect.equals(2, otherMap[dartx.values][dartx.length]); |
| 32 let count = dart.fn(map => { |
| 33 let cnt = 0; |
| 34 dart.dsend(map, 'forEach', dart.fn((a, b) => { |
| 35 cnt = dart.notNull(cnt) + dart.notNull(core.int._check(b)); |
| 36 }, dynamicAnddynamicTodynamic())); |
| 37 return cnt; |
| 38 }, dynamicToint()); |
| 39 expect$.Expect.equals(42 + 43, dart.dcall(count, map)); |
| 40 expect$.Expect.equals(dart.dcall(count, map), dart.dcall(count, otherMap)); |
| 41 }; |
| 42 dart.fn(map_from_test.testWithConstMap, VoidTodynamic()); |
| 43 map_from_test.testWithNonConstMap = function() { |
| 44 let map = dart.map({b: 42, a: 43}); |
| 45 let otherMap = core.Map.from(map); |
| 46 expect$.Expect.isTrue(core.Map.is(otherMap)); |
| 47 expect$.Expect.isTrue(collection.HashMap.is(otherMap)); |
| 48 expect$.Expect.isTrue(collection.LinkedHashMap.is(otherMap)); |
| 49 expect$.Expect.equals(2, otherMap[dartx.length]); |
| 50 expect$.Expect.equals(2, otherMap[dartx.keys][dartx.length]); |
| 51 expect$.Expect.equals(2, otherMap[dartx.values][dartx.length]); |
| 52 function count(map) { |
| 53 let count = 0; |
| 54 dart.dsend(map, 'forEach', dart.fn((a, b) => { |
| 55 count = dart.notNull(count) + dart.notNull(core.int._check(b)); |
| 56 }, dynamicAnddynamicTodynamic())); |
| 57 return count; |
| 58 } |
| 59 dart.fn(count, dynamicToint()); |
| 60 ; |
| 61 expect$.Expect.equals(42 + 43, count(map)); |
| 62 expect$.Expect.equals(count(map), count(otherMap)); |
| 63 map[dartx.set]('c', 44); |
| 64 expect$.Expect.equals(3, map[dartx.length]); |
| 65 expect$.Expect.equals(2, otherMap[dartx.length]); |
| 66 expect$.Expect.equals(2, otherMap[dartx.keys][dartx.length]); |
| 67 expect$.Expect.equals(2, otherMap[dartx.values][dartx.length]); |
| 68 otherMap[dartx.set]('c', 44); |
| 69 expect$.Expect.equals(3, map[dartx.length]); |
| 70 expect$.Expect.equals(3, otherMap[dartx.length]); |
| 71 expect$.Expect.equals(3, otherMap[dartx.keys][dartx.length]); |
| 72 expect$.Expect.equals(3, otherMap[dartx.values][dartx.length]); |
| 73 }; |
| 74 dart.fn(map_from_test.testWithNonConstMap, VoidTodynamic()); |
| 75 let const$0; |
| 76 map_from_test.testWithHashMap = function() { |
| 77 let map = const$0 || (const$0 = dart.const(dart.map({b: 1, a: 2, c: 3}))); |
| 78 let otherMap = collection.HashMap.from(map); |
| 79 expect$.Expect.isTrue(core.Map.is(otherMap)); |
| 80 expect$.Expect.isTrue(collection.HashMap.is(otherMap)); |
| 81 expect$.Expect.isTrue(!collection.LinkedHashMap.is(otherMap)); |
| 82 let i = 1; |
| 83 for (let val of map[dartx.values]) { |
| 84 expect$.Expect.equals(i++, val); |
| 85 } |
| 86 }; |
| 87 dart.fn(map_from_test.testWithHashMap, VoidTodynamic()); |
| 88 let const$1; |
| 89 map_from_test.testWithLinkedMap = function() { |
| 90 let map = const$1 || (const$1 = dart.const(dart.map({b: 1, a: 2, c: 3}))); |
| 91 let otherMap = collection.LinkedHashMap.from(map); |
| 92 expect$.Expect.isTrue(core.Map.is(otherMap)); |
| 93 expect$.Expect.isTrue(collection.HashMap.is(otherMap)); |
| 94 expect$.Expect.isTrue(collection.LinkedHashMap.is(otherMap)); |
| 95 let i = 1; |
| 96 for (let val of map[dartx.values]) { |
| 97 expect$.Expect.equals(i++, val); |
| 98 } |
| 99 }; |
| 100 dart.fn(map_from_test.testWithLinkedMap, VoidTodynamic()); |
| 101 // Exports: |
| 102 exports.map_from_test = map_from_test; |
| 103 }); |
OLD | NEW |