Skip to content

Commit

Permalink
[test] Fork mirrors tests.
Browse files Browse the repository at this point in the history
Bug: #40045
Change-Id: I597259b38684de87016f1e136723d24f4ac05420
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132440
Reviewed-by: Ben Konyi <[email protected]>
Commit-Queue: Ryan Macnak <[email protected]>
  • Loading branch information
rmacnak-google authored and [email protected] committed Jan 22, 2020
1 parent 0b06a36 commit 00b2e58
Show file tree
Hide file tree
Showing 299 changed files with 16,690 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ tests/lib_2/mirrors/method_mirror_source_line_ending_lf.dart -text
tests/lib_2/mirrors/method_mirror_source_line_ending_test.dart -text
tests/lib_2/mirrors/method_mirror_source_other.dart -text
tests/lib_2/mirrors/method_mirror_source_test.dart -text
tests/lib/mirrors/method_mirror_source_line_ending_cr.dart -text
tests/lib/mirrors/method_mirror_source_line_ending_crlf.dart -text
tests/lib/mirrors/method_mirror_source_line_ending_lf.dart -text
tests/lib/mirrors/method_mirror_source_line_ending_test.dart -text
tests/lib/mirrors/method_mirror_source_other.dart -text
tests/lib/mirrors/method_mirror_source_test.dart -text

# Files to leave alone and not diff.
*.png binary
Expand Down
174 changes: 174 additions & 0 deletions tests/lib/mirrors/abstract_class_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// Copyright (c) 2014, 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.

library test.abstract_class_test;

import 'dart:mirrors';
import 'package:expect/expect.dart';

void main() {
testSimple();
testFunctionType();
testFakeFunction();
testGeneric();
testAnonMixinApplication();
testNamedMixinApplication();
}

abstract class Foo {
foo();
}

class Bar extends Foo {
foo() {}
}

testSimple() {
Expect.isTrue(reflectClass(Foo).isAbstract);
Expect.isFalse(reflectClass(Bar).isAbstract);
Expect.isTrue(reflect(new Bar()).type.superclass.isAbstract);
Expect.isFalse(reflect(new Bar()).type.isAbstract);
}

void baz() {}

testFunctionType() {
Expect.isFalse(reflect(baz).type.isAbstract);
}

abstract class FunctionFoo implements Function {
call();
}

class FunctionBar extends FunctionFoo {
call() {}
}

testFakeFunction() {
Expect.isTrue(reflectClass(FunctionFoo).isAbstract);
Expect.isFalse(reflectClass(FunctionBar).isAbstract);
Expect.isTrue(reflect(new FunctionBar()).type.superclass.isAbstract);
Expect.isFalse(reflect(new FunctionBar()).type.isAbstract);
}

abstract class GenericFoo<T> {
T genericFoo();
}

class GenericBar<T> extends GenericFoo<T> {
T genericFoo() {}
}

testGeneric() {
// Unbound.
Expect.isTrue(reflectClass(GenericFoo).isAbstract);
Expect.isFalse(reflectClass(GenericBar).isAbstract);
// Bound.
Expect.isTrue(reflect(new GenericBar<int>()).type.superclass.isAbstract);
Expect.isFalse(reflect(new GenericBar<int>()).type.isAbstract);
}

class S {}

abstract class M {
mixinFoo();
}

abstract class MA extends S with M {}

class SubMA extends MA {
mixinFoo() {}
}

class ConcreteMA extends S with M {
mixinFoo() {}
}

class M2 {
mixin2Foo() {}
}

abstract class MA2 extends S with M2 {
mixinBar();
}

class SubMA2 extends MA2 {
mixinBar() {}
}

class ConcreteMA2 extends S with M2 {
mixin2Foo() {}
}

testAnonMixinApplication() {
// Application is abstract.
{
// Mixin is abstract.
Expect.isFalse(reflectClass(SubMA).isAbstract);
Expect.isTrue(reflectClass(SubMA).superclass.isAbstract);
Expect.isTrue(reflectClass(SubMA).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(MA).isAbstract);
Expect.isTrue(reflectClass(MA).superclass.isAbstract);

// Mixin is concrete.
Expect.isFalse(reflectClass(SubMA2).isAbstract);
Expect.isTrue(reflectClass(SubMA2).superclass.isAbstract);
Expect.isTrue(reflectClass(SubMA2).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(MA2).isAbstract);
Expect.isTrue(reflectClass(MA2).superclass.isAbstract);
}

// Application is concrete.
{
// Mixin is abstract.
Expect.isFalse(reflectClass(ConcreteMA).isAbstract);
Expect.isTrue(reflectClass(ConcreteMA).superclass.isAbstract);
Expect.isFalse(reflectClass(ConcreteMA).superclass.superclass.isAbstract);

// Mixin is concrete.
Expect.isFalse(reflectClass(ConcreteMA2).isAbstract);
Expect.isTrue(reflectClass(ConcreteMA2).superclass.isAbstract);
Expect.isFalse(reflectClass(ConcreteMA2).superclass.superclass.isAbstract);
}
}

abstract class NamedMA = S with M;

class SubNamedMA extends NamedMA {
mixinFoo() {}
}

abstract class NamedMA2 = S with M2;

class SubNamedMA2 extends NamedMA2 {
mixinFoo() {}
}

class ConcreteNamedMA2 = S with M2;

testNamedMixinApplication() {
// Application is abstract.
{
// Mixin is abstract.
Expect.isFalse(reflectClass(SubNamedMA).isAbstract);
Expect.isTrue(reflectClass(SubNamedMA).superclass.isAbstract);
Expect.isFalse(reflectClass(SubNamedMA).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(NamedMA).isAbstract);
Expect.isFalse(reflectClass(NamedMA).superclass.isAbstract);

// Mixin is concrete.
Expect.isFalse(reflectClass(SubNamedMA2).isAbstract);
Expect.isTrue(reflectClass(SubNamedMA2).superclass.isAbstract);
Expect.isFalse(reflectClass(SubNamedMA2).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(NamedMA2).isAbstract);
Expect.isFalse(reflectClass(NamedMA2).superclass.isAbstract);
}

// Application is concrete.
{
// Mixin is concrete.
Expect.isFalse(reflectClass(ConcreteNamedMA2).isAbstract);
Expect.isFalse(reflectClass(ConcreteNamedMA2).superclass.isAbstract);
}
}
18 changes: 18 additions & 0 deletions tests/lib/mirrors/abstract_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2013, 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.

// Test abstract classes are retained.

library test.abstract_test;

import 'dart:mirrors';

import 'stringify.dart';

abstract class Foo {}

void main() {
expect(
'Class(s(Foo) in s(test.abstract_test), top-level)', reflectClass(Foo));
}
Loading

0 comments on commit 00b2e58

Please sign in to comment.