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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 /// Test that the dart2js copy of [KernelVisitor] generates the expected class
6 /// hierarchy.
7
8 import 'package:compiler/src/compiler.dart' show Compiler;
9 import 'package:compiler/src/elements/elements.dart';
10 import 'package:compiler/src/js_backend/backend.dart' show JavaScriptBackend;
11 import 'package:compiler/src/commandline_options.dart' show Flags;
12 import 'package:kernel/ast.dart' as ir;
13 import 'package:kernel/class_hierarchy.dart';
14 import 'package:test/test.dart';
15
16 import '../memory_compiler.dart';
17
18 main(List<String> arguments) {
19 Compiler compiler = compilerFor(memorySourceFiles: {
20 'main.dart': '''
21 class S {
22 sMethod() {}
23 }
24 class M {
25 mMethod() {}
26 }
27 class C extends S with M {
28 cMethod() {}
29 }
30 main() {}
31 '''
32 }, options: [
33 Flags.analyzeOnly,
34 Flags.analyzeMain,
35 Flags.useKernel
36 ]);
37 test('mixin', () async {
38 Uri mainUri = Uri.parse('memory:main.dart');
39 LibraryElement library = await compiler.analyzeUri(mainUri);
40 JavaScriptBackend backend = compiler.backend;
41 ir.Program program = backend.kernelTask.buildProgram(library);
42 ClassHierarchy hierarchy = new ClassHierarchy(program);
43
44 ir.Class getClass(String name) {
45 for (ir.Class cls in hierarchy.classes) {
46 if (cls.enclosingLibrary.importUri == mainUri && cls.name == name) {
47 if (arguments.contains('-v')) {
48 print('$cls');
49 print(' dispatch targets:');
50 hierarchy
51 .getDispatchTargets(cls)
52 .forEach((member) => print(' $member'));
53 }
54 return cls;
55 }
56 }
57 fail('Class $name not found.');
58 }
59
60 ir.Class classS = getClass('S');
61 ir.Class classM = getClass('M');
62 ir.Class classC = getClass('C');
63
64 void checkInheritance(ir.Class superClass, ir.Class subClass) {
65 for (ir.Member member in hierarchy.getDispatchTargets(superClass)) {
66 expect(
67 hierarchy.getDispatchTarget(subClass, member.name), equals(member),
68 reason: 'Unexpected dispatch target for ${member.name} '
69 'in $subClass');
70 }
71 }
72
73 checkInheritance(classS, classC);
74 checkInheritance(classM, classC);
75 });
76 }
OLDNEW
« 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