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

Side by Side Diff: tests/compiler/dart2js/js_backend_cps_ir_test.dart

Issue 743973002: Add list literals in js cps codegen. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | 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 // VMOptions=-DUSE_CPS_IR=true 4 // VMOptions=-DUSE_CPS_IR=true
5 5
6 // Test that the CPS IR code generator is able to compile the provided 6 // Test that the CPS IR code generator compiles programs as expected
karlklose 2014/11/20 12:31:18 'expected' -> 'and produces the expected output'?
sigurdm 2014/11/20 13:32:45 Done.
7 // example programs.
8 7
9 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
10 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
11 import 'package:compiler/src/apiimpl.dart' 10 import 'package:compiler/src/apiimpl.dart'
12 show Compiler; 11 show Compiler;
13 import 'memory_compiler.dart'; 12 import 'memory_compiler.dart';
14 import 'package:compiler/src/js/js.dart' as js; 13 import 'package:compiler/src/js/js.dart' as js;
15 import 'package:compiler/src/common.dart' show Element; 14 import 'package:compiler/src/common.dart' show Element;
16 15
16 import 'js_backend_cps_ir_basic.dart' as basic;
17 import 'js_backend_cps_ir_literals.dart' as literals;
17 18
18 const String TEST_MAIN_FILE = 'test.dart'; 19 const String TEST_MAIN_FILE = 'test.dart';
19 20
20 class TestEntry { 21 class TestEntry {
21 final String source; 22 final String source;
22 final String expectation; 23 final String expectation;
23 const TestEntry(this.source, [this.expectation]); 24 const TestEntry(this.source, [this.expectation]);
24 } 25 }
25 26
26 /// The list of tests to run.
27 const List<TestEntry> tests = const [
28 const TestEntry(
29 """
30 foo(a) {
31 return a;
32 }
33 main() {
34 var a = 10;
35 var b = 1;
36 var t;
37 t = a;
38 a = b;
39 b = t;
40 print(a);
41 print(b);
42 print(b);
43 print(foo(a));
44 }
45 """,
46 """
47 function() {
48 var a, b;
49 a = 10;
50 b = 1;
51 P.print(b);
52 P.print(a);
53 P.print(a);
54 P.print(V.foo(b));
55 return null;
56 }"""),
57 const TestEntry(
58 """
59 foo() { return 42; }
60 main() { return foo(); }
61 """,
62 """function() {
63 return V.foo();
64 }"""),
65 const TestEntry("main() {}"),
66 const TestEntry("main() { return 42; }"),
67 const TestEntry("main() { return; }", """
68 function() {
69 return null;
70 }"""),
71 ];
72
73 String formatTest(Map test) { 27 String formatTest(Map test) {
74 return test[TEST_MAIN_FILE]; 28 return test[TEST_MAIN_FILE];
75 } 29 }
76 30
77 String getCodeForMain(Compiler compiler) { 31 String getCodeForMain(Compiler compiler) {
78 Element mainFunction = compiler.mainFunction; 32 Element mainFunction = compiler.mainFunction;
79 js.Node ast = compiler.enqueuer.codegen.generatedCode[mainFunction]; 33 js.Node ast = compiler.enqueuer.codegen.generatedCode[mainFunction];
80 return js.prettyPrint(ast, compiler).getText(); 34 return js.prettyPrint(ast, compiler).getText();
81 } 35 }
82 36
83 main() { 37 main() {
84 Expect.isTrue(const bool.fromEnvironment("USE_CPS_IR")); 38 Expect.isTrue(const bool.fromEnvironment("USE_CPS_IR"));
85 39
86 for (TestEntry test in tests) { 40 for (List<TestEntry> tests in [basic.tests, literals.tests]) {
karlklose 2014/11/20 12:31:18 Could you instead leaves tests where it is as L
sigurdm 2014/11/20 13:32:45 Done.
87 Map files = {TEST_MAIN_FILE: test.source}; 41 for (TestEntry test in tests) {
88 asyncTest(() { 42 Map files = {TEST_MAIN_FILE: test.source};
89 Compiler compiler = compilerFor(files); 43 asyncTest(() {
90 Uri uri = Uri.parse('memory:$TEST_MAIN_FILE'); 44 Compiler compiler = compilerFor(files);
91 return compiler.run(uri).then((_) { 45 Uri uri = Uri.parse('memory:$TEST_MAIN_FILE');
92 Expect.isNotNull(compiler.assembledCode); 46 return compiler.run(uri).then((_) {
93 String expectation = test.expectation; 47 Expect.isNotNull(compiler.assembledCode);
94 if (expectation != null) { 48 String expectation = test.expectation;
95 Expect.equals(test.expectation, getCodeForMain(compiler)); 49 if (expectation != null) {
96 } 50 Expect.equals(test.expectation, getCodeForMain(compiler));
97 }).catchError((e) { 51 }
98 print(e); 52 }).catchError((e) {
99 Expect.fail('The following test failed to compile:\n' 53 print(e);
100 '${formatTest(files)}'); 54 Expect.fail('The following test failed to compile:\n'
55 '${formatTest(files)}');
56 });
101 }); 57 });
102 }); 58 }
103 } 59 }
104 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698