// Copyright (c) 2018, 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, ]) { String sourceType = elements.runtimeType.toString(); check(sourceType, elements, new List.of(elements)); check(sourceType, elements, new List.of(elements)); check(sourceType, elements, new Queue.of(elements)); check(sourceType, elements, new Queue.of(elements)); check(sourceType, elements, new ListQueue.of(elements)); check(sourceType, elements, new ListQueue.of(elements)); check(sourceType, elements, new DoubleLinkedQueue.of(elements)); check(sourceType, elements, new DoubleLinkedQueue.of(elements)); check(sourceType, elements, new Set.of(elements)); check(sourceType, elements, new Set.of(elements)); check(sourceType, elements, new HashSet.of(elements)); check(sourceType, elements, new HashSet.of(elements)); check(sourceType, elements, new LinkedHashSet.of(elements)); check(sourceType, elements, new LinkedHashSet.of(elements)); check(sourceType, elements, new SplayTreeSet.of(elements)); check(sourceType, elements, new SplayTreeSet.of(elements)); // Inference applies to the `of` constructor, unlike the `from` constructor. Expect.isTrue(new List.of(elements) is Iterable); Expect.isTrue(new Queue.of(elements) is Iterable); Expect.isTrue(new ListQueue.of(elements) is Iterable); Expect.isTrue(new DoubleLinkedQueue.of(elements) is Iterable); Expect.isTrue(new Set.of(elements) is Iterable); Expect.isTrue(new HashSet.of(elements) is Iterable); Expect.isTrue(new LinkedHashSet.of(elements) is Iterable); Expect.isTrue(new SplayTreeSet.of(elements) is Iterable); Expect.isTrue(new List.of(elements) is! Iterable); Expect.isTrue(new Queue.of(elements) is! Iterable); Expect.isTrue(new ListQueue.of(elements) is! Iterable); Expect.isTrue(new DoubleLinkedQueue.of(elements) is! Iterable); Expect.isTrue(new Set.of(elements) is! Iterable); Expect.isTrue(new HashSet.of(elements) is! Iterable); Expect.isTrue(new LinkedHashSet.of(elements) is! Iterable); Expect.isTrue(new SplayTreeSet.of(elements) is! Iterable); } } void check(String sourceType, Iterable source, Iterable target) { String targetType = target.runtimeType.toString(); String name = "$sourceType->$targetType"; Expect.equals(source.length, target.length, "$name.length"); for (var element in target) { Expect.isTrue(source.contains(element), "$name:$element in source"); } for (var element in source) { Expect.isTrue(target.contains(element), "$name:$element in target"); } }