dart-sdk/tests/language/spread_collections/runtime_error_test.dart
Robert Nystrom 1951879d70 Migrate language_2/spread_collections to NNBD.
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>
2020-06-17 22:31:04 +00:00

35 lines
1.3 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:expect/expect.dart';
// Typed as dynamic to also test spreading a value of type dynamic.
final dynamic list = [1, 2, 3, 4];
final dynamic map = {1: 1, 2: 2, 3: 3, 4: 4};
final dynamic set = {1, 2, 3, 4};
void main() {
dynamic nonIterable = 3;
Expect.throwsTypeError(() => <int>[...nonIterable]);
Expect.throwsTypeError(() => <int>{...nonIterable});
dynamic nonMap = 3;
Expect.throwsTypeError(() => <int, int>{...nonMap});
dynamic wrongIterableType = <String>["s"];
Expect.throwsTypeError(() => <int>[...wrongIterableType]);
Expect.throwsTypeError(() => <int>{...wrongIterableType});
dynamic wrongKeyType = <String, int>{"s": 1};
dynamic wrongValueType = <int, String>{1: "s"};
Expect.throwsTypeError(() => <int, int>{...wrongKeyType});
Expect.throwsTypeError(() => <int, int>{...wrongValueType});
// Mismatched collection types.
Expect.throwsTypeError(() => <int>[...map]);
Expect.throwsTypeError(() => <int, int>{...list});
Expect.throwsTypeError(() => <int, int>{...set});
Expect.throwsTypeError(() => <int>{...map});
}