Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: test/runtime/dart_runtime_test.dart

Issue 1043323002: Update dart_runtime.dart rules (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Handle mixins Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« lib/runtime/dart_runtime.dart ('K') | « lib/runtime/dart_runtime.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 // Test code 5 // Test code
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:mirrors'; 7 import 'dart:mirrors';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 import 'package:dev_compiler/config.dart'; 9 import 'package:dev_compiler/config.dart';
10 import 'package:dev_compiler/runtime/dart_runtime.dart'; 10 import 'package:dev_compiler/runtime/dart_runtime.dart';
(...skipping 17 matching lines...) Expand all
28 T x; 28 T x;
29 U y; 29 U y;
30 } 30 }
31 31
32 class BB<T, U> extends AA<U, T> { 32 class BB<T, U> extends AA<U, T> {
33 T z; 33 T z;
34 } 34 }
35 35
36 class CC extends BB<String, List> {} 36 class CC extends BB<String, List> {}
37 37
38 typedef Func2(x, y);
38 typedef B Foo(B b, String s); 39 typedef B Foo(B b, String s);
39 40
40 A bar1(C c, String s) => null; 41 A bar1(C c, String s) => null;
41 bar2(B b, String s) => null; 42 bar2(B b, String s) => null;
42 B bar3(B b, Object o) => null; 43 B bar3(B b, Object o) => null;
43 B bar4(B b, o) => null; 44 B bar4(B b, o) => null;
44 C bar5(A a, Object o) => null; 45 C bar5(A a, Object o) => null;
45 B bar6(B b, String s, String o) => null; 46 B bar6(B b, String s, String o) => null;
46 B bar7(B b, String s, [Object o]) => null; 47 B bar7(B b, String s, [Object o]) => null;
47 B bar8(B b, String s, {Object p}) => null; 48 B bar8(B b, String s, {Object p}) => null;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 test('Map', () { 132 test('Map', () {
132 final m1 = new Map<String, String>(); 133 final m1 = new Map<String, String>();
133 final m2 = new Map<Object, Object>(); 134 final m2 = new Map<Object, Object>();
134 final m3 = new Map(); 135 final m3 = new Map();
135 final m4 = new HashMap<dynamic, dynamic>(); 136 final m4 = new HashMap<dynamic, dynamic>();
136 final m5 = new LinkedHashMap(); 137 final m5 = new LinkedHashMap();
137 138
138 expect(isGroundType(Map), isTrue); 139 expect(isGroundType(Map), isTrue);
139 expect(isGroundType(m1.runtimeType), isFalse); 140 expect(isGroundType(m1.runtimeType), isFalse);
140 expect(isGroundType(type((Map<String, String> _) {})), isFalse); 141 expect(isGroundType(type((Map<String, String> _) {})), isFalse);
141 expect(isGroundType(m2.runtimeType), isFalse); 142 expect(isGroundType(m2.runtimeType), isTrue);
142 expect(isGroundType(type((Map<Object, Object> _) {})), isFalse); 143 expect(isGroundType(type((Map<Object, Object> _) {})), isTrue);
143 expect(isGroundType(m3.runtimeType), isTrue); 144 expect(isGroundType(m3.runtimeType), isTrue);
144 expect(isGroundType(type((Map _) {})), isTrue); 145 expect(isGroundType(type((Map _) {})), isTrue);
145 expect(isGroundType(m4.runtimeType), isTrue); 146 expect(isGroundType(m4.runtimeType), isTrue);
146 expect(isGroundType(type((HashMap<dynamic, dynamic> _) {})), isTrue); 147 expect(isGroundType(type((HashMap<dynamic, dynamic> _) {})), isTrue);
147 expect(isGroundType(m5.runtimeType), isTrue); 148 expect(isGroundType(m5.runtimeType), isTrue);
148 expect(isGroundType(type((LinkedHashMap _) {})), isTrue); 149 expect(isGroundType(type((LinkedHashMap _) {})), isTrue);
149 expect(isGroundType(LinkedHashMap), isTrue); 150 expect(isGroundType(LinkedHashMap), isTrue);
150 151
151 // Map<T1,T2> <: Map 152 // Map<T1,T2> <: Map
152 checkType(m1, Map); 153 checkType(m1, Map);
153 checkType(m1, Object); 154 checkType(m1, Object);
154 155
155 // Instance of self 156 // Instance of self
156 checkType(m1, m1.runtimeType); 157 checkType(m1, m1.runtimeType);
157 checkType(m1, type((Map<String, String> _) {})); 158 checkType(m1, type((Map<String, String> _) {}));
158 159
160 // Object == dynamic == top as a type parameter
161 checkType(m2, m3.runtimeType);
162 checkType(m2, Map);
163 checkType(m3, m2.runtimeType);
164 checkType(m3, type((Map<Object, Object> _) {}));
165
159 // Covariance on generics 166 // Covariance on generics
160 checkType(m1, m2.runtimeType); 167 checkType(m1, m2.runtimeType);
161 checkType(m1, type((Map<Object, Object> _) {})); 168 checkType(m1, type((Map<Object, Object> _) {}));
162 169
163 // No contravariance on generics. 170 // No contravariance on generics.
164 checkType(m2, m1.runtimeType, false); 171 checkType(m2, m1.runtimeType, false);
165 checkType(m2, type((Map<String, String> _) {}), false); 172 checkType(m2, type((Map<String, String> _) {}), false);
166 173
167 // null is! Map 174 // null is! Map
168 checkType(null, Map, false); 175 checkType(null, Map, false);
169 176
170 // Raw generic types 177 // Raw generic types
171 checkType(m5, Map); 178 checkType(m5, Map);
179 checkType(m5, type((Map<Object, Object> _) {}));
172 checkType(m4, Map); 180 checkType(m4, Map);
181 checkType(m4, type((Map<Object, Object> _) {}));
182
183 // Mixin: the actual implementation class should implement MapMixin
184 checkType(m1, MapMixin);
185 checkType(m1, type((MapMixin<String, String> _) {}));
186 checkType(m1, type((MapMixin<Object, Object> _) {}));
187 checkType(m5, MapMixin);
188 checkType(m5, type((MapMixin<String, String> _) {}), false);
189 checkType(m5, type((MapMixin<Object, Object> _) {}));
173 }); 190 });
174 191
175 test('generic and inheritance', () { 192 test('generic and inheritance', () {
176 AA aaraw = new AA(); 193 AA aaraw = new AA();
177 final aarawtype = aaraw.runtimeType; 194 final aarawtype = aaraw.runtimeType;
178 AA<dynamic, dynamic> aadynamic = new AA<dynamic, dynamic>(); 195 AA<dynamic, dynamic> aadynamic = new AA<dynamic, dynamic>();
179 final aadynamictype = aadynamic.runtimeType; 196 final aadynamictype = aadynamic.runtimeType;
180 AA<String, List> aa = new AA<String, List>(); 197 AA<String, List> aa = new AA<String, List>();
181 final aatype = aa.runtimeType; 198 final aatype = aa.runtimeType;
182 BB<String, List> bb = new BB<String, List>(); 199 BB<String, List> bb = new BB<String, List>();
(...skipping 29 matching lines...) Expand all
212 checkType(aaraw, type((AA<String> _) {})); 229 checkType(aaraw, type((AA<String> _) {}));
213 checkType(aaraw, aadynamictype); 230 checkType(aaraw, aadynamictype);
214 checkType(aaraw, type((AA<dynamic, dynamic> _) {})); 231 checkType(aaraw, type((AA<dynamic, dynamic> _) {}));
215 checkType(aadynamic, aarawtype); 232 checkType(aadynamic, aarawtype);
216 checkType(aadynamic, AA); 233 checkType(aadynamic, AA);
217 }); 234 });
218 235
219 test('Functions', () { 236 test('Functions', () {
220 // - return type: Dart is bivariant. We're covariant. 237 // - return type: Dart is bivariant. We're covariant.
221 // - param types: Dart is bivariant. We're contravariant. 238 // - param types: Dart is bivariant. We're contravariant.
239 expect(isGroundType(Func2), isTrue);
222 expect(isGroundType(Foo), isFalse); 240 expect(isGroundType(Foo), isFalse);
223 expect(isGroundType(type((B _(B _1, String _2)) {})), isFalse); 241 expect(isGroundType(type((B _(B _1, String _2)) {})), isFalse);
224 checkType(bar1, Foo, false); 242 checkType(bar1, Foo, false);
225 checkType(bar1, type((B _(B _1, String _2)) {}), false); 243 checkType(bar1, type((B _(B _1, String _2)) {}), false);
226 checkType(bar2, Foo, false); 244 checkType(bar2, Foo, false);
227 checkType(bar2, type((B _(B _1, String _2)) {}), false); 245 checkType(bar2, type((B _(B _1, String _2)) {}), false);
228 checkType(bar3, Foo); 246 checkType(bar3, Foo);
229 checkType(bar3, type((B _(B _1, String _2)) {})); 247 checkType(bar3, type((B _(B _1, String _2)) {}));
230 checkType(bar4, Foo); 248 checkType(bar4, Foo, false);
231 checkType(bar4, type((B _(B _1, String _2)) {})); 249 // TODO(vsm): Revisit. bar4 is (B, *) -> B. Perhaps it should be treated a s top for a reified object.
250 checkType(bar4, type((B _(B _1, String _2)) {}), false);
232 checkType(bar5, Foo); 251 checkType(bar5, Foo);
233 checkType(bar5, type((B _(B _1, String _2)) {})); 252 checkType(bar5, type((B _(B _1, String _2)) {}));
234 checkType(bar6, Foo, false); 253 checkType(bar6, Foo, false);
235 checkType(bar6, type((B _(B _1, String _2)) {}), false); 254 checkType(bar6, type((B _(B _1, String _2)) {}), false);
236 checkType(bar7, Foo); 255 checkType(bar7, Foo);
237 checkType(bar7, type((B _(B _1, String _2)) {})); 256 checkType(bar7, type((B _(B _1, String _2)) {}));
238 checkType(bar7, bar6.runtimeType); 257 checkType(bar7, bar6.runtimeType);
239 checkType(bar8, Foo); 258 checkType(bar8, Foo);
240 checkType(bar8, type((B _(B _1, String _2)) {})); 259 checkType(bar8, type((B _(B _1, String _2)) {}));
241 checkType(bar8, bar6.runtimeType, false); 260 checkType(bar8, bar6.runtimeType, false);
(...skipping 24 matching lines...) Expand all
266 test('arity', () { 285 test('arity', () {
267 checkArity(bar1, 2, 2); 286 checkArity(bar1, 2, 2);
268 checkArity(bar4, 2, 2); 287 checkArity(bar4, 2, 2);
269 checkArity(bar6, 3, 3); 288 checkArity(bar6, 3, 3);
270 checkArity(bar7, 2, 3); 289 checkArity(bar7, 2, 3);
271 checkArity(bar8, 2, 2); 290 checkArity(bar8, 2, 2);
272 checkArity(() {}, 0, 0); 291 checkArity(() {}, 0, 0);
273 checkArity((a, [b]) {}, 1, 2); 292 checkArity((a, [b]) {}, 1, 2);
274 }); 293 });
275 } 294 }
OLDNEW
« lib/runtime/dart_runtime.dart ('K') | « lib/runtime/dart_runtime.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698