-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathmap_unmodifiable_cast_test.dart
81 lines (71 loc) · 2.32 KB
/
map_unmodifiable_cast_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2018, 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_unmodifiable_cast_test;
import "package:expect/expect.dart";
import 'dart:collection';
void main() {
testNum(const {1: 37}, "const");
testNum(const <num, num>{1: 37}.cast<int, int>(), "const.cast");
testNum(new UnmodifiableMapView({1: 37}), "unmod");
testNum(new UnmodifiableMapView<num, num>(<num, num>{1: 37}), "unmod.cast");
testNum(
new UnmodifiableMapView<num, num>(<num, num>{1: 37}).cast<int, int>(),
"unmodView<num>(num).cast<int>",
);
testNum(
new UnmodifiableMapView<num, num>(<int, int>{1: 37}).cast<int, int>(),
"unmodView<num>(int).cast<int>",
);
testNum(
new UnmodifiableMapView<Object, Object>(<num, num>{1: 37}).cast<int, int>(),
"unmodView<Object>(num).cast<int>",
);
testNum(
new UnmodifiableMapView<Object, Object>(<int, int>{1: 37}).cast<num, num>(),
"unmodView<Object>(int).cast<num>",
);
var m2 = new Map<num, num>.unmodifiable({1: 37});
testNum(m2, "Map<num>.unmod");
testNum(m2.cast<int, int>(), "Map<num>.unmod.cast<int>");
Map<Symbol, dynamic> nsm = new NsmMap().foo(a: 0);
test<Symbol, dynamic>(nsm, #a, 0, "nsm", noSuchMethodMap: true);
test<Object, int>(
nsm.cast<Object, int>(),
#a,
0,
"nsm.cast",
noSuchMethodMap: true,
);
}
void testNum(Map<Object, Object> map, String name) {
test<int, int>(map, 1, 37, name);
}
void test<K, V>(
map,
firstKey,
firstValue,
String name, {
bool noSuchMethodMap = false,
}) {
if (!noSuchMethodMap) {
Expect.isTrue(map.containsKey(firstKey), "$name.containsKey");
Expect.equals(1, map.length, "$name.length");
Expect.equals(firstKey, map.keys.first, "$name.keys.first");
Expect.equals(firstValue, map.values.first, "$name.values.first");
}
Expect.throwsUnsupportedError(map.clear, "$name.clear");
Expect.throwsUnsupportedError(() {
map.remove(firstKey);
}, "$name.remove");
Expect.throwsUnsupportedError(() {
map[firstKey] = firstValue;
}, "$name[]=");
Expect.throwsUnsupportedError(() {
map.addAll(<K, V>{firstKey: firstValue});
}, "$name.addAll");
}
class NsmMap {
noSuchMethod(i) => i.namedArguments;
foo({a, b, c, d});
}