| Index: tests/compiler/dart2js/mirror_helper2_test.dart
|
| diff --git a/tests/compiler/dart2js/mirror_helper2_test.dart b/tests/compiler/dart2js/mirror_helper2_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..57397f613dfb8524afee26aa42ce3ac02c806498
|
| --- /dev/null
|
| +++ b/tests/compiler/dart2js/mirror_helper2_test.dart
|
| @@ -0,0 +1,94 @@
|
| +// 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.
|
| +
|
| +import "package:expect/expect.dart";
|
| +import 'memory_compiler.dart' show compilerFor;
|
| +import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
|
| + Compiler;
|
| +import
|
| + '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart'
|
| +show
|
| + Elements;
|
| +import
|
| + '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'
|
| +show
|
| + Node;
|
| +import
|
| + '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backend.dart';
|
| +import
|
| + '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_renamer.dart';
|
| +
|
| +main() {
|
| + testWithMirrorHeplerLibrary(minify: true);
|
| + testWithMirrorHeplerLibrary(minify: false);
|
| + testWithoutMirrorHelperLibrary(minify: true);
|
| + testWithoutMirrorHelperLibrary(minify: false);
|
| +}
|
| +
|
| +Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
| + List<String> options = ['--output-type=dart'];
|
| + if (minify) {
|
| + options.add('--minify');
|
| + }
|
| + Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options);
|
| + DartBackend backend = compiler.backend;
|
| + backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
|
| + MirrorRenamer.inverseRenames = null;
|
| + compiler.runCompiler(Uri.parse('memory:main.dart'));
|
| + return compiler;
|
| +}
|
| +
|
| +void testWithMirrorHeplerLibrary({bool minify}) {
|
| + Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify);
|
| +
|
| + DartBackend backend = compiler.backend;
|
| + Map<Node, String> renames = backend.renames;
|
| + Map<String, String> inverseRenames = MirrorRenamer.inverseRenames;
|
| +
|
| + Expect.isFalse(inverseRenames.isEmpty);
|
| +
|
| + for (Node n in renames.keys) {
|
| + if (inverseRenames.containsKey(renames[n])) {
|
| + Expect.equals(inverseRenames[renames[n]], n.toString());
|
| + }
|
| + }
|
| +
|
| + String output = compiler.assembledCode;
|
| + String match =
|
| + "${MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME}."
|
| + "${MirrorRenamer.MIRROR_HELPER_ADD_RENAME_FUNCTION}";
|
| + Iterable i = match.allMatches(output);
|
| +
|
| + Expect.isTrue(output.indexOf('main(){$match') != -1);
|
| + Expect.equals(inverseRenames.length, i.length);
|
| +}
|
| +
|
| +void testWithoutMirrorHelperLibrary({bool minify}) {
|
| + Compiler compiler =
|
| + runCompiler(useMirrorHelperLibrary: false, minify: minify);
|
| +
|
| + Expect.equals(null, MirrorRenamer.inverseRenames);
|
| +
|
| + String output = compiler.assembledCode;
|
| + String match =
|
| + "${MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME}."
|
| + "${MirrorRenamer.MIRROR_HELPER_ADD_RENAME_FUNCTION}";
|
| + Expect.equals(-1, output.indexOf(match));
|
| +}
|
| +
|
| +const MEMORY_SOURCE_FILES = const <String, String> {
|
| + 'main.dart': """
|
| +import 'dart:mirrors';
|
| +
|
| +
|
| +class Foo {
|
| + noSuchMethod(Invocation invocation) {
|
| + MirrorSystem.getName(invocation.memberName);
|
| + }
|
| +}
|
| +
|
| +void main() {
|
| + new Foo().fisk();
|
| +}
|
| +"""};
|
|
|