mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
[dartdevc] add unit test for subtyping op
Change-Id: I704e7b566fe76fa320c68eadd89611517c3641af Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107446 Reviewed-by: Nicholas Shahan <nshahan@google.com> Auto-Submit: Vijay Menon <vsm@google.com> Commit-Queue: Vijay Menon <vsm@google.com>
This commit is contained in:
parent
8b1efb2b76
commit
74643f65c2
1 changed files with 46 additions and 0 deletions
46
tests/compiler/dartdevc_native/subtype_test.dart
Normal file
46
tests/compiler/dartdevc_native/subtype_test.dart
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:_foreign_helper' show JS;
|
||||
import 'dart:_runtime' as dart;
|
||||
|
||||
class A {}
|
||||
|
||||
class B extends A {}
|
||||
|
||||
class C extends B {}
|
||||
|
||||
class D<T extends B> {}
|
||||
|
||||
// Returns sWrapped<tWrapped> as a wrapped type.
|
||||
Object generic1(Type sWrapped, Type tWrapped) {
|
||||
var s = dart.unwrapType(sWrapped);
|
||||
var t = dart.unwrapType(tWrapped);
|
||||
var sGeneric = dart.getGenericClass(s);
|
||||
return dart.wrapType(JS('', '#(#)', sGeneric, t));
|
||||
}
|
||||
|
||||
void checkSubtype(Type sWrapped, Type tWrapped) {
|
||||
var s = dart.unwrapType(sWrapped);
|
||||
var t = dart.unwrapType(tWrapped);
|
||||
Expect.isTrue(dart.isSubtypeOf(s, t));
|
||||
}
|
||||
|
||||
void checkProperSubtype(Type sWrapped, Type tWrapped) {
|
||||
var s = dart.unwrapType(sWrapped);
|
||||
var t = dart.unwrapType(tWrapped);
|
||||
Expect.isTrue(dart.isSubtypeOf(s, t));
|
||||
Expect.isFalse(dart.isSubtypeOf(t, s));
|
||||
}
|
||||
|
||||
void main() {
|
||||
checkProperSubtype(B, A);
|
||||
checkProperSubtype(C, B);
|
||||
checkProperSubtype(C, A);
|
||||
|
||||
checkSubtype(D, generic1(D, B));
|
||||
checkSubtype(generic1(D, B), D);
|
||||
checkProperSubtype(generic1(D, C), generic1(D, B));
|
||||
}
|
Loading…
Reference in a new issue