Index: tests/language/async_await_test.dart |
diff --git a/tests/language/async_await_test.dart b/tests/language/async_await_test.dart |
index 62ebe28ef672ffc670d1b8b649727c6a5e24d8c9..fe76505151573cb604301003a06ee9b4e607ca24 100644 |
--- a/tests/language/async_await_test.dart |
+++ b/tests/language/async_await_test.dart |
@@ -15,7 +15,10 @@ main() { |
group("basic", () { |
test("async w/o await", () { |
- f() async { return id(42); } |
+ f() async { |
+ return id(42); |
+ } |
+ |
return expect42(f()); |
}); |
@@ -25,7 +28,9 @@ main() { |
f() async { |
result.add(1); |
return id(42); |
- }; |
+ } |
+ |
+ ; |
var future = f(); |
result.add(0); |
return future.whenComplete(() { |
@@ -38,6 +43,7 @@ main() { |
throw "err"; |
return id(42); |
} |
+ |
return throwsErr(f()); |
}); |
@@ -45,7 +51,9 @@ main() { |
f() async { |
var v = await new Future.value(42); |
return v; |
- }; |
+ } |
+ |
+ ; |
return expect42(f()); |
}); |
@@ -53,7 +61,9 @@ main() { |
f() async { |
var v = await id(42); |
return v; |
- }; |
+ } |
+ |
+ ; |
return expect42(f()); |
}); |
@@ -61,7 +71,9 @@ main() { |
f() async { |
var v = await null; |
expect(v, equals(null)); |
- }; |
+ } |
+ |
+ ; |
return f(); |
}); |
@@ -69,6 +81,7 @@ main() { |
f() async { |
return await await new Future.value(42); |
} |
+ |
return expect42(f()); |
}); |
@@ -76,6 +89,7 @@ main() { |
f() async { |
return await new FakeValueFuture(42); |
} |
+ |
return expect42(f()); |
}); |
@@ -83,33 +97,39 @@ main() { |
f() async { |
return await new FakeErrorFuture("err"); |
} |
+ |
return throwsErr(f()); |
}); |
test("await value is delayed", () { |
f() async { |
bool x = false; |
- scheduleMicrotask(() { x = true; }); |
+ scheduleMicrotask(() { |
+ x = true; |
+ }); |
var y = await true; |
expect(x, equals(y)); |
} |
+ |
return f(); |
}); |
test("await throw", () { |
f() async { |
- await (throw "err"); // Check grammar: Are parentheses necessary? |
+ await (throw "err"); // Check grammar: Are parentheses necessary? |
return id(42); |
} |
+ |
return throwsErr(f()); |
}); |
test("throw before await", () { |
f() async { |
var x = throw "err"; |
- await x; // Check grammar: Are parentheses necessary? |
+ await x; // Check grammar: Are parentheses necessary? |
return id(42); |
} |
+ |
return throwsErr(f()); |
}); |
@@ -119,6 +139,7 @@ main() { |
assert(v == 87); |
return await new Future.microtask(() => 42); |
} |
+ |
return f(42).then((_) { |
fail("assert didn't throw"); |
}, onError: (e, s) { |
@@ -132,6 +153,7 @@ main() { |
assert(v == 87); |
return x; |
} |
+ |
return f(42).then((_) { |
fail("assert didn't throw"); |
}, onError: (e, s) { |
@@ -145,22 +167,27 @@ main() { |
await new Future.error("err"); |
return id(42); |
} |
+ |
return throwsErr(f()); |
}); |
test("async flattens futures", () { |
f() async { |
- return new Future.value(42); // Not awaited. |
- }; |
+ return new Future.value(42); // Not awaited. |
+ } |
+ |
+ ; |
return f().then((v) { |
- expect(v, equals(42)); // And not a Future with value 42. |
+ expect(v, equals(42)); // And not a Future with value 42. |
}); |
}); |
test("async flattens futures, error", () { |
f() async { |
- return new Future.error("err"); // Not awaited. |
- }; |
+ return new Future.error("err"); // Not awaited. |
+ } |
+ |
+ ; |
return throwsErr(f()); |
}); |
@@ -172,8 +199,9 @@ main() { |
} |
return i; |
} |
+ |
return f(mkStream()).then((v) { |
- expect(v, equals(45)); // 0 + 1 + ... + 9 |
+ expect(v, equals(45)); // 0 + 1 + ... + 9 |
}); |
}); |
@@ -185,8 +213,9 @@ main() { |
} |
return i; |
} |
+ |
return f(mkStream()).then((v) { |
- expect(v, equals(45)); // 0 + 1 + ... + 9 |
+ expect(v, equals(45)); // 0 + 1 + ... + 9 |
}); |
}); |
@@ -198,6 +227,7 @@ main() { |
} |
return v; |
} |
+ |
var s = (new StreamController()..close()).stream; |
return f(s).then((v) { |
expect(v, equals(0)); |
@@ -214,6 +244,7 @@ main() { |
} |
return i; |
} |
+ |
return f(mkStream()).then((v) { |
fail("assert didn't throw"); |
}, onError: (e, s) { |
@@ -232,6 +263,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(10 * id(42))); |
}); |
@@ -245,6 +277,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(10 * 5)); |
}); |
@@ -258,6 +291,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(10 * 5)); |
}); |
@@ -271,6 +305,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(10 * 3)); |
}); |
@@ -284,6 +319,7 @@ main() { |
} |
return v; |
} |
+ |
return throwsErr(f()); |
}); |
@@ -295,6 +331,7 @@ main() { |
} |
return v; |
} |
+ |
return throwsErr(f()); |
}); |
@@ -306,6 +343,7 @@ main() { |
} |
return v; |
} |
+ |
return throwsErr(f()); |
}); |
@@ -317,6 +355,7 @@ main() { |
} |
return v; |
} |
+ |
return throwsErr(f()); |
}); |
@@ -328,6 +367,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(0)); |
}); |
@@ -341,6 +381,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(0)); |
}); |
@@ -355,6 +396,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 2)); |
}); |
@@ -369,6 +411,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 2)); |
}); |
@@ -383,6 +426,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 9)); |
}); |
@@ -398,6 +442,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 9)); |
}); |
@@ -415,6 +460,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(10 * id(42))); |
}); |
@@ -430,6 +476,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(10 * 5)); |
}); |
@@ -445,6 +492,7 @@ main() { |
} |
return v; |
} |
+ |
return throwsErr(f()); |
}); |
@@ -458,6 +506,7 @@ main() { |
} |
return v; |
} |
+ |
return throwsErr(f()); |
}); |
@@ -472,6 +521,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 2)); |
}); |
@@ -488,6 +538,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 3)); |
}); |
@@ -504,6 +555,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 9)); |
}); |
@@ -521,6 +573,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 9)); |
}); |
@@ -538,6 +591,7 @@ main() { |
} while (i < 10); |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(10 * id(42))); |
}); |
@@ -553,6 +607,7 @@ main() { |
} while (i < await new Future.value(42)); |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(10 * 5)); |
}); |
@@ -568,8 +623,12 @@ main() { |
} while (i < 10); |
return v; |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
}); |
test("await err in test", () { |
@@ -582,8 +641,12 @@ main() { |
} while (i < await new Future.error("err")); |
return v; |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
}); |
test("break before await", () { |
@@ -597,6 +660,7 @@ main() { |
} while (i < 10); |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 2)); |
}); |
@@ -613,6 +677,7 @@ main() { |
} while (i < 10); |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 3)); |
}); |
@@ -629,6 +694,7 @@ main() { |
} while (i < 10); |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 9)); |
}); |
@@ -646,6 +712,7 @@ main() { |
} while (i < 10); |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(42 * 9)); |
}); |
@@ -661,6 +728,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(6)); |
}); |
@@ -674,6 +742,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(6)); |
}); |
@@ -682,15 +751,18 @@ main() { |
test("await err in for-in", () { |
f() async { |
var v = 0; |
- for (var fut in [1, 2, 3].map((v) => (v != 1) |
- ? new Future.value(v) |
- : new Future.error("err"))) { |
+ for (var fut in [1, 2, 3].map( |
+ (v) => (v != 1) ? new Future.value(v) : new Future.error("err"))) { |
v += await fut; |
} |
return v; |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
}); |
test("await err in for-in iterable", () { |
@@ -701,8 +773,12 @@ main() { |
} |
return v; |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
}); |
test("break before await in for-in", () { |
@@ -714,6 +790,7 @@ main() { |
} |
return v; |
} |
+ |
return f().then((v) { |
expect(v, equals(3)); |
}); |
@@ -725,10 +802,11 @@ main() { |
f() async { |
try { |
return await id(42); |
- } catch(e) { |
+ } catch (e) { |
return 37; |
} |
} |
+ |
return expect42(f()); |
}); |
@@ -736,10 +814,11 @@ main() { |
f() async { |
try { |
await new Future.error(42); |
- } catch(e) { |
+ } catch (e) { |
return e; |
} |
} |
+ |
return expect42(f()); |
}); |
@@ -749,10 +828,11 @@ main() { |
try { |
if (i >= 0) throw id(42); |
return await new Future.value(10); |
- } catch(e) { |
+ } catch (e) { |
return e; |
} |
} |
+ |
return expect42(f()); |
}); |
@@ -760,10 +840,11 @@ main() { |
f() async { |
try { |
throw id(42); |
- } catch(e) { |
+ } catch (e) { |
return await new Future.value(e); |
} |
} |
+ |
return expect42(f()); |
}); |
@@ -771,25 +852,33 @@ main() { |
f() async { |
try { |
throw id(42); |
- } catch(e) { |
+ } catch (e) { |
await new Future.error("err"); |
} |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
}); |
test("try-catch-rethrow", () { |
f() async { |
try { |
await new Future.error("err"); |
- } catch(e) { |
+ } catch (e) { |
if (e == id(42)) return; |
rethrow; |
} |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
}); |
}); |
@@ -802,6 +891,7 @@ main() { |
// Don't do anything. |
} |
} |
+ |
return expect42(f()); |
}); |
@@ -814,6 +904,7 @@ main() { |
x = await new Future.value(37); |
} |
} |
+ |
return f().then((v) { |
expect(v, equals(42)); |
expect(x, equals(37)); |
@@ -828,8 +919,12 @@ main() { |
// Don't do anything. |
} |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
}); |
test("await err in finally", () { |
@@ -840,8 +935,12 @@ main() { |
await new Future.error("err"); |
} |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
}); |
test("await err in both", () { |
@@ -852,8 +951,12 @@ main() { |
await new Future.error("err"); |
} |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
}); |
test("await err in body, override in finally", () { |
@@ -864,25 +967,29 @@ main() { |
return id(42); |
} |
} |
+ |
return expect42(f()); |
}); |
test("await in body, override in finally", () { |
f() async { |
- label: try { |
+ label: |
+ try { |
return await new Future.value(37); |
} finally { |
break label; |
} |
return id(42); |
} |
+ |
return expect42(f()); |
}); |
test("await, override in finally", () { |
var x = 0; |
f() async { |
- label: try { |
+ label: |
+ try { |
return 87; |
} finally { |
x = await new Future.value(37); |
@@ -890,6 +997,7 @@ main() { |
} |
return id(42); |
} |
+ |
return f().then((v) { |
expect(v, equals(42)); |
expect(x, equals(37)); |
@@ -899,7 +1007,8 @@ main() { |
test("throw in body, await, override in finally 3", () { |
var x = 0; |
f() async { |
- label: try { |
+ label: |
+ try { |
throw "err"; |
} finally { |
x = await new Future.value(37); |
@@ -907,6 +1016,7 @@ main() { |
} |
return id(42); |
} |
+ |
return f().then((v) { |
expect(v, equals(42)); |
expect(x, equals(37)); |
@@ -915,13 +1025,15 @@ main() { |
test("await err in body, override in finally 2", () { |
f() async { |
- label: try { |
+ label: |
+ try { |
return await new Future.error("err"); |
} finally { |
break label; |
} |
return id(42); |
} |
+ |
return expect42(f()); |
}); |
@@ -936,6 +1048,7 @@ main() { |
} |
return id(42); |
} |
+ |
return expect42(f()); |
}); |
@@ -952,6 +1065,7 @@ main() { |
} |
return id(i); |
} |
+ |
return f().then((v) { |
expect(v, equals(10)); |
}); |
@@ -970,6 +1084,7 @@ main() { |
} |
return id(i); |
} |
+ |
return f().then((v) { |
expect(v, equals(0)); |
}); |
@@ -987,6 +1102,7 @@ main() { |
} |
return id(42); |
} |
+ |
return expect42(f()); |
}); |
@@ -1002,6 +1118,7 @@ main() { |
} |
return id(42); |
} |
+ |
return expect42(f()); |
}); |
@@ -1018,6 +1135,7 @@ main() { |
x += await new Future.value(37); |
} |
} |
+ |
return f().then((v) { |
expect(v, equals(42)); |
expect(x, equals(74)); |
@@ -1027,7 +1145,8 @@ main() { |
test("nested finallies 2", () { |
var x = 0; |
f() async { |
- label: try { |
+ label: |
+ try { |
try { |
break label; |
} finally { |
@@ -1038,6 +1157,7 @@ main() { |
} |
return 42; |
} |
+ |
return f().then((v) { |
expect(v, equals(42)); |
expect(x, equals(74)); |
@@ -1047,7 +1167,8 @@ main() { |
test("nested finallies 3", () { |
var x = 0; |
f() async { |
- label: try { |
+ label: |
+ try { |
try { |
break label; |
} finally { |
@@ -1058,6 +1179,7 @@ main() { |
} |
return 42; |
} |
+ |
return expect42(f()); |
}); |
@@ -1074,11 +1196,13 @@ main() { |
x += await new Future.value(37); |
} |
} |
- return f().then((v) { fail("didn't throw"); }, |
- onError: (e) { |
- expect(e, equals("err")); |
- expect(x, equals(2 * 37)); |
- }); |
+ |
+ return f().then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ expect(x, equals(2 * 37)); |
+ }); |
}); |
}); |
@@ -1093,6 +1217,7 @@ main() { |
if (id(42) == id(10)) return 10; |
} |
} |
+ |
return expect42(f()); |
}); |
@@ -1106,6 +1231,7 @@ main() { |
if (id(42) == id(10)) return 10; |
} |
} |
+ |
return expect42(f()); |
}); |
@@ -1119,6 +1245,7 @@ main() { |
if (id(42) == id(10)) return 10; |
} |
} |
+ |
return expect42(f()); |
}); |
@@ -1134,6 +1261,7 @@ main() { |
if (id(42) == id(10)) return 10; |
} |
} |
+ |
return f().then((v) { |
expect(v, equals(42)); |
expect(x, equals(37)); |
@@ -1145,48 +1273,64 @@ main() { |
test("await in expression", () { |
f(v) async { |
switch (await new Future.value(v)) { |
- case 1: return 1; |
- case 2: return 42; |
- default: return 3; |
+ case 1: |
+ return 1; |
+ case 2: |
+ return 42; |
+ default: |
+ return 3; |
} |
return null; |
} |
+ |
return expect42(f(2)); |
}); |
test("await err in expression", () { |
f(v) async { |
switch (await new Future.error("err")) { |
- case 1: return 1; |
- case 2: return 42; |
- default: return 3; |
+ case 1: |
+ return 1; |
+ case 2: |
+ return 42; |
+ default: |
+ return 3; |
} |
return null; |
} |
+ |
return throwsErr(f(2)); |
}); |
test("await in case", () { |
f(v) async { |
switch (v) { |
- case 1: return 1; |
- case 2: return await new Future.value(42); |
- default: return 3; |
+ case 1: |
+ return 1; |
+ case 2: |
+ return await new Future.value(42); |
+ default: |
+ return 3; |
} |
return null; |
} |
+ |
return expect42(f(2)); |
}); |
test("await err in case", () { |
f(v) async { |
switch (v) { |
- case 1: return 1; |
- case 2: return await new Future.error("err"); |
- default: return 3; |
+ case 1: |
+ return 1; |
+ case 2: |
+ return await new Future.error("err"); |
+ default: |
+ return 3; |
} |
return null; |
} |
+ |
return throwsErr(f(2)); |
}); |
@@ -1194,14 +1338,17 @@ main() { |
f(v) async { |
switch (v) { |
label: |
- case 1: return 42; |
+ case 1: |
+ return 42; |
case 2: |
if (v <= 2) continue label; |
return await new Future.value(10); |
- default: return 3; |
+ default: |
+ return 3; |
} |
return null; |
} |
+ |
return expect42(f(2)); |
}); |
@@ -1209,14 +1356,17 @@ main() { |
f(v) async { |
switch (v) { |
label: |
- case 1: return 42; |
+ case 1: |
+ return 42; |
case 2: |
await new Future.value(10); |
continue label; |
- default: return 3; |
+ default: |
+ return 3; |
} |
return null; |
} |
+ |
return expect42(f(2)); |
}); |
}); |
@@ -1230,6 +1380,7 @@ main() { |
return 37; |
} |
} |
+ |
return expect42(f(true)); |
}); |
@@ -1241,6 +1392,7 @@ main() { |
return 37; |
} |
} |
+ |
return throwsErr(f(true)); |
}); |
@@ -1251,6 +1403,7 @@ main() { |
} |
return 37; |
} |
+ |
return expect42(f(true)); |
}); |
@@ -1261,6 +1414,7 @@ main() { |
} |
return 37; |
} |
+ |
return throwsErr(f(true)); |
}); |
@@ -1273,6 +1427,7 @@ main() { |
} |
return 37; |
} |
+ |
return expect42(f(true)); |
}); |
@@ -1285,6 +1440,7 @@ main() { |
} |
return 37; |
} |
+ |
return throwsErr(f(true)); |
}); |
@@ -1297,6 +1453,7 @@ main() { |
} |
return 87; |
} |
+ |
return expect42(f(false)); |
}); |
@@ -1309,6 +1466,7 @@ main() { |
} |
return 87; |
} |
+ |
return throwsErr(f(false)); |
}); |
@@ -1323,6 +1481,7 @@ main() { |
} |
return 87; |
} |
+ |
return expect42(f(false)); |
}); |
@@ -1337,6 +1496,7 @@ main() { |
} |
return 87; |
} |
+ |
return expect42(f(false)); |
}); |
}); |
@@ -1346,6 +1506,7 @@ main() { |
f(v) async { |
return (await new Future.value(v)) ? 42 : 37; |
} |
+ |
return expect42(f(true)); |
}); |
@@ -1353,6 +1514,7 @@ main() { |
f(v) async { |
return (await new Future.error("err")) ? 42 : 37; |
} |
+ |
return throwsErr(f(true)); |
}); |
@@ -1360,6 +1522,7 @@ main() { |
f(v) async { |
return v ? (await new Future.value(42)) : 37; |
} |
+ |
return expect42(f(true)); |
}); |
@@ -1367,6 +1530,7 @@ main() { |
f(v) async { |
return v ? (await new Future.error("err")) : 37; |
} |
+ |
return throwsErr(f(true)); |
}); |
@@ -1374,6 +1538,7 @@ main() { |
f(v) async { |
return v ? 37 : (await new Future.value(42)); |
} |
+ |
return expect42(f(false)); |
}); |
@@ -1381,6 +1546,7 @@ main() { |
f(v) async { |
return v ? 37 : (await new Future.error("err")); |
} |
+ |
return throwsErr(f(false)); |
}); |
}); |
@@ -1553,6 +1719,7 @@ main() { |
f() async { |
return await l42; |
} |
+ |
return expect42(f()); |
}); |
@@ -1560,6 +1727,7 @@ main() { |
f(p) async { |
return await p; |
} |
+ |
return expect42(f(42)); |
}); |
@@ -1567,6 +1735,7 @@ main() { |
f() async { |
return await v42; |
} |
+ |
return expect42(f()); |
}); |
@@ -1574,6 +1743,7 @@ main() { |
f() async { |
return await c42; |
} |
+ |
return expect42(f()); |
}); |
@@ -1581,6 +1751,7 @@ main() { |
f() async { |
return -await -42; |
} |
+ |
return expect42(f()); |
}); |
@@ -1589,6 +1760,7 @@ main() { |
var v = [42]; |
return await v[0]; |
} |
+ |
return expect42(f()); |
}); |
@@ -1597,6 +1769,7 @@ main() { |
var x = 42; |
return await x++; |
} |
+ |
return expect42(f()); |
}); |
@@ -1605,6 +1778,7 @@ main() { |
var v = [42]; |
return await v[0]++; |
} |
+ |
return expect42(f()); |
}); |
@@ -1613,6 +1787,7 @@ main() { |
var v = [42]; |
return await v[await 0]++; |
} |
+ |
return expect42(f()); |
}); |
@@ -1621,6 +1796,7 @@ main() { |
var x = 41; |
return await ++x; |
} |
+ |
return expect42(f()); |
}); |
@@ -1629,6 +1805,7 @@ main() { |
var v = [41]; |
return await ++v[0]; |
} |
+ |
return expect42(f()); |
}); |
@@ -1637,6 +1814,7 @@ main() { |
var x = 37; |
return await (x = 42); |
} |
+ |
return expect42(f()); |
}); |
@@ -1645,6 +1823,7 @@ main() { |
var x = 37; |
return await (x += 5); |
} |
+ |
return expect42(f()); |
}); |
@@ -1652,6 +1831,7 @@ main() { |
f() async { |
return await (10 + 11) + await (10 + 11); |
} |
+ |
return expect42(f()); |
}); |
@@ -1659,6 +1839,7 @@ main() { |
f(v) async { |
return await ((v == 10) ? new Future.value(42) : 37); |
} |
+ |
return expect42(f(10)); |
}); |
@@ -1666,6 +1847,7 @@ main() { |
f() async { |
return await topMethod(42); |
} |
+ |
return expect42(f()); |
}); |
@@ -1673,6 +1855,7 @@ main() { |
f() async { |
return await Async.staticMethod(42); |
} |
+ |
return expect42(f()); |
}); |
@@ -1681,6 +1864,7 @@ main() { |
var a = new Async(); |
return await a.instanceMethod(42); |
} |
+ |
return expect42(f()); |
}); |
@@ -1688,6 +1872,7 @@ main() { |
f() async { |
return await topMethod(await 42); |
} |
+ |
return expect42(f()); |
}); |
@@ -1695,6 +1880,7 @@ main() { |
f() async { |
return await Async.staticMethod(await 42); |
} |
+ |
return expect42(f()); |
}); |
@@ -1703,6 +1889,7 @@ main() { |
var a = new Async(); |
return await a.instanceMethod(await 42); |
} |
+ |
return expect42(f()); |
}); |
@@ -1710,6 +1897,7 @@ main() { |
f() async { |
return await topGetter; |
} |
+ |
return expect42(f()); |
}); |
@@ -1717,6 +1905,7 @@ main() { |
f() async { |
return await Async.staticGetter; |
} |
+ |
return expect42(f()); |
}); |
@@ -1725,6 +1914,7 @@ main() { |
var a = new Async(); |
return await a.instanceGetter; |
} |
+ |
return expect42(f()); |
}); |
@@ -1735,6 +1925,7 @@ main() { |
assert(await new Future.microtask(() => true)); |
return 42; |
} |
+ |
return expect42(f()); |
}); |
@@ -1743,6 +1934,7 @@ main() { |
assert(await new Future.microtask(() => false)); |
return 42; |
} |
+ |
return f().then((_) { |
fail("assert didn't throw"); |
}, onError: (e, s) { |
@@ -1755,13 +1947,13 @@ main() { |
assert(await new Future.microtask(() => false)); |
return 42; |
} |
+ |
return f().then((_) { |
fail("assert didn't throw"); |
}, onError: (e, s) { |
expect(e is AssertionError, isTrue); |
}); |
}); |
- |
}); |
group("syntax", () { |
@@ -1785,7 +1977,6 @@ main() { |
}); |
} |
- |
// Attempt to obfuscates value to avoid too much constant folding. |
id(v) { |
try { |
@@ -1808,6 +1999,7 @@ Stream mkStream() { |
scheduleMicrotask(next); |
} |
} |
+ |
c = new StreamController(onListen: () { |
scheduleMicrotask(next); |
}); |
@@ -1816,8 +2008,11 @@ Stream mkStream() { |
// Check that future contains the error "err". |
Future throwsErr(Future future) { |
- return future.then((v) { fail("didn't throw"); }, |
- onError: (e) { expect(e, equals("err")); }); |
+ return future.then((v) { |
+ fail("didn't throw"); |
+ }, onError: (e) { |
+ expect(e, equals("err")); |
+ }); |
} |
// Check that future contains the value 42. |
@@ -1827,10 +2022,11 @@ Future expect42(Future future) { |
}); |
} |
- |
// Various async declarations. |
-Future topMethod(f) async { return await f; } |
+Future topMethod(f) async { |
+ return await f; |
+} |
Future topArrowMethod(f) async => await f; |
@@ -1841,7 +2037,10 @@ Future get topGetter async { |
Future get topArrowGetter async => await new Future.value(42); |
Future topLocal(f) { |
- local() async { return await f; } |
+ local() async { |
+ return await f; |
+ } |
+ |
return local(); |
} |
@@ -1851,14 +2050,18 @@ Future topArrowLocal(f) { |
} |
Future topExpression(f) { |
- return () async { return await f; } (); |
+ return () async { |
+ return await f; |
+ }(); |
} |
Future topArrowExpression(f) { |
- return (() async => await f) (); |
+ return (() async => await f)(); |
} |
-var topVarExpression = (f) async { return await f; }; |
+var topVarExpression = (f) async { |
+ return await f; |
+}; |
var topVarArrowExpression = (f) async => await f; |
@@ -1866,12 +2069,17 @@ class Async { |
var initValue; |
Async(); |
- Async.initializer(f) : initValue = (() async { return await f; } ()); |
+ Async.initializer(f) |
+ : initValue = (() async { |
+ return await f; |
+ }()); |
- Async.initializerArrow(f) : initValue = ((() async => await f) ()); |
+ Async.initializerArrow(f) : initValue = ((() async => await f)()); |
/* static */ |
- static Future staticMethod(f) async { return await f; } |
+ static Future staticMethod(f) async { |
+ return await f; |
+ } |
static Future staticArrowMethod(f) async => await f; |
@@ -1882,7 +2090,10 @@ class Async { |
static Future get staticArrowGetter async => await new Future.value(42); |
static Future staticLocal(f) { |
- local() async { return await f; } |
+ local() async { |
+ return await f; |
+ } |
+ |
return local(); |
} |
@@ -1892,19 +2103,25 @@ class Async { |
} |
static Future staticExpression(f) { |
- return () async { return await f; } (); |
+ return () async { |
+ return await f; |
+ }(); |
} |
static Future staticArrowExpression(f) { |
- return (() async => await f) (); |
+ return (() async => await f)(); |
} |
- static var staticVarExpression = (f) async { return await f; }; |
+ static var staticVarExpression = (f) async { |
+ return await f; |
+ }; |
static var staticVarArrowExpression = (f) async => await f; |
/* instance */ |
- Future instanceMethod(f) async { return await f; } |
+ Future instanceMethod(f) async { |
+ return await f; |
+ } |
Future instanceArrowMethod(f) async => await f; |
@@ -1915,7 +2132,10 @@ class Async { |
Future get instanceArrowGetter async => await new Future.value(42); |
Future instanceLocal(f) { |
- local() async { return await f; } |
+ local() async { |
+ return await f; |
+ } |
+ |
return local(); |
} |
@@ -1925,14 +2145,18 @@ class Async { |
} |
Future instanceExpression(f) { |
- return () async { return await f; } (); |
+ return () async { |
+ return await f; |
+ }(); |
} |
Future instanceArrowExpression(f) { |
- return (() async => await f) (); |
+ return (() async => await f)(); |
} |
- var instanceVarExpression = (f) async { return await f; }; |
+ var instanceVarExpression = (f) async { |
+ return await f; |
+ }; |
var instanceVarArrowExpression = (f) async => await f; |
} |
@@ -1941,6 +2165,7 @@ Future asyncInAsync(f) async { |
inner(f) async { |
return await f; |
} |
+ |
return await inner(f); |
} |
@@ -1948,6 +2173,7 @@ Future asyncInSync(f) { |
inner(f) async { |
return await f; |
} |
+ |
return inner(f); |
} |
@@ -1955,6 +2181,7 @@ Future syncInAsync(f) async { |
inner(f) { |
return f; |
} |
+ |
return await inner(f); |
} |
@@ -1967,11 +2194,18 @@ class FakeValueFuture implements Future { |
Future then(callback(value), {Function onError}) { |
return new Future.microtask(() => callback(_value)); |
} |
+ |
Future whenComplete(callback()) { |
- return new Future.microtask(() { callback(); }); |
+ return new Future.microtask(() { |
+ callback(); |
+ }); |
} |
+ |
Future catchError(Function onError, {bool test(error)}) => this; |
- Stream asStream() => (new StreamController()..add(_value)..close()).stream; |
+ Stream asStream() => (new StreamController() |
+ ..add(_value) |
+ ..close()) |
+ .stream; |
Future timeout(Duration duration, {onTimeout}) => this; |
} |
@@ -1992,9 +2226,13 @@ class FakeErrorFuture implements Future { |
} |
return this; |
} |
+ |
Future whenComplete(callback()) { |
- return new Future.microtask(() { callback(); }).then((_) => this); |
+ return new Future.microtask(() { |
+ callback(); |
+ }).then((_) => this); |
} |
+ |
Future catchError(Function onError, {bool test(error)}) { |
return new Future.microtask(() { |
if (test != null && !test(_error)) return this; |
@@ -2004,7 +2242,10 @@ class FakeErrorFuture implements Future { |
return onError(_error); |
}); |
} |
- Stream asStream() => |
- (new StreamController()..addError(_error)..close()).stream; |
+ |
+ Stream asStream() => (new StreamController() |
+ ..addError(_error) |
+ ..close()) |
+ .stream; |
Future timeout(Duration duration, {onTimeout}) => this; |
} |