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

Unified Diff: test/codegen/lib/mirrors/typedef_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 side-by-side diff with in-line comments
Download patch
Index: test/codegen/lib/mirrors/typedef_test.dart
diff --git a/test/codegen/lib/mirrors/typedef_test.dart b/test/codegen/lib/mirrors/typedef_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..19c7a70f77136eba10219a5d968b2910c9ff75d6
--- /dev/null
+++ b/test/codegen/lib/mirrors/typedef_test.dart
@@ -0,0 +1,151 @@
+// 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.
+
+// This test is a multi-test with three positive tests. "01" pass on dart2js,
+// "02" pass on the VM, and "none" is the correct behavior.
+// The goal is to remove all "01" and "02" lines.
+
+library test.typedef_test;
+
+@MirrorsUsed(targets: 'test.typedef_test')
+import 'dart:mirrors';
+
+import 'package:expect/expect.dart';
+
+typedef Func();
+typedef void Void();
+typedef String Foo(int x);
+typedef String Bar(int x, [num y]);
+typedef String Baz(int x, {num y});
+typedef String Foo2(int x, num y);
+typedef String Bar2(int x, [num y, num z]);
+typedef String Baz2(int x, {num y, num z});
+
+check(t) {
+ var sb = new StringBuffer();
+ writeln(o) {
+ sb.write(o);
+ sb.write('\n');
+ }
+ writeln(t);
+ t = t.referent;
+ writeln(t);
+ writeln(t.returnType);
+ writeln(t.parameters);
+ for (var p in t.parameters) {
+ writeln(p.simpleName);
+ writeln(p.type);
+ }
+
+ return sb.toString();
+}
+
+// Return "$args -> $ret".
+ft(args, ret) {
+ return '$args -> $ret';
+}
+
+void main() {
+ String x = 'x';
+ String y = 'y';
+ String z = 'z';
+
+ Expect.stringEquals(
+ """
+TypedefMirror on 'Func'
+FunctionTypeMirror on '${ft('()', 'dynamic')}'
+TypeMirror on 'dynamic'
+[]
+""",
+ check(reflectType(Func)));
+ Expect.stringEquals(
+ """
+TypedefMirror on 'Void'
+FunctionTypeMirror on '${ft('()', 'void')}'
+TypeMirror on 'void'
+[]
+""",
+ check(reflectType(Void)));
+ Expect.stringEquals(
+ """
+TypedefMirror on 'Foo'
+FunctionTypeMirror on '${ft('(dart.core.int)', 'dart.core.String')}'
+ClassMirror on 'String'
+[ParameterMirror on '$x']
+Symbol(\"$x\")
+ClassMirror on 'int'
+""",
+ check(reflectType(Foo)));
+ String type = ft('(dart.core.int, dart.core.num)', 'dart.core.String');
+ Expect.stringEquals(
+ """
+TypedefMirror on 'Foo2'
+FunctionTypeMirror on '$type'
+ClassMirror on 'String'
+[ParameterMirror on '$x', ParameterMirror on '$y']
+Symbol(\"$x\")
+ClassMirror on 'int'
+Symbol(\"$y\")
+ClassMirror on 'num'
+""",
+ check(reflectType(Foo2)));
+ type = ft('(dart.core.int, [dart.core.num])', 'dart.core.String');
+ Expect.stringEquals(
+ """
+TypedefMirror on 'Bar'
+FunctionTypeMirror on '$type'
+ClassMirror on 'String'
+[ParameterMirror on '$x', ParameterMirror on '$y']
+Symbol(\"$x\")
+ClassMirror on 'int'
+Symbol(\"$y\")
+ClassMirror on 'num'
+""",
+ check(reflectType(Bar)));
+ type = ft('(dart.core.int, [dart.core.num, dart.core.num])',
+ 'dart.core.String');
+ Expect.stringEquals(
+ """
+TypedefMirror on 'Bar2'
+FunctionTypeMirror on '$type'
+ClassMirror on 'String'
+[ParameterMirror on '$x', ParameterMirror on '$y', ParameterMirror on '$z']
+Symbol(\"$x\")
+ClassMirror on 'int'
+Symbol(\"$y\")
+ClassMirror on 'num'
+Symbol(\"$z\")
+ClassMirror on 'num'
+""",
+ check(reflectType(Bar2)));
+ type = ft('(dart.core.int, {y: dart.core.num})', 'dart.core.String');
+ Expect.stringEquals(
+ """
+TypedefMirror on 'Baz'
+FunctionTypeMirror on '$type'
+ClassMirror on 'String'
+[ParameterMirror on '$x', ParameterMirror on 'y']
+Symbol(\"$x\")
+ClassMirror on 'int'
+Symbol(\"y\")
+ClassMirror on 'num'
+""",
+ check(reflectType(Baz)));
+ type = ft('(dart.core.int, {y: dart.core.num, z: dart.core.num})',
+ 'dart.core.String');
+ Expect.stringEquals(
+ """
+TypedefMirror on 'Baz2'
+FunctionTypeMirror on '$type'
+ClassMirror on 'String'
+[ParameterMirror on '$x', ParameterMirror on 'y', ParameterMirror on 'z']
+Symbol(\"$x\")
+ClassMirror on 'int'
+Symbol(\"y\")
+ClassMirror on 'num'
+Symbol(\"z\")
+ClassMirror on 'num'
+""",
+ check(reflectType(Baz2)));
+}

Powered by Google App Engine
This is Rietveld 408576698