mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:37:12 +00:00
1951879d70
Change-Id: Iec6318773d2d8d33832951a61b2d4df54027662d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151048 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
88 lines
2 KiB
Dart
88 lines
2 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());
|
|
}
|