Index: tests/language_strong/async_star_test.dart |
diff --git a/tests/language_strong/async_star_test.dart b/tests/language_strong/async_star_test.dart |
index ce0528dbb46633007aa61979dbfa3cb1115ad145..be6921ef7c31f5b8ab8a6a55234750ec99642cb1 100644 |
--- a/tests/language_strong/async_star_test.dart |
+++ b/tests/language_strong/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; |
+ } |
+ |
// TODO(jmesserly): use tear off. For now this is a workaround for: |
// https://github.com/dart-lang/dev_compiler/issues/269 |
var res = f().forEach((x) => list.add(x)); |
@@ -36,14 +43,17 @@ main() { |
}); |
test("throws", () { |
- f() async* { yield 1; throw 2; } |
+ f() async* { |
+ yield 1; |
+ throw 2; |
+ } |
+ |
var completer = new Completer(); |
var list = []; |
// TODO(jmesserly): use tear off. For now this is a workaround for: |
// https://github.com/dart-lang/dev_compiler/issues/269 |
f().listen((x) => list.add(x), |
- 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"])); |
}); |
@@ -55,6 +65,7 @@ main() { |
yield i; |
} |
} |
+ |
return expectList(f(), new List.generate(10, id)); |
}); |
@@ -64,6 +75,7 @@ main() { |
yield x; |
x = await new Future.value(42); |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -73,6 +85,7 @@ main() { |
yield await i; |
} |
} |
+ |
return expectList(f(), new List.generate(10, id)); |
}); |
@@ -80,6 +93,7 @@ main() { |
f() async* { |
yield* new Stream.fromIterable([1, 2, 3]); |
} |
+ |
return expectList(f(), [1, 2, 3]); |
}); |
@@ -90,6 +104,7 @@ main() { |
yield* f(n - 1); |
yield n; |
} |
+ |
return expectList(f(3), [3, 2, 1, 0, 1, 2, 3]); |
}); |
@@ -97,16 +112,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); |
@@ -119,13 +136,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]); |
}); |
@@ -134,16 +156,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]); |
}); |
@@ -159,6 +186,7 @@ main() { |
f() async* { |
for (int i = 0; i < 3; i++) yield i; |
} |
+ |
return expectList(f(), [0, 1, 2]); |
}); |
@@ -166,6 +194,7 @@ main() { |
f() async* { |
for (var i in [0, 1, 2]) yield i; |
} |
+ |
return expectList(f(), [0, 1, 2]); |
}); |
@@ -173,6 +202,7 @@ main() { |
f() async* { |
await for (var i in new Stream.fromIterable([0, 1, 2])) yield i; |
} |
+ |
return expectList(f(), [0, 1, 2]); |
}); |
@@ -181,6 +211,7 @@ main() { |
int i = 0; |
while (i < 3) yield i++; |
} |
+ |
return expectList(f(), [0, 1, 2]); |
}); |
@@ -189,20 +220,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]); |
}); |
@@ -234,6 +280,7 @@ main() { |
return; |
yield 1; |
} |
+ |
return expectList(f(), []); |
}); |
@@ -244,6 +291,7 @@ main() { |
yield 1; |
} catch (_) {} |
} |
+ |
return expectList(f(), []); |
}); |
@@ -254,16 +302,19 @@ main() { |
yield 1; |
} |
} |
+ |
return expectList(f(), []); |
}); |
test("dead-code break 2", () { |
f() async* { |
- label: { |
+ label: |
+ { |
break label; |
yield 1; |
} |
} |
+ |
return expectList(f(), []); |
}); |
@@ -274,6 +325,7 @@ main() { |
yield 1; |
} while (false); |
} |
+ |
return expectList(f(), []); |
}); |
}); |
@@ -284,6 +336,7 @@ main() { |
var x = 42; |
yield x; |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -292,6 +345,7 @@ main() { |
const x = 42; |
yield x; |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -300,6 +354,7 @@ main() { |
f() async* { |
yield g(); |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -308,6 +363,7 @@ main() { |
var x = -42; |
yield -x; |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -316,6 +372,7 @@ main() { |
var x = 21; |
yield x + x; |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -324,6 +381,7 @@ main() { |
var x = 21; |
yield x == 21 ? x + x : x; |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -332,6 +390,7 @@ main() { |
var x = 42; |
yield x++; |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -340,6 +399,7 @@ main() { |
var x = 41; |
yield ++x; |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -348,6 +408,7 @@ main() { |
var x = 37; |
yield x = 42; |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -356,6 +417,7 @@ main() { |
var x = 41; |
yield x += 1; |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -363,6 +425,7 @@ main() { |
f() async* { |
yield await new Future.value(42); |
} |
+ |
return expectList(f(), [42]); |
}); |
@@ -371,14 +434,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)); |
}); |
@@ -389,6 +456,7 @@ main() { |
f() async* { |
yield () => o; |
} |
+ |
return f().first.then((v) { |
expect(v(), same(o)); |
}); |
@@ -397,8 +465,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)); |
}); |
@@ -409,6 +480,7 @@ main() { |
f() async* { |
yield () async => o; |
} |
+ |
return f().first.then((v) => v()).then((v) { |
expect(v, same(o)); |
}); |
@@ -417,8 +489,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)); |
}); |
@@ -432,6 +507,7 @@ main() { |
yield i; |
} |
} |
+ |
return expectList(f(), [0, 1, 2]); |
}); |
@@ -443,6 +519,7 @@ main() { |
} |
} |
} |
+ |
return expectList(f(), [0, 1, 2, 3, 4, 5]); |
}); |
@@ -457,6 +534,7 @@ main() { |
} |
} |
} |
+ |
return expectList(f(), [0, 1, 2]).whenComplete(() { |
expect(list, equals(["0", "1", "2"])); |
}); |
@@ -475,6 +553,7 @@ main() { |
} |
} |
} |
+ |
return expectList(f(), [0, 1, 2]).whenComplete(() { |
expect(list, equals(["0", "1", "2"])); |
}); |
@@ -493,6 +572,7 @@ main() { |
} |
} |
} |
+ |
return expectList(f(), [0, 1, 2]).whenComplete(() { |
expect(list, equals(["0", "1", "2"])); |
}); |
@@ -508,6 +588,7 @@ main() { |
} |
} |
} |
+ |
return expectList(f().take(3), [0, 1, 2]); |
}); |
}); |
@@ -527,9 +608,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) { |
@@ -550,12 +635,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", () { |
@@ -570,6 +656,7 @@ main() { |
} |
} |
} |
+ |
test("- all, sanity check", () { |
return expectList(f(), [1, 2, 3]); |
}); |
@@ -621,7 +708,6 @@ main() { |
// "fisk 1", "+fisk", 0, "done", "-fisk", ]); |
// }); |
// }); |
- |
}); |
group("pausing", () { |
@@ -634,6 +720,7 @@ main() { |
yield 4; |
list.add(5); |
} |
+ |
var done = new Completer(); |
var sub = f().listen((v) { |
if (v == 2) { |
@@ -659,6 +746,7 @@ main() { |
yield 4; |
list.add(5); |
} |
+ |
var done = new Completer(); |
var sub; |
sub = f().listen((v) { |
@@ -691,6 +779,7 @@ main() { |
i++; |
} |
} |
+ |
int expected = 0; |
var done = new Completer(); |
var sub; |
@@ -723,8 +812,8 @@ main() { |
list.add("*3"); // //# 02: continued |
}; // //# 02: continued |
var stream = f(); // //# 02: continued |
- // TODO(jmesserly): added workaround for: |
- // https://github.com/dart-lang/dev_compiler/issues/269 |
+ // TODO(jmesserly): added workaround for: |
+ // https://github.com/dart-lang/dev_compiler/issues/269 |
var sub = stream.listen((x) => list.add(x)); // //# 02: continued |
return sync.wait().whenComplete(() { // //# 02: continued |
expect(list, equals(["*1", 1])); // //# 02: continued |
@@ -749,9 +838,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)); |
}); |
@@ -760,9 +850,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)); |
}); |
@@ -782,16 +873,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]); |
}); |
@@ -813,6 +906,7 @@ main() { |
} |
return r; |
} |
+ |
return f().then((v) { |
expect(v, equals((1 + 2 + 3 + 4) * (1 + 2))); |
}); |
@@ -828,6 +922,7 @@ main() { |
} |
return r; |
} |
+ |
return f().then((v) { |
expect(v, equals((1 + 2 + 3 + 4) * (1 + 2))); |
}); |
@@ -844,6 +939,7 @@ main() { |
} |
return r; |
} |
+ |
return f().then((v) { |
expect(v, equals((1 + 2 + 3 + 4) * (1 + 2))); |
}); |
@@ -892,10 +988,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}) { |