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

Side by Side Diff: tests/compiler/dart2js/subtype_test.dart

Issue 14295018: Support new function subtyping rules in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
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 library subtype_test; 5 library subtype_test;
6 6
7 import 'package:expect/expect.dart'; 7 import 'package:expect/expect.dart';
8 import 'type_test_helper.dart'; 8 import 'type_test_helper.dart';
9 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; 9 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart';
10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t" 10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 355
356 testFunctionSubtypingOptional() { 356 testFunctionSubtypingOptional() {
357 var env = new TypeEnvironment(r""" 357 var env = new TypeEnvironment(r"""
358 void void_() {} 358 void void_() {}
359 void void__int(int i) {} 359 void void__int(int i) {}
360 void void___int([int i]) {} 360 void void___int([int i]) {}
361 void void___int2([int i]) {} 361 void void___int2([int i]) {}
362 void void___Object([Object o]) {} 362 void void___Object([Object o]) {}
363 void void__int__int(int i1, [int i2]) {} 363 void void__int__int(int i1, [int i2]) {}
364 void void__int__int2(int i1, [int i2]) {} 364 void void__int__int2(int i1, [int i2]) {}
365 void void__int__int_int(int i1, [int i2, int i3]);
365 void void___double(double d) {} 366 void void___double(double d) {}
366 void void___int_int([int i1, int i2]) {} 367 void void___int_int([int i1, int i2]) {}
368 void void___int_int_int([int i1, int i2, int i3]);
karlklose 2013/04/24 11:59:20 This is not used, is it?
Johnni Winther 2013/04/25 07:54:12 Done.
367 void void___Object_int([Object o, int i]) {} 369 void void___Object_int([Object o, int i]) {}
368 """); 370 """);
369 functionSubtypingOptionalHelper(env); 371 functionSubtypingOptionalHelper(env);
370 } 372 }
371 373
372 testTypedefSubtypingOptional() { 374 testTypedefSubtypingOptional() {
373 var env = new TypeEnvironment(r""" 375 var env = new TypeEnvironment(r"""
374 typedef void void_(); 376 typedef void void_();
375 typedef void void__int(int i); 377 typedef void void__int(int i);
376 typedef void void___int([int i]); 378 typedef void void___int([int i]);
377 typedef void void___int2([int i]); 379 typedef void void___int2([int i]);
378 typedef void void___Object([Object o]); 380 typedef void void___Object([Object o]);
379 typedef void void__int__int(int i1, [int i2]); 381 typedef void void__int__int(int i1, [int i2]);
380 typedef void void__int__int2(int i1, [int i2]); 382 typedef void void__int__int2(int i1, [int i2]);
383 typedef void void__int__int_int(int i1, [int i2, int i3]);
381 typedef void void___double(double d); 384 typedef void void___double(double d);
382 typedef void void___int_int([int i1, int i2]); 385 typedef void void___int_int([int i1, int i2]);
386 typedef void void___int_int_int([int i1, int i2, int i3]);
karlklose 2013/04/24 11:59:20 Ditto.
Johnni Winther 2013/04/25 07:54:12 Done.
383 typedef void void___Object_int([Object o, int i]); 387 typedef void void___Object_int([Object o, int i]);
384 """); 388 """);
385 functionSubtypingOptionalHelper(env); 389 functionSubtypingOptionalHelper(env);
386 } 390 }
387 391
388 functionSubtypingOptionalHelper(TypeEnvironment env) { 392 functionSubtypingOptionalHelper(TypeEnvironment env) {
389 expect(bool expectedResult, String sub, String sup) { 393 expect(bool expectedResult, String sub, String sup) {
390 DartType subtype = env.getElementType(sub); 394 DartType subtype = env.getElementType(sub);
391 DartType supertype = env.getElementType(sup); 395 DartType supertype = env.getElementType(sup);
392 Expect.equals(expectedResult, env.isSubtype(subtype, supertype), 396 Expect.equals(expectedResult, env.isSubtype(subtype, supertype),
393 '$subtype <: $supertype'); 397 '$subtype <: $supertype');
394 } 398 }
395 399
396 // Test ([int])->void <: ()->void. 400 // Test ([int])->void <: ()->void.
397 expect(true, 'void___int', 'void_'); 401 expect(true, 'void___int', 'void_');
398 // Test ([int])->void <: (int)->void. 402 // Test ([int])->void <: (int)->void.
399 expect(false, 'void___int', 'void__int'); 403 expect(true, 'void___int', 'void__int');
400 // Test (int)->void <: ([int])->void. 404 // Test (int)->void <: ([int])->void.
401 expect(false, 'void__int', 'void___int'); 405 expect(false, 'void__int', 'void___int');
402 // Test ([int])->void <: ([int])->void. 406 // Test ([int])->void <: ([int])->void.
403 expect(true, 'void___int', 'void___int2'); 407 expect(true, 'void___int', 'void___int2');
404 // Test ([Object])->void <: ([int])->void. 408 // Test ([Object])->void <: ([int])->void.
405 expect(true, 'void___Object', 'void___int'); 409 expect(true, 'void___Object', 'void___int');
406 // Test ([int])->void <: ([Object])->void. 410 // Test ([int])->void <: ([Object])->void.
407 expect(true, 'void___int', 'void___Object'); 411 expect(true, 'void___int', 'void___Object');
408 // Test (int,[int])->void <: (int,[int])->void. 412 // Test (int,[int])->void <: (int,[int])->void.
409 expect(true, 'void__int__int', 'void__int__int2'); 413 expect(true, 'void__int__int', 'void__int__int2');
414 // Test (int)->void <: ([int])->void.
415 expect(false, 'void__int', 'void___int');
416 // Test ([int,int])->void <: (int)->void.
417 expect(true, 'void___int_int', 'void__int');
418 // Test ([int,int])->void <: (int,[int])->void.
419 expect(true, 'void___int_int', 'void__int__int');
420 // Test ([int,int])->void <: (int,[int,int])->void.
421 expect(false, 'void___int_int', 'void__int__int_int');
410 // Test ([int])->void <: ([double])->void. 422 // Test ([int])->void <: ([double])->void.
411 expect(false, 'void___int', 'void___double'); 423 expect(false, 'void___int', 'void___double');
412 // Test ([int])->void <: ([int,int])->void. 424 // Test ([int])->void <: ([int,int])->void.
413 expect(false, 'void___int', 'void___int_int'); 425 expect(false, 'void___int', 'void___int_int');
414 // Test ([int,int])->void <: ([int])->void. 426 // Test ([int,int])->void <: ([int])->void.
415 expect(true, 'void___int_int', 'void___int'); 427 expect(true, 'void___int_int', 'void___int');
416 // Test ([Object,int])->void <: ([int])->void. 428 // Test ([Object,int])->void <: ([int])->void.
417 expect(true, 'void___Object_int', 'void___int'); 429 expect(true, 'void___Object_int', 'void___int');
418 } 430 }
419 431
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 expect(true, J_U, Object_); 716 expect(true, J_U, Object_);
705 expect(false, J_U, num_); 717 expect(false, J_U, num_);
706 expect(false, J_U, int_); 718 expect(false, J_U, int_);
707 expect(false, J_U, String_); 719 expect(false, J_U, String_);
708 expect(true, J_U, dynamic_); 720 expect(true, J_U, dynamic_);
709 expect(false, J_U, J_T); 721 expect(false, J_U, J_T);
710 expect(true, J_U, J_S); 722 expect(true, J_U, J_S);
711 expect(true, J_U, J_U); 723 expect(true, J_U, J_U);
712 expect(false, J_U, A_T); 724 expect(false, J_U, A_T);
713 } 725 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698