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

Side by Side Diff: test/codegen/lib/mirrors/instantiate_abstract_class_test.dart

Issue 2265533002: Add mirrors tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.instantiate_abstract_class;
6
7 import 'dart:mirrors';
8 import 'package:expect/expect.dart';
9
10
11 assertInstanitationErrorOnGenerativeConstructors(classMirror) {
12 classMirror.declarations.values.forEach((decl) {
13 if (decl is! MethodMirror) return;
14 if (!decl.isGenerativeConstructor) return;
15 var args = new List(decl.parameters.length);
16 Expect.throws(() => classMirror.newInstance(decl.constructorName, args),
17 (e) => e is AbstractClassInstantiationError,
18 '${decl.qualifiedName} should have failed');
19 });
20 }
21
22 runFactoryConstructors(classMirror) {
23 classMirror.declarations.values.forEach((decl) {
24 if (decl is! MethodMirror) return;
25 if (!decl.isFactoryConstructor) return;
26 var args = new List(decl.parameters.length);
27 classMirror.newInstance(decl.constructorName, args); // Should not throw.
28 });
29 }
30
31 abstract class AbstractClass {
32 AbstractClass();
33 AbstractClass.named();
34 factory AbstractClass.named2() => new ConcreteClass();
35 }
36
37 class ConcreteClass implements AbstractClass {}
38
39 main() {
40 assertInstanitationErrorOnGenerativeConstructors(reflectType(num));
41 assertInstanitationErrorOnGenerativeConstructors(reflectType(double));
42 assertInstanitationErrorOnGenerativeConstructors(reflectType(StackTrace));
43
44 assertInstanitationErrorOnGenerativeConstructors(reflectType(AbstractClass));
45 runFactoryConstructors(reflectType(AbstractClass));
46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698