| Index: tests/language/async_star_test.dart
|
| diff --git a/tests/language/async_star_test.dart b/tests/language/async_star_test.dart
|
| index fb7d2e4d17bc363d6613850e339b8d7c1ee2220c..691890fa32dfb25677b974e19c8b49e09496a4c4 100644
|
| --- a/tests/language/async_star_test.dart
|
| +++ b/tests/language/async_star_test.dart
|
| @@ -17,7 +17,10 @@ main() {
|
| });
|
|
|
| test("single", () {
|
| - f() async* { yield 42; }
|
| + f() async* {
|
| + yield 42;
|
| + }
|
| +
|
| return f().toList().then((v) {
|
| expect(v, equals([42]));
|
| });
|
| @@ -25,7 +28,11 @@ main() {
|
|
|
| test("call delays", () {
|
| var list = [];
|
| - f() async* { list.add(1); yield 2; }
|
| + f() async* {
|
| + list.add(1);
|
| + yield 2;
|
| + }
|
| +
|
| var res = f().forEach(list.add);
|
| list.add(0);
|
| return res.whenComplete(() {
|
| @@ -34,12 +41,15 @@ main() {
|
| });
|
|
|
| test("throws", () {
|
| - f() async* { yield 1; throw 2; }
|
| + f() async* {
|
| + yield 1;
|
| + throw 2;
|
| + }
|
| +
|
| var completer = new Completer();
|
| var list = [];
|
| f().listen(list.add,
|
| - onError: (v) => list.add("$v"),
|
| - onDone: completer.complete);
|
| + onError: (v) => list.add("$v"), onDone: completer.complete);
|
| return completer.future.whenComplete(() {
|
| expect(list, equals([1, "2"]));
|
| });
|
| @@ -51,6 +61,7 @@ main() {
|
| yield i;
|
| }
|
| }
|
| +
|
| return expectList(f(), new List.generate(10, id));
|
| });
|
|
|
| @@ -60,6 +71,7 @@ main() {
|
| yield x;
|
| x = await new Future.value(42);
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -69,6 +81,7 @@ main() {
|
| yield await i;
|
| }
|
| }
|
| +
|
| return expectList(f(), new List.generate(10, id));
|
| });
|
|
|
| @@ -76,6 +89,7 @@ main() {
|
| f() async* {
|
| yield* new Stream.fromIterable([1, 2, 3]);
|
| }
|
| +
|
| return expectList(f(), [1, 2, 3]);
|
| });
|
|
|
| @@ -86,6 +100,7 @@ main() {
|
| yield* f(n - 1);
|
| yield n;
|
| }
|
| +
|
| return expectList(f(3), [3, 2, 1, 0, 1, 2, 3]);
|
| });
|
|
|
| @@ -93,16 +108,18 @@ main() {
|
| f(s) async* {
|
| yield* s;
|
| }
|
| +
|
| return f(42).transform(getErrors).single.then((v) {
|
| // Not implementing Stream.
|
| expect(v is Error, isTrue);
|
| });
|
| });
|
|
|
| - test("Cannot yield* non-stream", () {
|
| + test("Cannot yield* non-stream", () {
|
| f(s) async* {
|
| yield* s;
|
| }
|
| +
|
| return f(new NotAStream()).transform(getErrors).single.then((v) {
|
| // Not implementing Stream.
|
| expect(v is Error, isTrue);
|
| @@ -115,13 +132,18 @@ main() {
|
| f() async* {
|
| yield 0;
|
| }
|
| +
|
| return expectList(f(), [0]);
|
| });
|
|
|
| test("if-then-else", () {
|
| f(b) async* {
|
| - if (b) yield 0; else yield 1;
|
| + if (b)
|
| + yield 0;
|
| + else
|
| + yield 1;
|
| }
|
| +
|
| return expectList(f(true), [0]).whenComplete(() {
|
| expectList(f(false), [1]);
|
| });
|
| @@ -130,16 +152,21 @@ main() {
|
| test("block", () {
|
| f() async* {
|
| yield 0;
|
| - { yield 1; }
|
| + {
|
| + yield 1;
|
| + }
|
| yield 2;
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]);
|
| });
|
|
|
| test("labeled", () {
|
| f() async* {
|
| - label1: yield 0;
|
| + label1:
|
| + yield 0;
|
| }
|
| +
|
| return expectList(f(), [0]);
|
| });
|
|
|
| @@ -147,6 +174,7 @@ main() {
|
| f() async* {
|
| for (int i = 0; i < 3; i++) yield i;
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]);
|
| });
|
|
|
| @@ -154,6 +182,7 @@ main() {
|
| f() async* {
|
| for (var i in [0, 1, 2]) yield i;
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]);
|
| });
|
|
|
| @@ -161,6 +190,7 @@ main() {
|
| f() async* {
|
| await for (var i in new Stream.fromIterable([0, 1, 2])) yield i;
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]);
|
| });
|
|
|
| @@ -169,6 +199,7 @@ main() {
|
| int i = 0;
|
| while (i < 3) yield i++;
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]);
|
| });
|
|
|
| @@ -177,20 +208,35 @@ main() {
|
| int i = 0;
|
| do yield i++; while (i < 3);
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]);
|
| });
|
|
|
| test("try-catch-finally", () {
|
| f() async* {
|
| - try { yield 0; } catch (e) { yield 1; } finally { yield 2; }
|
| + try {
|
| + yield 0;
|
| + } catch (e) {
|
| + yield 1;
|
| + } finally {
|
| + yield 2;
|
| + }
|
| }
|
| +
|
| return expectList(f(), [0, 2]);
|
| });
|
|
|
| test("try-catch-finally 2", () {
|
| f() async* {
|
| - try { yield throw 0; } catch (e) { yield 1; } finally { yield 2; }
|
| + try {
|
| + yield throw 0;
|
| + } catch (e) {
|
| + yield 1;
|
| + } finally {
|
| + yield 2;
|
| + }
|
| }
|
| +
|
| return expectList(f(), [1, 2]);
|
| });
|
|
|
| @@ -208,6 +254,7 @@ main() {
|
| yield 2;
|
| }
|
| }
|
| +
|
| return expectList(f(0), [0, 1]).whenComplete(() {
|
| return expectList(f(1), [1]);
|
| }).whenComplete(() {
|
| @@ -220,6 +267,7 @@ main() {
|
| return;
|
| yield 1;
|
| }
|
| +
|
| return expectList(f(), []);
|
| });
|
|
|
| @@ -230,6 +278,7 @@ main() {
|
| yield 1;
|
| } catch (_) {}
|
| }
|
| +
|
| return expectList(f(), []);
|
| });
|
|
|
| @@ -240,16 +289,19 @@ main() {
|
| yield 1;
|
| }
|
| }
|
| +
|
| return expectList(f(), []);
|
| });
|
|
|
| test("dead-code break 2", () {
|
| f() async* {
|
| - label: {
|
| + label:
|
| + {
|
| break label;
|
| yield 1;
|
| }
|
| }
|
| +
|
| return expectList(f(), []);
|
| });
|
|
|
| @@ -260,6 +312,7 @@ main() {
|
| yield 1;
|
| } while (false);
|
| }
|
| +
|
| return expectList(f(), []);
|
| });
|
| });
|
| @@ -270,6 +323,7 @@ main() {
|
| var x = 42;
|
| yield x;
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -278,6 +332,7 @@ main() {
|
| const x = 42;
|
| yield x;
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -286,6 +341,7 @@ main() {
|
| f() async* {
|
| yield g();
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -294,6 +350,7 @@ main() {
|
| var x = -42;
|
| yield -x;
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -302,6 +359,7 @@ main() {
|
| var x = 21;
|
| yield x + x;
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -310,6 +368,7 @@ main() {
|
| var x = 21;
|
| yield x == 21 ? x + x : x;
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -318,6 +377,7 @@ main() {
|
| var x = 42;
|
| yield x++;
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -326,6 +386,7 @@ main() {
|
| var x = 41;
|
| yield ++x;
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -334,6 +395,7 @@ main() {
|
| var x = 37;
|
| yield x = 42;
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -342,6 +404,7 @@ main() {
|
| var x = 41;
|
| yield x += 1;
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -349,6 +412,7 @@ main() {
|
| f() async* {
|
| yield await new Future.value(42);
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| @@ -357,14 +421,18 @@ main() {
|
| var x = [42];
|
| yield x[0];
|
| }
|
| +
|
| return expectList(f(), [42]);
|
| });
|
|
|
| test("function expression block", () {
|
| var o = new Object();
|
| f() async* {
|
| - yield () { return o; };
|
| + yield () {
|
| + return o;
|
| + };
|
| }
|
| +
|
| return f().first.then((v) {
|
| expect(v(), same(o));
|
| });
|
| @@ -375,6 +443,7 @@ main() {
|
| f() async* {
|
| yield () => o;
|
| }
|
| +
|
| return f().first.then((v) {
|
| expect(v(), same(o));
|
| });
|
| @@ -383,8 +452,11 @@ main() {
|
| test("function expression block async", () {
|
| var o = new Object();
|
| f() async* {
|
| - yield () async { return o; };
|
| + yield () async {
|
| + return o;
|
| + };
|
| }
|
| +
|
| return f().first.then((v) => v()).then((v) {
|
| expect(v, same(o));
|
| });
|
| @@ -395,6 +467,7 @@ main() {
|
| f() async* {
|
| yield () async => o;
|
| }
|
| +
|
| return f().first.then((v) => v()).then((v) {
|
| expect(v, same(o));
|
| });
|
| @@ -403,8 +476,11 @@ main() {
|
| test("function expression block async*", () {
|
| var o = new Object();
|
| f() async* {
|
| - yield () async* { yield o; };
|
| + yield () async* {
|
| + yield o;
|
| + };
|
| }
|
| +
|
| return f().first.then((v) => v().first).then((v) {
|
| expect(v, same(o));
|
| });
|
| @@ -418,6 +494,7 @@ main() {
|
| yield i;
|
| }
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]);
|
| });
|
|
|
| @@ -429,6 +506,7 @@ main() {
|
| }
|
| }
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2, 3, 4, 5]);
|
| });
|
|
|
| @@ -443,6 +521,7 @@ main() {
|
| }
|
| }
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]).whenComplete(() {
|
| expect(list, equals(["0", "1", "2"]));
|
| });
|
| @@ -461,6 +540,7 @@ main() {
|
| }
|
| }
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]).whenComplete(() {
|
| expect(list, equals(["0", "1", "2"]));
|
| });
|
| @@ -479,6 +559,7 @@ main() {
|
| }
|
| }
|
| }
|
| +
|
| return expectList(f(), [0, 1, 2]).whenComplete(() {
|
| expect(list, equals(["0", "1", "2"]));
|
| });
|
| @@ -494,6 +575,7 @@ main() {
|
| }
|
| }
|
| }
|
| +
|
| return expectList(f().take(3), [0, 1, 2]);
|
| });
|
| });
|
| @@ -513,9 +595,13 @@ main() {
|
| exits.complete(3);
|
| }
|
| }
|
| +
|
| // No events must be fired synchronously in response to a listen.
|
| - var subscription = f().listen((v) { fail("Received event $v"); },
|
| - onDone: () { fail("Received done"); });
|
| + var subscription = f().listen((v) {
|
| + fail("Received event $v");
|
| + }, onDone: () {
|
| + fail("Received done");
|
| + });
|
| // No events must be delivered after a cancel.
|
| subscription.cancel();
|
| return exits.future.then((v) {
|
| @@ -536,12 +622,13 @@ main() {
|
| exits.complete(i);
|
| }
|
| }
|
| +
|
| return expectList(f().take(5), [0, 1, 2, 3, 4])
|
| .then((_) => exits.future)
|
| .then((v) {
|
| - expect(v, greaterThan(4));
|
| - expect(list, ["a"]);
|
| - });
|
| + expect(v, greaterThan(4));
|
| + expect(list, ["a"]);
|
| + });
|
| });
|
|
|
| group("at index", () {
|
| @@ -556,6 +643,7 @@ main() {
|
| }
|
| }
|
| }
|
| +
|
| test("- all, sanity check", () {
|
| return expectList(f(), [1, 2, 3]);
|
| });
|
| @@ -587,6 +675,7 @@ main() {
|
| yield 4;
|
| list.add(5);
|
| }
|
| +
|
| var done = new Completer();
|
| var sub = f().listen((v) {
|
| if (v == 2) {
|
| @@ -612,6 +701,7 @@ main() {
|
| yield 4;
|
| list.add(5);
|
| }
|
| +
|
| var done = new Completer();
|
| var sub;
|
| sub = f().listen((v) {
|
| @@ -644,6 +734,7 @@ main() {
|
| i++;
|
| }
|
| }
|
| +
|
| int expected = 0;
|
| var done = new Completer();
|
| var sub;
|
| @@ -672,9 +763,10 @@ main() {
|
| test("simple stream", () {
|
| f(s) async {
|
| var r = 0;
|
| - await for(var v in s) r += v;
|
| + await for (var v in s) r += v;
|
| return r;
|
| }
|
| +
|
| return f(mkStream(5)).then((v) {
|
| expect(v, equals(10));
|
| });
|
| @@ -683,9 +775,10 @@ main() {
|
| test("simple stream, await", () {
|
| f(s) async {
|
| var r = 0;
|
| - await for(var v in s) r += await new Future.microtask(() => v);
|
| + await for (var v in s) r += await new Future.microtask(() => v);
|
| return r;
|
| }
|
| +
|
| return f(mkStream(5)).then((v) {
|
| expect(v, equals(10));
|
| });
|
| @@ -694,16 +787,18 @@ main() {
|
| test("simple stream reyield", () {
|
| f(s) async* {
|
| var r = 0;
|
| - await for(var v in s) yield r += v;
|
| + await for (var v in s) yield r += v;
|
| }
|
| +
|
| return expectList(f(mkStream(5)), [0, 1, 3, 6, 10]);
|
| });
|
|
|
| test("simple stream, await, reyield", () {
|
| f(s) async* {
|
| var r = 0;
|
| - await for(var v in s) yield r += await new Future.microtask(() => v);
|
| + await for (var v in s) yield r += await new Future.microtask(() => v);
|
| }
|
| +
|
| return expectList(f(mkStream(5)), [0, 1, 3, 6, 10]);
|
| });
|
|
|
| @@ -717,6 +812,7 @@ main() {
|
| }
|
| return r;
|
| }
|
| +
|
| return f().then((v) {
|
| expect(v, equals((1 + 2 + 3 + 4) * (1 + 2)));
|
| });
|
| @@ -732,6 +828,7 @@ main() {
|
| }
|
| return r;
|
| }
|
| +
|
| return f().then((v) {
|
| expect(v, equals((1 + 2 + 3 + 4) * (1 + 2)));
|
| });
|
| @@ -748,6 +845,7 @@ main() {
|
| }
|
| return r;
|
| }
|
| +
|
| return f().then((v) {
|
| expect(v, equals((1 + 2 + 3 + 4) * (1 + 2)));
|
| });
|
| @@ -773,10 +871,13 @@ expectList(stream, list) {
|
|
|
| const MS = const Duration(milliseconds: 1);
|
|
|
| -var getErrors = new StreamTransformer.fromHandlers(
|
| - handleData:(data, sink) { fail("Unexpected value"); },
|
| - handleError: (e, s, sink) { sink.add(e); },
|
| - handleDone: (sink) { sink.close(); });
|
| +var getErrors = new StreamTransformer.fromHandlers(handleData: (data, sink) {
|
| + fail("Unexpected value");
|
| +}, handleError: (e, s, sink) {
|
| + sink.add(e);
|
| +}, handleDone: (sink) {
|
| + sink.close();
|
| +});
|
|
|
| class NotAStream {
|
| listen(oData, {onError, onDone, cancelOnError}) {
|
|
|