OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 main() { | 9 main() { |
10 // Unique object. | 10 // Unique object. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 Expect.equals("baz", Zone.current[baz]); | 86 Expect.equals("baz", Zone.current[baz]); |
87 Expect.isNull(Zone.current[mimic]); | 87 Expect.isNull(Zone.current[mimic]); |
88 Expect.equals("zero!", Zone.current[0]); | 88 Expect.equals("zero!", Zone.current[0]); |
89 Expect.equals(baz, Zone.current[null]); | 89 Expect.equals(baz, Zone.current[null]); |
90 Expect.isNull(Zone.current["qux"]); | 90 Expect.isNull(Zone.current["qux"]); |
91 }); | 91 }); |
92 | 92 |
93 // Creating a further nested zone with new values allows keeping, overriding, | 93 // Creating a further nested zone with new values allows keeping, overriding, |
94 // and shadowing existing values from the outer zone. | 94 // and shadowing existing values from the outer zone. |
95 zoneValues = new Map(); | 95 zoneValues = new Map(); |
96 zoneValues[#foo] = -499; // Values can be overridden. | 96 zoneValues[#foo] = -499; // Values can be overridden. |
97 zoneValues["bar"] = null; // Values can be changed to null. | 97 zoneValues["bar"] = null; // Values can be changed to null. |
98 zoneValues["qux"] = 99; // Values can be added | 98 zoneValues["qux"] = 99; // Values can be added |
99 // Overriding with equal, but not identical, key is possible. | 99 // Overriding with equal, but not identical, key is possible. |
100 zoneValues[mimic] = "floo"; | 100 zoneValues[mimic] = "floo"; |
101 zoneValues[0.0] = "zero!ZERO!"; | 101 zoneValues[0.0] = "zero!ZERO!"; |
102 | 102 |
103 Zone forkedChild = forked.fork(zoneValues: zoneValues); | 103 Zone forkedChild = forked.fork(zoneValues: zoneValues); |
104 | 104 |
105 // New values available on zone. | 105 // New values available on zone. |
106 Expect.equals(-499, forkedChild[#foo]); // Overridden. | 106 Expect.equals(-499, forkedChild[#foo]); // Overridden. |
107 Expect.isNull(forkedChild["bar"]); // Overridden to null. | 107 Expect.isNull(forkedChild["bar"]); // Overridden to null. |
108 Expect.equals("floo", forkedChild[baz]); // Overridden by mimic. | 108 Expect.equals("floo", forkedChild[baz]); // Overridden by mimic. |
109 Expect.equals("floo", forkedChild[mimic]); // Now recognizes mimic. | 109 Expect.equals("floo", forkedChild[mimic]); // Now recognizes mimic. |
110 Expect.equals("zero!ZERO!", forkedChild[0]); // Overridden by 0.0. | 110 Expect.equals("zero!ZERO!", forkedChild[0]); // Overridden by 0.0. |
111 Expect.equals("zero!ZERO!", forkedChild[0.0]); // Overriding 0. | 111 Expect.equals("zero!ZERO!", forkedChild[0.0]); // Overriding 0. |
112 Expect.equals(baz, forkedChild[null]); // Inherited. | 112 Expect.equals(baz, forkedChild[null]); // Inherited. |
113 Expect.equals(99, forkedChild["qux"]); // Added. | 113 Expect.equals(99, forkedChild["qux"]); // Added. |
114 | 114 |
115 forkedChild.run(() { | 115 forkedChild.run(() { |
116 Expect.identical(forkedChild, Zone.current); // Sanity check. | 116 Expect.identical(forkedChild, Zone.current); // Sanity check. |
117 // New values available on current zone when the zone is current. | 117 // New values available on current zone when the zone is current. |
118 Expect.equals(-499, Zone.current[#foo]); // Overridden. | 118 Expect.equals(-499, Zone.current[#foo]); // Overridden. |
119 Expect.isNull(Zone.current["bar"]); // Overridden to null. | 119 Expect.isNull(Zone.current["bar"]); // Overridden to null. |
120 Expect.equals("floo", Zone.current[baz]); // Overridden by mimic. | 120 Expect.equals("floo", Zone.current[baz]); // Overridden by mimic. |
121 Expect.equals("floo", Zone.current[mimic]); // Now recognizes mimic. | 121 Expect.equals("floo", Zone.current[mimic]); // Now recognizes mimic. |
122 Expect.equals("zero!ZERO!", Zone.current[0]); // Overridden by 0.0. | 122 Expect.equals("zero!ZERO!", Zone.current[0]); // Overridden by 0.0. |
123 Expect.equals("zero!ZERO!", Zone.current[0.0]); // Overriding 0. | 123 Expect.equals("zero!ZERO!", Zone.current[0.0]); // Overriding 0. |
124 Expect.equals(baz, Zone.current[null]); // Inherited. | 124 Expect.equals(baz, Zone.current[null]); // Inherited. |
125 Expect.equals(99, Zone.current["qux"]); // Added. | 125 Expect.equals(99, Zone.current["qux"]); // Added. |
126 }); | 126 }); |
127 | 127 |
128 // Parent zone values are unchanged. | 128 // Parent zone values are unchanged. |
129 Expect.equals(499, forked[#foo]); | 129 Expect.equals(499, forked[#foo]); |
130 Expect.listEquals([42], forked["bar"]); | 130 Expect.listEquals([42], forked["bar"]); |
131 Expect.equals("baz", forked[baz]); | 131 Expect.equals("baz", forked[baz]); |
132 Expect.isNull(Zone.current[mimic]); | 132 Expect.isNull(Zone.current[mimic]); |
133 Expect.equals("zero!", forked[0]); | 133 Expect.equals("zero!", forked[0]); |
134 Expect.equals("zero!", forked[0.0]); // Lookup uses equality. | 134 Expect.equals("zero!", forked[0.0]); // Lookup uses equality. |
135 Expect.equals("zero!", forked[-0.0]); | 135 Expect.equals("zero!", forked[-0.0]); |
136 Expect.equals(baz, forked[null]); | 136 Expect.equals(baz, forked[null]); |
137 Expect.isNull(forked["qux"]); | 137 Expect.isNull(forked["qux"]); |
138 } | 138 } |
139 | 139 |
140 // Class of objects that consider themselves equal to their originals. | 140 // Class of objects that consider themselves equal to their originals. |
141 // Sees through mimickry. | 141 // Sees through mimickry. |
142 class Mimic { | 142 class Mimic { |
143 final Object original; | 143 final Object original; |
144 Mimic(this.original); | 144 Mimic(this.original); |
145 int get hashCode => original.hashCode; | 145 int get hashCode => original.hashCode; |
146 bool operator==(Object other) => | 146 bool operator==(Object other) => |
147 (other is Mimic) ? this == other.original : original == other; | 147 (other is Mimic) ? this == other.original : original == other; |
148 } | 148 } |
OLD | NEW |