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

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

Issue 858573002: Implement await and async for the js-ast. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 'dart:async'; 5 import 'dart:async';
6 import 'package:expect/expect.dart'; 6 import 'package:expect/expect.dart';
7 import 'package:async_helper/async_helper.dart'; 7 import 'package:async_helper/async_helper.dart';
8 import 'mock_compiler.dart'; 8 import 'mock_compiler.dart';
9 import 'package:compiler/src/js/js.dart' as jsAst; 9 import 'package:compiler/src/js/js.dart' as jsAst;
10 import 'package:compiler/src/js/js.dart' show js; 10 import 'package:compiler/src/js/js.dart' show js;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 function foo() { 69 function foo() {
70 /a/; 70 /a/;
71 1; 71 1;
72 2; 72 2;
73 }'''; 73 }''';
74 74
75 75
76 void main() { 76 void main() {
77 77
78 var eOne = js('1'); 78 var eOne = js('1');
79 var eTwo = js('2');
79 var eTrue = js('true'); 80 var eTrue = js('true');
80 var eVar = js('x'); 81 var eVar = js('x');
81 var block12 = js.statement('{ 1; 2; }'); 82 var block12 = js.statement('{ 1; 2; }');
83 var stm = js.statement('foo();');
82 var seq1 = js('1, 2, 3'); 84 var seq1 = js('1, 2, 3');
83 85
84 Expect.isTrue(eOne is jsAst.LiteralNumber); 86 Expect.isTrue(eOne is jsAst.LiteralNumber);
85 Expect.isTrue(eTrue is jsAst.LiteralBool); 87 Expect.isTrue(eTrue is jsAst.LiteralBool);
86 Expect.isTrue(block12 is jsAst.Block); 88 Expect.isTrue(block12 is jsAst.Block);
87 89
88 asyncTest(() => Future.wait([ 90 asyncTest(() => Future.wait([
89 // Interpolated Expressions are upgraded to ExpressionStatements. 91 // Interpolated Expressions are upgraded to ExpressionStatements.
90 testStatement('{ #; #; }', [eOne, eOne], '{\n 1;\n 1;\n}'), 92 testStatement('{ #; #; }', [eOne, eOne], '{\n 1;\n 1;\n}'),
91 testStatement('{ #a; #b; }', {'a': eOne, 'b': eOne}, '{\n 1;\n 1;\n}'), 93 testStatement('{ #a; #b; }', {'a': eOne, 'b': eOne}, '{\n 1;\n 1;\n}'),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 testStatement('if (#a) #b;', 126 testStatement('if (#a) #b;',
125 {'a': false, 'b': block12}, 127 {'a': false, 'b': block12},
126 ';'), 128 ';'),
127 testStatement('if (#a) 3; else #b;', 129 testStatement('if (#a) 3; else #b;',
128 {'a': true, 'b': block12}, 130 {'a': true, 'b': block12},
129 '3;'), 131 '3;'),
130 testStatement('if (#a) 3; else #b;', 132 testStatement('if (#a) 3; else #b;',
131 {'a': false, 'b': block12}, 133 {'a': false, 'b': block12},
132 '{\n 1;\n 2;\n}'), 134 '{\n 1;\n 2;\n}'),
133 135
136 testStatement('while (#) #', [eOne, block12], 'while (1) {\n 1;\n 2;\n}'),
137 testStatement('while (#) #;', [eTrue, block12],
138 'while (true) {\n 1;\n 2;\n}'),
139 testStatement('while (#) #;', [eVar, block12],
140 'while (x) {\n 1;\n 2;\n}'),
141 testStatement('while (#) #;', ['a', block12],
142 'while (a) {\n 1;\n 2;\n}'),
143 testStatement('while (#) #;', ['a', stm],
144 'while (a)\n foo();'),
145
146 testStatement('do {#} while (#)', [block12, eOne],
147 'do {\n 1;\n 2;\n} while (1); '),
148 testStatement('do {#} while (#)', [block12, eTrue],
149 'do {\n 1;\n 2;\n} while (true); '),
150 testStatement('do {#} while (#);', [block12, eVar],
151 'do {\n 1;\n 2;\n} while (x);'),
152 testStatement('do {#} while (#)', [block12, 'a'],
153 'do {\n 1;\n 2;\n} while (a);'),
154 testStatement('do # ; while (#)', [stm, 'a'],
155 'do\n foo();\nwhile (a);'),
156
157 testStatement('switch (#) {}', [eOne], 'switch (1) {\n}'),
158 testStatement('''
159 switch (#) {
160 case #: { # }
161 }''', [eTrue, eOne, block12],
162 'switch (true) {\n case 1:\n 1;\n 2;\n}'),
163 testStatement('''
164 switch (#) {
165 case #: { # }
166 break;
167 case #: { # }
168 default: { # }
169 }''', [eTrue, eOne, block12, eTwo, block12, stm], '''
170 switch (true) {
171 case 1:
172 1;
173 2;
174 break;
175 case 2:
176 1;
177 2;
178 default:
179 foo();
180 }'''),
134 181
135 testStatement(NAMED_FUNCTION_1, [eOne], NAMED_FUNCTION_1_ONE), 182 testStatement(NAMED_FUNCTION_1, [eOne], NAMED_FUNCTION_1_ONE),
136 testStatement(NAMED_FUNCTION_1_NAMED_HOLE, 183 testStatement(NAMED_FUNCTION_1_NAMED_HOLE,
137 {'hole': eOne}, 184 {'hole': eOne},
138 NAMED_FUNCTION_1_ONE), 185 NAMED_FUNCTION_1_ONE),
139 186
140 testStatement(MISC_1, [block12], MISC_1_1), 187 testStatement(MISC_1, [block12], MISC_1_1),
141 testStatement(MISC_1_NAMED_HOLE, {'hole': block12}, MISC_1_1), 188 testStatement(MISC_1_NAMED_HOLE, {'hole': block12}, MISC_1_1),
142 189
143 // Argument list splicing. 190 // Argument list splicing.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 testStatement('function foo(#){}', [['x', 'y']], 'function foo(x, y) {\n}'), 240 testStatement('function foo(#){}', [['x', 'y']], 'function foo(x, y) {\n}'),
194 testStatement('function foo(#a){}', {'a': new jsAst.Parameter('x')}, 241 testStatement('function foo(#a){}', {'a': new jsAst.Parameter('x')},
195 'function foo(x) {\n}'), 242 'function foo(x) {\n}'),
196 testStatement('function foo(#a){}', {'a': 'x'}, 'function foo(x) {\n}'), 243 testStatement('function foo(#a){}', {'a': 'x'}, 'function foo(x) {\n}'),
197 testStatement('function foo(#a){}', {'a': []}, 'function foo() {\n}'), 244 testStatement('function foo(#a){}', {'a': []}, 'function foo() {\n}'),
198 testStatement('function foo(#a){}', {'a': ['x']}, 'function foo(x) {\n}'), 245 testStatement('function foo(#a){}', {'a': ['x']}, 'function foo(x) {\n}'),
199 testStatement('function foo(#a){}', 246 testStatement('function foo(#a){}',
200 {'a': ['x', 'y']}, 247 {'a': ['x', 'y']},
201 'function foo(x, y) {\n}'), 248 'function foo(x, y) {\n}'),
202 249
250 testStatement('function foo() async {}', [], 'function foo() async {\n}'),
251 testStatement('function foo() sync* {}', [], 'function foo() sync* {\n}'),
252 testStatement('function foo() async* {}', [], 'function foo() async* {\n}'),
253
203 testStatement('a = #.#', [eVar,eOne], 'a = x[1];'), 254 testStatement('a = #.#', [eVar,eOne], 'a = x[1];'),
204 testStatement('a = #.#', [eVar,'foo'], 'a = x.foo;'), 255 testStatement('a = #.#', [eVar,'foo'], 'a = x.foo;'),
205 testStatement('a = #a.#b', {'a': eVar, 'b': eOne}, 'a = x[1];'), 256 testStatement('a = #a.#b', {'a': eVar, 'b': eOne}, 'a = x[1];'),
206 testStatement('a = #a.#b', {'a': eVar, 'b': 'foo'}, 'a = x.foo;'), 257 testStatement('a = #a.#b', {'a': eVar, 'b': 'foo'}, 'a = x.foo;'),
207 258
208 testStatement('function f(#) { return #.#; }', ['x', eVar,'foo'], 259 testStatement('function f(#) { return #.#; }', ['x', eVar,'foo'],
209 'function f(x) {\n return x.foo;\n}'), 260 'function f(x) {\n return x.foo;\n}'),
210 testStatement('function f(#a) { return #b.#c; }', 261 testStatement('function f(#a) { return #b.#c; }',
211 {'a': 'x', 'b': eVar, 'c': 'foo'}, 262 {'a': 'x', 'b': eVar, 'c': 'foo'},
212 'function f(x) {\n return x.foo;\n}'), 263 'function f(x) {\n return x.foo;\n}'),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 304
254 // Use the same name several times. 305 // Use the same name several times.
255 testStatement('#a.prototype.#a = function(#b) { return #c.#c };', 306 testStatement('#a.prototype.#a = function(#b) { return #c.#c };',
256 {'a': 'name1_2', 307 {'a': 'name1_2',
257 'b': ['r', 'y'], 308 'b': ['r', 'y'],
258 'c': 'name4_5'}, 309 'c': 'name4_5'},
259 'name1_2.prototype.name1_2 = function(r, y) {\n' 310 'name1_2.prototype.name1_2 = function(r, y) {\n'
260 ' return name4_5.name4_5;\n' 311 ' return name4_5.name4_5;\n'
261 '};'), 312 '};'),
262 313
314 testStatement('label: while (a) { label2: break label;}', [],
315 'label:\n while (a) {\n label2:\n break label;\n }'),
316
263 ])); 317 ]));
264 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698