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

Side by Side Diff: tests/compiler/dart2js/backend_dart/sexpr_test.dart

Issue 669673006: Add SExpression test and share tests between dart2dart and analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import '../compiler_helper.dart'; 5 library dart_backend.sexpr_test;
6 import 'sexpr_unstringifier.dart'; 6
7 import 'dart:async'; 7 import 'dart:async';
8 import "package:async_helper/async_helper.dart"; 8
9 import "package:expect/expect.dart"; 9 import 'package:async_helper/async_helper.dart';
10 import 'package:compiler/implementation/dart2jslib.dart'; 10 import 'package:compiler/implementation/dart2jslib.dart';
11 import 'package:compiler/implementation/cps_ir/cps_ir_nodes.dart'; 11 import 'package:compiler/implementation/cps_ir/cps_ir_nodes.dart';
12 import 'package:compiler/implementation/cps_ir/cps_ir_nodes_sexpr.dart'; 12 import 'package:compiler/implementation/cps_ir/cps_ir_nodes_sexpr.dart';
13 import 'package:expect/expect.dart';
14
15 import '../compiler_helper.dart' hide compilerFor;
16 import 'sexpr_unstringifier.dart';
17 import 'test_helper.dart';
13 18
14 const String CODE = """ 19 const String CODE = """
15 class Foo { 20 class Foo {
16 static int x = 1; 21 static int x = 1;
17 foo() => 42; 22 foo() => 42;
18 } 23 }
19 24
20 class Bar extends Foo { 25 class Bar extends Foo {
21 int y = 2; 26 int y = 2;
22 Bar() { 27 Bar() {
23 Foo.x = 2; 28 Foo.x = 2;
24 } 29 }
25 foo() => this.y + super.foo(); 30 foo() => this.y + super.foo();
26 } 31 }
27 32
28 class FooBar<T> { 33 class FooBar<T> {
29 bool foobar() => T is int; 34 bool foobar() => T is int;
30 } 35 }
31 36
32 main() { 37 main() {
33 Foo foo; 38 Foo foo;
34 if (foo is Foo) { 39 if (foo is Foo) {
35 print("Surprise"); 40 print("Surprise");
36 } 41 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 81
77 bool shouldOutput(Element element) { 82 bool shouldOutput(Element element) {
78 return (!element.library.isPlatformLibrary && 83 return (!element.library.isPlatformLibrary &&
79 !element.isSynthesized && 84 !element.isSynthesized &&
80 element.kind == ElementKind.FUNCTION); 85 element.kind == ElementKind.FUNCTION);
81 } 86 }
82 87
83 /// Compiles the given dart code (which must include a 'main' function) and 88 /// Compiles the given dart code (which must include a 'main' function) and
84 /// returns a list of all generated CPS IR definitions. 89 /// returns a list of all generated CPS IR definitions.
85 Future<List<FunctionDefinition>> compile(String code) { 90 Future<List<FunctionDefinition>> compile(String code) {
86 MockCompiler compiler = new MockCompiler.internal( 91 return compilerFor(code).then((Compiler compiler) {
87 emitJavaScript: false,
88 enableMinification: false);
89
90 return compiler.init().then((_) {
91 compiler.parseScript(code);
92
93 Element element = compiler.mainApp.find('main');
94 if (element == null) return null;
95
96 compiler.mainFunction = element;
97 compiler.phase = Compiler.PHASE_RESOLVING;
98 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution,
99 compiler.globalDependencies);
100 compiler.processQueue(compiler.enqueuer.resolution, element);
101 compiler.world.populate();
102 compiler.backend.onResolutionComplete();
103
104 compiler.irBuilder.buildNodes(useNewBackend: true);
105
106 return compiler.enqueuer.resolution.resolvedElements 92 return compiler.enqueuer.resolution.resolvedElements
107 .where(shouldOutput) 93 .where(shouldOutput)
108 .map(compiler.irBuilder.getIr) 94 .map(compiler.irBuilder.getIr)
109 .toList(); 95 .toList();
110 }); 96 });
111 } 97 }
112 98
113 /// Returns an S-expression string for each compiled function. 99 /// Returns an S-expression string for each compiled function.
114 List<String> stringifyAll(Iterable<FunctionDefinition> functions) { 100 List<String> stringifyAll(Iterable<FunctionDefinition> functions) {
115 final stringifier = new SExpressionStringifier(); 101 final stringifier = new SExpressionStringifier();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 ]; 165 ];
180 166
181 asyncTest(() => testStringifier(CODE, tokens).then((List<String> sexprs) { 167 asyncTest(() => testStringifier(CODE, tokens).then((List<String> sexprs) {
182 final functions = testUnstringifier(sexprs); 168 final functions = testUnstringifier(sexprs);
183 169
184 // Ensure that 170 // Ensure that
185 // stringified(CODE) == stringified(unstringified(stringified(CODE))) 171 // stringified(CODE) == stringified(unstringified(stringified(CODE)))
186 Expect.listEquals(sexprs, stringifyAll(functions)); 172 Expect.listEquals(sexprs, stringifyAll(functions));
187 })); 173 }));
188 } 174 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/backend_dart/sexpr2_test.dart ('k') | tests/compiler/dart2js/backend_dart/test_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698