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>
61 lines
1.8 KiB
Dart
61 lines
1.8 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.
|
|
|
|
import "package:async_helper/async_helper.dart";
|
|
import 'package:expect/expect.dart';
|
|
|
|
final list = [1, 2, 3, 4, 5];
|
|
final map = {1: 1, 2: 2, 3: 3, 4: 4, 5: 5};
|
|
final set = {1, 2, 3, 4, 5};
|
|
|
|
void main() {
|
|
asyncTest(() async {
|
|
await testList();
|
|
await testMap();
|
|
await testSet();
|
|
});
|
|
}
|
|
|
|
Future<void> testList() async {
|
|
var future12 = Future.value([1, 2]);
|
|
var future45 = Future.value([4, 5]);
|
|
var nullableFuture12 = Future<List<int>?>.value([1, 2]);
|
|
var futureNull = Future.value(null);
|
|
|
|
// Await in spread.
|
|
Expect.listEquals(list, [...await future12, 3, ...await future45]);
|
|
|
|
// Await in null-aware spread.
|
|
Expect.listEquals(
|
|
list, [...?await nullableFuture12, 3, ...?await futureNull, 4, 5]);
|
|
}
|
|
|
|
Future<void> testMap() async {
|
|
var future12 = Future.value({1: 1, 2: 2});
|
|
var future45 = Future.value({4: 4, 5: 5});
|
|
var nullableFuture12 = Future<Map<int, int>?>.value({1: 1, 2: 2});
|
|
var futureNull = Future.value(null);
|
|
|
|
// Await in spread.
|
|
Expect.mapEquals(map, {...await future12, 3: 3, ...await future45});
|
|
|
|
// Await in null-aware spread.
|
|
Expect.mapEquals(map,
|
|
{...?await nullableFuture12, 3: 3, ...?await futureNull, 4: 4, 5: 5});
|
|
}
|
|
|
|
Future<void> testSet() async {
|
|
var future12 = Future.value([1, 2]);
|
|
var future45 = Future.value([4, 5]);
|
|
var nullableFuture12 = Future<List<int>?>.value([1, 2]);
|
|
var futureNull = Future.value(null);
|
|
|
|
// Await in spread.
|
|
Expect.setEquals(set, {...await future12, 3, ...await future45});
|
|
|
|
// Await in null-aware spread.
|
|
Expect.setEquals(
|
|
set, {...?await nullableFuture12, 3, ...?await futureNull, 4, 5});
|
|
}
|