// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. library map.from.test; import "package:expect/expect.dart"; import 'dart:collection'; main() { for (Map map in [ {}, const {}, new HashMap(), new LinkedHashMap(), new SplayTreeMap(), {1: 11, 2: 12, 4: 14}, const {1: 11, 2: 12, 4: 14}, new Map() ..[1] = 11 ..[2] = 12 ..[3] = 13, new HashMap() ..[1] = 11 ..[2] = 12 ..[3] = 13, new LinkedHashMap() ..[1] = 11 ..[2] = 12 ..[3] = 13, new SplayTreeMap() ..[1] = 11 ..[2] = 12 ..[3] = 13, ]) { expectThrows(void operation()) { Expect.throwsTypeError(operation); } var sourceType = map.runtimeType.toString(); check(sourceType, map, new Map.of(map)); check(sourceType, map, new Map.of(map)); check(sourceType, map, new HashMap.of(map)); check(sourceType, map, new HashMap.of(map)); check(sourceType, map, new LinkedHashMap.of(map)); check(sourceType, map, new LinkedHashMap.of(map)); check(sourceType, map, new SplayTreeMap.of(map)); check(sourceType, map, new SplayTreeMap.of(map)); } } check(String sourceType, Map expect, Map actual) { var targetType = actual.runtimeType.toString(); var name = "$sourceType->$targetType"; Expect.equals(expect.length, actual.length, "$name.length"); for (var key in expect.keys) { Expect.isTrue(actual.containsKey(key), "$name?[$key]"); Expect.equals(expect[key], actual[key], "$name[$key]"); } }