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

Unified Diff: tests/compiler/dart2js/type_checker_test.dart

Issue 886833005: Fix await parsing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added comment 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/compiler/dart2js/mock_libraries.dart ('k') | tests/utils/dummy_compiler_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/type_checker_test.dart
diff --git a/tests/compiler/dart2js/type_checker_test.dart b/tests/compiler/dart2js/type_checker_test.dart
index 697a866ff16f899128b8b36939a548122d09d417..387eb82f00e116839320ed89582b54929bff499b 100644
--- a/tests/compiler/dart2js/type_checker_test.dart
+++ b/tests/compiler/dart2js/type_checker_test.dart
@@ -54,7 +54,8 @@ main() {
testInitializers,
testTypePromotionHints,
testFunctionCall,
- testCascade];
+ testCascade,
+ testAwait];
asyncTest(() => Future.forEach(tests, (test) => setup(test)));
}
@@ -1999,6 +2000,32 @@ void testCascade(MockCompiler compiler) {
check('new A()..afunc()()[0] = new C();');
}
+testAwait(MockCompiler compiler) {
+ String script = """class Foo {
+ void method() async {}
+ Future<int> asyncInt() => new Future<int>.value(0);
+ Foo self() => this;
+ }""";
+ compiler.parseScript(script);
+ ClassElement foo = compiler.mainApp.find("Foo");
+ foo.ensureResolved(compiler);
+ FunctionElement method = foo.lookupLocalMember('method');
+ analyzeIn(compiler, method, "{ await 0; }");
+ analyzeIn(compiler, method, "{ int i = await 0; }");
+ analyzeIn(compiler, method, "{ String s = await 0; }", NOT_ASSIGNABLE);
+ analyzeIn(compiler, method, "{ await asyncInt(); }");
+ analyzeIn(compiler, method, "{ int i = await asyncInt(); }");
+ analyzeIn(compiler, method, "{ String s = await asyncInt(); }",
+ NOT_ASSIGNABLE);
+ analyzeIn(compiler, method, "{ Foo f = self(); }");
+ analyzeIn(compiler, method, "{ Foo f = await self(); }");
+ analyzeIn(compiler, method, "{ Foo f = await self().asyncInt(); }",
+ NOT_ASSIGNABLE);
+ analyzeIn(compiler, method, "{ int i = await self().asyncInt(); }");
+ analyzeIn(compiler, method, "{ String s = await self().asyncInt(); }",
+ NOT_ASSIGNABLE);
+}
+
const CLASS_WITH_METHODS = '''
typedef int String2Int(String s);
@@ -2079,8 +2106,9 @@ const Map<String, String> ALT_SOURCE = const <String, String>{
};
Future setup(test(MockCompiler compiler)) {
- MockCompiler compiler = new MockCompiler.internal(coreSource: ALT_SOURCE);
- return compiler.init().then((_) => test(compiler));
+ MockCompiler compiler = new MockCompiler.internal(
+ coreSource: ALT_SOURCE, enableAsyncAwait: true);
+ return compiler.init("import 'dart:async';").then((_) => test(compiler));
}
DartType analyzeType(MockCompiler compiler, String text) {
@@ -2192,15 +2220,18 @@ void generateOutput(MockCompiler compiler, String text) {
}
analyzeIn(MockCompiler compiler,
- ExecutableElement element,
+ FunctionElement element,
String text,
[expectedWarnings]) {
if (expectedWarnings == null) expectedWarnings = [];
if (expectedWarnings is !List) expectedWarnings = [expectedWarnings];
+ compiler.resolver.resolve(element);
Token tokens = scan(text);
NodeListener listener = new NodeListener(compiler, null);
- Parser parser = new Parser(listener);
+ Parser parser = new Parser(listener,
+ yieldIsKeyword: element.asyncMarker.isYielding,
+ awaitIsKeyword: element.asyncMarker.isAsync);
parser.parseStatement(tokens);
Node node = listener.popNode();
TreeElements elements = compiler.resolveNodeStatement(node, element);
« no previous file with comments | « tests/compiler/dart2js/mock_libraries.dart ('k') | tests/utils/dummy_compiler_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698