Files
sdk/tests/language_2/spread_collections/bind_test.dart
T
Anna Gringauze 33274b6fae [dartdevc] removed unnecessary '.bind(this)' + added doc comments.
Bug https://github.com/dart-lang/sdk/issues/38896

Change-Id: If5399c19c178e7b379d7827bde1277c2bf18062e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123470
Commit-Queue: Anna Gringauze <annagrin@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2019-10-30 18:18:01 +00:00

88 lines
2.0 KiB
Dart

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Check that spread collections can be used in combination with async/await features.
/// This is a regression test for http://dartbug.com/38896
import "package:async_helper/async_helper.dart";
import 'package:expect/expect.dart';
Future<void> asyncTest1(Future<void> f()) {
asyncStart();
return f().then(asyncSuccess);
}
void main() {
asyncTest1(() async {
await awaitSpreadMemberCallBindTest(); // A
await yieldSpreadMemberCallBindTest(); // C
await spreadAwaitMemberCallBindTest(); // G
await spreadAwaitMemberAccessBindTest(); // I
});
}
class A {
List<int> m1() => [1, 2];
Future<List<int>> run() async {
return [await null, ...m1()];
}
}
Future<void> awaitSpreadMemberCallBindTest() async {
// spread on member call in await
Expect.listEquals([null, 1, 2], await A().run());
}
class C {
List<int> m2() => [1, 2];
Future<List<int>> run() async {
return await run3().toList();
}
Stream<int> run3() async* {
for (var k in [...await m2()]) yield k;
}
}
Future<void> yieldSpreadMemberCallBindTest() async {
var expected = [1, 2];
// spread on await of member call with yield
Expect.listEquals(expected, await C().run());
}
class G {
List<int> m2() => [1, 2];
Future<List<int>> run() async {
return [...await m2()];
}
}
Future<void> spreadAwaitMemberCallBindTest() async {
var expected = [1, 2];
// spread on await of member call
Expect.listEquals(expected, await G().run());
}
class I1 {
List<int> foo() => [1, 2];
}
class I {
I1 b = I1();
Future<List<int>> run() async {
return [...await b.foo()];
}
}
Future<void> spreadAwaitMemberAccessBindTest() async {
var expected = [1, 2];
// spread on await of member access
Expect.listEquals(expected, await I().run());
}