Index: tests/compiler/dart2js/closure/closure_test.dart |
diff --git a/tests/compiler/dart2js/closure/closure_test.dart b/tests/compiler/dart2js/closure/closure_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..acf11a06e5571017ae5d6122b43410ba858959f8 |
--- /dev/null |
+++ b/tests/compiler/dart2js/closure/closure_test.dart |
@@ -0,0 +1,60 @@ |
+// Copyright (c) 2017, 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 'dart:io'; |
+import 'package:async_helper/async_helper.dart'; |
+import 'package:compiler/src/closure.dart'; |
+import 'package:compiler/src/compiler.dart'; |
+import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
+import 'package:compiler/src/elements/elements.dart'; |
+import 'package:compiler/src/tree/nodes.dart'; |
+import '../equivalence/id_equivalence.dart'; |
+import '../equivalence/id_equivalence_helper.dart'; |
+ |
+main() { |
+ asyncTest(() async { |
+ Directory dataDir = new Directory.fromUri(Platform.script.resolve('data')); |
+ await for (FileSystemEntity entity in dataDir.list()) { |
+ print('Checking ${entity.uri}'); |
+ String annotatedCode = await new File.fromUri(entity.uri).readAsString(); |
+ await checkCode(annotatedCode, checkClosureData); |
+ } |
+ }); |
+} |
+ |
+void checkClosureData( |
+ Compiler compiler, Map<Id, String> expectedMap, MemberElement member) { |
+ new ClosureChecker(compiler.reporter, expectedMap, member.resolvedAst, |
+ compiler.closureDataLookup as ClosureDataLookup<Node>) |
+ .check(); |
+} |
+ |
+class ClosureChecker extends AbstractResolvedAstChecker { |
+ final ClosureDataLookup<Node> closureDataLookup; |
+ final ClosureRepresentationInfo info; |
+ |
+ ClosureChecker(DiagnosticReporter reporter, Map<Id, String> expectedMap, |
+ ResolvedAst resolvedAst, this.closureDataLookup) |
+ : this.info = |
+ closureDataLookup.getClosureRepresentationInfo(resolvedAst.element), |
+ super(reporter, expectedMap, resolvedAst); |
+ |
+ @override |
+ String computeNodeValue(Node node, [AstElement element]) { |
+ if (element != null && element.isLocal) { |
+ LocalElement local = element; |
+ StringBuffer sb = new StringBuffer(); |
+ if (info.variableIsUsedInTryOrSync(local)) { |
+ sb.write('inTry'); |
+ } |
+ return sb.toString(); |
+ } |
+ return null; |
+ } |
+ |
+ @override |
+ String computeElementValue(AstElement element) { |
+ return null; |
+ } |
+} |