dart-sdk/tests/web/42531_test.dart
Sigmund Cherem 912005267d [web] rename suite dart2js -> web.
Change-Id: I46be49b2effec3e38a3dc44cd45cfe736f77fa78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182680
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2021-02-04 23:11:32 +00:00

47 lines
1.5 KiB
Dart

// Copyright (c) 2020, 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:expect/expect.dart';
// Regression test for badly named generator body.
Future<void> goo(Future Function() f) async {
Expect.equals(102, (await f()).keys.single);
Expect.equals(104, (await f()).keys.single);
}
Future<T> identity<T>(T x) async => x;
extension Gloop<T> on Map<T, List<T>> {
// An async method using a 'complex' generator type `Map<T, List<T>>`. This
// requires a separated entry and body, which requires a name, and the name
// must be legal JavaScript.
Future<Map<T, List<T>>> foo(int x) async {
var result = await identity({(x += this.length) as T: <T>[]});
return result;
}
Future<int> bar(int x) async {
// An async closure using a 'complex' generator type `Map<T, Set<T>>`. This
// requires a separated entry and body, which requires a name, and the name
// must be legal JavaScript.
await goo(() async => {(x += this.length) as T: <T>{}});
return x;
}
}
main() async {
// Test method.
Map<int, List<int>> o1 = {1: [], 2: []};
var o2 = await o1.foo(100);
var o3 = await o2.foo(100);
Expect.equals('{102: []}', '$o2');
Expect.equals('{101: []}', '$o3');
// Test closure.
Map<int, List<int>> o = {1: [], 2: []};
int x = await o.bar(100);
Expect.equals(104, x);
}