// 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 elements in [ new Set(), [], const [], const {}.keys, const {}.values, new Iterable.generate(0), new Set()..add(1)..add(2)..add(4), [1, 2, 4], new Iterable.generate(3, (i) => [1, 2, 4][i]), const [1, 2, 4], const {1: 0, 2: 0, 4: 0}.keys, const {1: 1, 2: 2, 4: 4}.values, ]) { int elementCount = elements.length; check(elements, new List.from(elements)); check(elements, new List.from(elements)); check(elements, new List.from(elements)); check(elements, new List.from(elements, growable: true)); check(elements, new List.from(elements, growable: true)); check(elements, new List.from(elements, growable: true)); check(elements, new List.from(elements, growable: false)); check(elements, new List.from(elements, growable: false)); check(elements, new List.from(elements, growable: false)); check(elements, new Queue.from(elements)); check(elements, new Queue.from(elements)); check(elements, new Queue.from(elements)); check(elements, new ListQueue.from(elements)); check(elements, new ListQueue.from(elements)); check(elements, new ListQueue.from(elements)); check(elements, new DoubleLinkedQueue.from(elements)); check(elements, new DoubleLinkedQueue.from(elements)); check(elements, new DoubleLinkedQueue.from(elements)); check(elements, new Set.from(elements)); check(elements, new Set.from(elements)); check(elements, new Set.from(elements)); check(elements, new HashSet.from(elements)); check(elements, new HashSet.from(elements)); check(elements, new HashSet.from(elements)); check(elements, new LinkedHashSet.from(elements)); check(elements, new LinkedHashSet.from(elements)); check(elements, new LinkedHashSet.from(elements)); check(elements, new SplayTreeSet.from(elements)); check(elements, new SplayTreeSet.from(elements)); check(elements, new SplayTreeSet.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.from(elements, growable: true); Expect.equals(elementCount, list.length); list.add(42); Expect.equals(elementCount + 1, list.length); } { var list = new List.from(elements); Expect.equals(elementCount, list.length); list.add(42); Expect.equals(elementCount + 1, list.length); } { var list = new List.from(elements, growable: false); Expect.equals(elementCount, list.length); Expect.throwsUnsupportedError(() { list.add(42); }); Expect.equals(elementCount, list.length); } } } void check(Iterable 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); } }