mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 15:17:07 +00:00
a4d799c402
Note that cast_test.dart isn't migrated yet due to #39517. First patch set is just copying the tests over. The second patchset has the actual meaningful changes. Change-Id: I89233f20187b4305a776f865cde09a984423fa4f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125920 Commit-Queue: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com>
93 lines
3.5 KiB
Dart
93 lines
3.5 KiB
Dart
// Copyright (c) 2011, 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.
|
|
|
|
library collection.from.test;
|
|
|
|
import "package:expect/expect.dart";
|
|
import 'dart:collection';
|
|
|
|
main() {
|
|
for (Iterable<num> elements in [
|
|
new Set<num>(),
|
|
<num>[],
|
|
const <num>[],
|
|
const <num, int>{}.keys,
|
|
const <int, num>{}.values,
|
|
new Iterable<num>.generate(0),
|
|
new Set<num>()..add(1)..add(2)..add(4),
|
|
<num>[1, 2, 4],
|
|
new Iterable<num>.generate(3, (i) => [1, 2, 4][i]),
|
|
const <num>[1, 2, 4],
|
|
const <num, int>{1: 0, 2: 0, 4: 0}.keys,
|
|
const <int, num>{1: 1, 2: 2, 4: 4}.values,
|
|
]) {
|
|
int elementCount = elements.length;
|
|
check(elements, new List<num>.from(elements));
|
|
check(elements, new List<int>.from(elements));
|
|
check(elements, new List<Object>.from(elements));
|
|
check(elements, new List<num>.from(elements, growable: true));
|
|
check(elements, new List<int>.from(elements, growable: true));
|
|
check(elements, new List<Object>.from(elements, growable: true));
|
|
check(elements, new List<num>.from(elements, growable: false));
|
|
check(elements, new List<int>.from(elements, growable: false));
|
|
check(elements, new List<Object>.from(elements, growable: false));
|
|
check(elements, new Queue<num>.from(elements));
|
|
check(elements, new Queue<int>.from(elements));
|
|
check(elements, new Queue<Object>.from(elements));
|
|
check(elements, new ListQueue<num>.from(elements));
|
|
check(elements, new ListQueue<int>.from(elements));
|
|
check(elements, new ListQueue<Object>.from(elements));
|
|
check(elements, new DoubleLinkedQueue<num>.from(elements));
|
|
check(elements, new DoubleLinkedQueue<int>.from(elements));
|
|
check(elements, new DoubleLinkedQueue<Object>.from(elements));
|
|
check(elements, new Set<num>.from(elements));
|
|
check(elements, new Set<int>.from(elements));
|
|
check(elements, new Set<Object>.from(elements));
|
|
check(elements, new HashSet<num>.from(elements));
|
|
check(elements, new HashSet<int>.from(elements));
|
|
check(elements, new HashSet<Object>.from(elements));
|
|
check(elements, new LinkedHashSet<num>.from(elements));
|
|
check(elements, new LinkedHashSet<int>.from(elements));
|
|
check(elements, new LinkedHashSet<Object>.from(elements));
|
|
check(elements, new SplayTreeSet<num>.from(elements));
|
|
check(elements, new SplayTreeSet<int>.from(elements));
|
|
check(elements, new SplayTreeSet<Object>.from(elements));
|
|
// Sanity check that elements didn't change.
|
|
Expect.equals(elementCount, elements.length);
|
|
|
|
// Lists may be growable or not growable.
|
|
{
|
|
var list = new List<num>.from(elements, growable: true);
|
|
Expect.equals(elementCount, list.length);
|
|
list.add(42);
|
|
Expect.equals(elementCount + 1, list.length);
|
|
}
|
|
{
|
|
var list = new List<num>.from(elements);
|
|
Expect.equals(elementCount, list.length);
|
|
list.add(42);
|
|
Expect.equals(elementCount + 1, list.length);
|
|
}
|
|
{
|
|
var list = new List<num>.from(elements, growable: false);
|
|
Expect.equals(elementCount, list.length);
|
|
Expect.throwsUnsupportedError(() {
|
|
list.add(42);
|
|
});
|
|
Expect.equals(elementCount, list.length);
|
|
}
|
|
}
|
|
}
|
|
|
|
void check(Iterable<num> initial, Iterable other) {
|
|
Expect.equals(initial.length, other.length);
|
|
|
|
for (var element in other) {
|
|
initial.contains(element);
|
|
}
|
|
|
|
for (var element in initial) {
|
|
other.contains(element);
|
|
}
|
|
}
|