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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 const m1 = const { '__proto__': 400 + 99 }; | 7 const m1 = const {'__proto__': 400 + 99}; |
8 const m2 = const { 'a': 499, 'b': 42 }; | 8 const m2 = const {'a': 499, 'b': 42}; |
9 const m3 = const { '__proto__': 499 }; | 9 const m3 = const {'__proto__': 499}; |
10 | 10 |
11 bool isUnsupportedError(o) => o is UnsupportedError; | 11 bool isUnsupportedError(o) => o is UnsupportedError; |
12 | 12 |
13 main() { | 13 main() { |
14 Expect.equals(499, m1['__proto__']); | 14 Expect.equals(499, m1['__proto__']); |
15 Expect.equals(null, m1['b']); | 15 Expect.equals(null, m1['b']); |
16 Expect.listEquals(['__proto__'], m1.keys.toList()); | 16 Expect.listEquals(['__proto__'], m1.keys.toList()); |
17 Expect.listEquals([499], m1.values.toList()); | 17 Expect.listEquals([499], m1.values.toList()); |
18 Expect.isTrue(m1.containsKey('__proto__')); | 18 Expect.isTrue(m1.containsKey('__proto__')); |
19 Expect.isFalse(m1.containsKey('toString')); | 19 Expect.isFalse(m1.containsKey('toString')); |
20 Expect.isTrue(m1.containsValue(499)); | 20 Expect.isTrue(m1.containsValue(499)); |
21 Expect.isFalse(m1.containsValue(null)); | 21 Expect.isFalse(m1.containsValue(null)); |
22 var seenKeys = []; | 22 var seenKeys = []; |
23 var seenValues = []; | 23 var seenValues = []; |
24 m1.forEach((key, value) { | 24 m1.forEach((key, value) { |
25 seenKeys.add(key); | 25 seenKeys.add(key); |
26 seenValues.add(value); | 26 seenValues.add(value); |
27 }); | 27 }); |
28 Expect.listEquals(['__proto__'], seenKeys); | 28 Expect.listEquals(['__proto__'], seenKeys); |
29 Expect.listEquals([499], seenValues); | 29 Expect.listEquals([499], seenValues); |
30 Expect.isFalse(m1.isEmpty); | 30 Expect.isFalse(m1.isEmpty); |
31 Expect.equals(1, m1.length); | 31 Expect.equals(1, m1.length); |
32 Expect.throws(() => m1.remove('__proto__'), isUnsupportedError); | 32 Expect.throws(() => m1.remove('__proto__'), isUnsupportedError); |
33 Expect.throws(() => m1.remove('b'), isUnsupportedError); | 33 Expect.throws(() => m1.remove('b'), isUnsupportedError); |
34 Expect.throws(() => m1.clear(), isUnsupportedError); | 34 Expect.throws(() => m1.clear(), isUnsupportedError); |
35 Expect.throws(() => m1['b'] = 42, isUnsupportedError); | 35 Expect.throws(() => m1['b'] = 42, isUnsupportedError); |
36 Expect.throws(() => m1['__proto__'] = 499, isUnsupportedError); | 36 Expect.throws(() => m1['__proto__'] = 499, isUnsupportedError); |
37 Expect.throws(() => m1.putIfAbsent('__proto__', () => 499), | 37 Expect.throws( |
38 isUnsupportedError); | 38 () => m1.putIfAbsent('__proto__', () => 499), isUnsupportedError); |
39 Expect.throws(() => m1.putIfAbsent('z', () => 499), isUnsupportedError); | 39 Expect.throws(() => m1.putIfAbsent('z', () => 499), isUnsupportedError); |
40 | 40 |
41 Expect.equals(499, m2['a']); | 41 Expect.equals(499, m2['a']); |
42 Expect.equals(42, m2['b']); | 42 Expect.equals(42, m2['b']); |
43 Expect.equals(null, m2['c']); | 43 Expect.equals(null, m2['c']); |
44 Expect.equals(null, m2['__proto__']); | 44 Expect.equals(null, m2['__proto__']); |
45 Expect.listEquals(['a', 'b'], m2.keys.toList()); | 45 Expect.listEquals(['a', 'b'], m2.keys.toList()); |
46 Expect.listEquals([499, 42], m2.values.toList()); | 46 Expect.listEquals([499, 42], m2.values.toList()); |
47 Expect.isTrue(m2.containsKey('a')); | 47 Expect.isTrue(m2.containsKey('a')); |
48 Expect.isTrue(m2.containsKey('b')); | 48 Expect.isTrue(m2.containsKey('b')); |
(...skipping 13 matching lines...) Expand all Loading... |
62 Expect.isFalse(m2.isEmpty); | 62 Expect.isFalse(m2.isEmpty); |
63 Expect.equals(2, m2.length); | 63 Expect.equals(2, m2.length); |
64 Expect.throws(() => m2.remove('a'), isUnsupportedError); | 64 Expect.throws(() => m2.remove('a'), isUnsupportedError); |
65 Expect.throws(() => m2.remove('b'), isUnsupportedError); | 65 Expect.throws(() => m2.remove('b'), isUnsupportedError); |
66 Expect.throws(() => m2.remove('__proto__'), isUnsupportedError); | 66 Expect.throws(() => m2.remove('__proto__'), isUnsupportedError); |
67 Expect.throws(() => m2.clear(), isUnsupportedError); | 67 Expect.throws(() => m2.clear(), isUnsupportedError); |
68 Expect.throws(() => m2['a'] = 499, isUnsupportedError); | 68 Expect.throws(() => m2['a'] = 499, isUnsupportedError); |
69 Expect.throws(() => m2['b'] = 42, isUnsupportedError); | 69 Expect.throws(() => m2['b'] = 42, isUnsupportedError); |
70 Expect.throws(() => m2['__proto__'] = 499, isUnsupportedError); | 70 Expect.throws(() => m2['__proto__'] = 499, isUnsupportedError); |
71 Expect.throws(() => m2.putIfAbsent('a', () => 499), isUnsupportedError); | 71 Expect.throws(() => m2.putIfAbsent('a', () => 499), isUnsupportedError); |
72 Expect.throws(() => m2.putIfAbsent('__proto__', () => 499), | 72 Expect.throws( |
73 isUnsupportedError); | 73 () => m2.putIfAbsent('__proto__', () => 499), isUnsupportedError); |
74 Expect.throws(() => m2['a'] = 499, isUnsupportedError); | 74 Expect.throws(() => m2['a'] = 499, isUnsupportedError); |
75 | 75 |
76 Expect.isTrue(identical(m1, m3)); | 76 Expect.isTrue(identical(m1, m3)); |
77 } | 77 } |
OLD | NEW |