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

Unified Diff: tests/compiler/dart2js/kernel/class_hierarchy_test.dart

Issue 2468273003: Fix kernel/visitor_test (Closed)
Patch Set: Fix impact_test after changes. Created 4 years, 1 month 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
« no previous file with comments | « tests/compiler/dart2js/dart2js.status ('k') | tests/compiler/dart2js/kernel/impact_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/kernel/class_hierarchy_test.dart
diff --git a/tests/compiler/dart2js/kernel/class_hierarchy_test.dart b/tests/compiler/dart2js/kernel/class_hierarchy_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9b6aa08451375e0931ab3a33992c930097fe1ea9
--- /dev/null
+++ b/tests/compiler/dart2js/kernel/class_hierarchy_test.dart
@@ -0,0 +1,76 @@
+// Copyright (c) 2016, 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.
+
+/// Test that the dart2js copy of [KernelVisitor] generates the expected class
+/// hierarchy.
+
+import 'package:compiler/src/compiler.dart' show Compiler;
+import 'package:compiler/src/elements/elements.dart';
+import 'package:compiler/src/js_backend/backend.dart' show JavaScriptBackend;
+import 'package:compiler/src/commandline_options.dart' show Flags;
+import 'package:kernel/ast.dart' as ir;
+import 'package:kernel/class_hierarchy.dart';
+import 'package:test/test.dart';
+
+import '../memory_compiler.dart';
+
+main(List<String> arguments) {
+ Compiler compiler = compilerFor(memorySourceFiles: {
+ 'main.dart': '''
+ class S {
+ sMethod() {}
+ }
+ class M {
+ mMethod() {}
+ }
+ class C extends S with M {
+ cMethod() {}
+ }
+ main() {}
+ '''
+ }, options: [
+ Flags.analyzeOnly,
+ Flags.analyzeMain,
+ Flags.useKernel
+ ]);
+ test('mixin', () async {
+ Uri mainUri = Uri.parse('memory:main.dart');
+ LibraryElement library = await compiler.analyzeUri(mainUri);
+ JavaScriptBackend backend = compiler.backend;
+ ir.Program program = backend.kernelTask.buildProgram(library);
+ ClassHierarchy hierarchy = new ClassHierarchy(program);
+
+ ir.Class getClass(String name) {
+ for (ir.Class cls in hierarchy.classes) {
+ if (cls.enclosingLibrary.importUri == mainUri && cls.name == name) {
+ if (arguments.contains('-v')) {
+ print('$cls');
+ print(' dispatch targets:');
+ hierarchy
+ .getDispatchTargets(cls)
+ .forEach((member) => print(' $member'));
+ }
+ return cls;
+ }
+ }
+ fail('Class $name not found.');
+ }
+
+ ir.Class classS = getClass('S');
+ ir.Class classM = getClass('M');
+ ir.Class classC = getClass('C');
+
+ void checkInheritance(ir.Class superClass, ir.Class subClass) {
+ for (ir.Member member in hierarchy.getDispatchTargets(superClass)) {
+ expect(
+ hierarchy.getDispatchTarget(subClass, member.name), equals(member),
+ reason: 'Unexpected dispatch target for ${member.name} '
+ 'in $subClass');
+ }
+ }
+
+ checkInheritance(classS, classC);
+ checkInheritance(classM, classC);
+ });
+}
« no previous file with comments | « tests/compiler/dart2js/dart2js.status ('k') | tests/compiler/dart2js/kernel/impact_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698