dart-sdk/tests/lib_2/mirrors/instantiate_abstract_class_test.dart
Josh Soref df97aca1fa Spelling tests
Closes https://github.com/dart-lang/sdk/pull/50764

GitOrigin-RevId: ee2fe9a75d50e877f4ad2fe3743acdbc04f186ef
Change-Id: Ia73cd22da4e6ec95e84772aa4e1345ce2dbde215
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276360
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2022-12-19 12:56:47 +00:00

48 lines
1.6 KiB
Dart

// 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.
// @dart = 2.9
library test.instantiate_abstract_class;
import 'dart:mirrors';
import 'package:expect/expect.dart';
assertInstantiationErrorOnGenerativeConstructors(classMirror) {
classMirror.declarations.values.forEach((decl) {
if (decl is! MethodMirror) return;
if (!decl.isGenerativeConstructor) return;
var args = new List.filled(decl.parameters.length, null);
Expect.throws(
() => classMirror.newInstance(decl.constructorName, args),
(e) => e is AbstractClassInstantiationError,
'${decl.qualifiedName} should have failed');
});
}
runFactoryConstructors(classMirror) {
classMirror.declarations.values.forEach((decl) {
if (decl is! MethodMirror) return;
if (!decl.isFactoryConstructor) return;
var args = new List.filled(decl.parameters.length, null);
classMirror.newInstance(decl.constructorName, args); // Should not throw.
});
}
abstract class AbstractClass {
AbstractClass();
AbstractClass.named();
factory AbstractClass.named2() => new ConcreteClass();
}
class ConcreteClass implements AbstractClass {}
main() {
assertInstantiationErrorOnGenerativeConstructors(reflectType(num));
assertInstantiationErrorOnGenerativeConstructors(reflectType(double));
assertInstantiationErrorOnGenerativeConstructors(reflectType(StackTrace));
assertInstantiationErrorOnGenerativeConstructors(reflectType(AbstractClass));
runFactoryConstructors(reflectType(AbstractClass));
}