OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import "package:expect/expect.dart"; | |
6 | |
7 const m1 = const {'a': 400 + 99}; | |
8 const m2 = const {'a': 499, 'b': 42}; | |
9 const m3 = const {'m1': m1, 'm2': m2}; | |
10 const m4 = const {'z': 9, 'a': 8, 'm': 7}; | |
11 const m5 = const {'': 499}; | |
12 const m6 = const {'a': 499}; | |
13 const m7 = const {}; | |
14 | |
15 bool isUnsupportedError(o) => o is UnsupportedError; | |
16 | |
17 main() { | |
18 Expect.equals(499, m1['a']); | |
19 Expect.equals(null, m1['b']); | |
20 Expect.listEquals(['a'], m1.keys.toList()); | |
21 Expect.listEquals([499], m1.values.toList()); | |
22 Expect.isTrue(m1.containsKey('a')); | |
23 Expect.isFalse(m1.containsKey('toString')); | |
24 Expect.isTrue(m1.containsValue(499)); | |
25 Expect.isFalse(m1.containsValue(42)); | |
26 Expect.isFalse(m1.containsValue(null)); | |
27 var seenKeys = []; | |
28 var seenValues = []; | |
29 m1.forEach((key, value) { | |
30 seenKeys.add(key); | |
31 seenValues.add(value); | |
32 }); | |
33 Expect.listEquals(['a'], seenKeys); | |
34 Expect.listEquals([499], seenValues); | |
35 Expect.isFalse(m1.isEmpty); | |
36 Expect.equals(1, m1.length); | |
37 Expect.throws(() => m1.remove('a'), isUnsupportedError); | |
38 Expect.throws(() => m1.remove('b'), isUnsupportedError); | |
39 Expect.throws(() => m1.clear(), isUnsupportedError); | |
40 Expect.throws(() => m1['b'] = 42, isUnsupportedError); | |
41 Expect.throws(() => m1['a'] = 499, isUnsupportedError); | |
42 Expect.throws(() => m1.putIfAbsent('a', () => 499), isUnsupportedError); | |
43 Expect.throws(() => m1.putIfAbsent('z', () => 499), isUnsupportedError); | |
44 | |
45 Expect.equals(499, m2['a']); | |
46 Expect.equals(42, m2['b']); | |
47 Expect.equals(null, m2['c']); | |
48 Expect.listEquals(['a', 'b'], m2.keys.toList()); | |
49 Expect.listEquals([499, 42], m2.values.toList()); | |
50 Expect.isTrue(m2.containsKey('a')); | |
51 Expect.isTrue(m2.containsKey('b')); | |
52 Expect.isFalse(m2.containsKey('toString')); | |
53 Expect.isTrue(m2.containsValue(499)); | |
54 Expect.isTrue(m2.containsValue(42)); | |
55 Expect.isFalse(m2.containsValue(99)); | |
56 Expect.isFalse(m2.containsValue(null)); | |
57 seenKeys = []; | |
58 seenValues = []; | |
59 m2.forEach((key, value) { | |
60 seenKeys.add(key); | |
61 seenValues.add(value); | |
62 }); | |
63 Expect.listEquals(['a', 'b'], seenKeys); | |
64 Expect.listEquals([499, 42], seenValues); | |
65 Expect.isFalse(m2.isEmpty); | |
66 Expect.equals(2, m2.length); | |
67 Expect.throws(() => m2.remove('a'), isUnsupportedError); | |
68 Expect.throws(() => m2.remove('b'), isUnsupportedError); | |
69 Expect.throws(() => m2.remove('c'), isUnsupportedError); | |
70 Expect.throws(() => m2.clear(), isUnsupportedError); | |
71 Expect.throws(() => m2['a'] = 499, isUnsupportedError); | |
72 Expect.throws(() => m2['b'] = 42, isUnsupportedError); | |
73 Expect.throws(() => m2['c'] = 499, isUnsupportedError); | |
74 Expect.throws(() => m2.putIfAbsent('a', () => 499), isUnsupportedError); | |
75 Expect.throws(() => m2.putIfAbsent('z', () => 499), isUnsupportedError); | |
76 Expect.throws(() => m2['a'] = 499, isUnsupportedError); | |
77 | |
78 Expect.identical(m3['m1'], m1); | |
79 Expect.identical(m3['m2'], m2); | |
80 | |
81 Expect.listEquals(['z', 'a', 'm'], m4.keys.toList()); | |
82 Expect.listEquals([9, 8, 7], m4.values.toList()); | |
83 seenKeys = []; | |
84 seenValues = []; | |
85 m4.forEach((key, value) { | |
86 seenKeys.add(key); | |
87 seenValues.add(value); | |
88 }); | |
89 Expect.listEquals(['z', 'a', 'm'], seenKeys); | |
90 Expect.listEquals([9, 8, 7], seenValues); | |
91 | |
92 Expect.equals(499, m5['']); | |
93 Expect.isTrue(m5.containsKey('')); | |
94 Expect.equals(1, m5.length); | |
95 | |
96 Expect.identical(m1, m6); | |
97 | |
98 Expect.isTrue(m7.isEmpty); | |
99 Expect.equals(0, m7.length); | |
100 Expect.equals(null, m7['b']); | |
101 Expect.listEquals([], m7.keys.toList()); | |
102 Expect.listEquals([], m7.values.toList()); | |
103 Expect.isFalse(m7.containsKey('a')); | |
104 Expect.isFalse(m7.containsKey('toString')); | |
105 Expect.isFalse(m7.containsValue(499)); | |
106 Expect.isFalse(m7.containsValue(null)); | |
107 seenKeys = []; | |
108 seenValues = []; | |
109 m7.forEach((key, value) { | |
110 seenKeys.add(key); | |
111 seenValues.add(value); | |
112 }); | |
113 Expect.listEquals([], seenKeys); | |
114 Expect.listEquals([], seenValues); | |
115 Expect.throws(() => m7.remove('a'), isUnsupportedError); | |
116 Expect.throws(() => m7.remove('b'), isUnsupportedError); | |
117 Expect.throws(() => m7.clear(), isUnsupportedError); | |
118 Expect.throws(() => m7['b'] = 42, isUnsupportedError); | |
119 Expect.throws(() => m7['a'] = 499, isUnsupportedError); | |
120 Expect.throws(() => m7.putIfAbsent('a', () => 499), isUnsupportedError); | |
121 Expect.throws(() => m7.putIfAbsent('z', () => 499), isUnsupportedError); | |
122 } | |
OLD | NEW |