Migrate test block 11 to Dart 2.0.

Interesting items in this block:
- Manually merged iterable_generate_test changes from both trees and
dropped some typeAssertionsEnabled/checked mode checking.

BUG=
R=bkonyi@google.com

Review-Url: https://codereview.chromium.org/3000543002 .
This commit is contained in:
Janice Collins 2017-08-16 10:16:37 -07:00
parent 1f2844c992
commit e89d0d2e14
26 changed files with 62 additions and 1037 deletions

View file

@ -15,8 +15,6 @@ string_trimlr_test/02: RuntimeError # Uses Unicode 6.2.0 or earlier.
[ $compiler == dart2js && ! $dart2js_with_kernel ]
error_stack_trace1_test: RuntimeError # Issue 12399
iterable_return_type_test/01: RuntimeError # Issue 20085
iterable_return_type_test/02: RuntimeError # Dart2js does not support Uint64*.
big_integer_*: Skip # VM specific test.
compare_to2_test: RuntimeError, OK # Requires bigint support.
@ -64,7 +62,6 @@ string_from_environment3_test/03: MissingCompileTimeError
string_from_environment3_test/04: MissingCompileTimeError
string_from_environment3_test/05: MissingCompileTimeError
[ $compiler == dart2js && $dart2js_with_kernel && $host_checked ]
big_integer_parsed_div_rem_vm_test: RuntimeError
big_integer_parsed_mul_div_vm_test: RuntimeError
@ -100,20 +97,6 @@ for_in_test: Crash
growable_list_test: Crash
has_next_iterator_test: Crash
hash_map2_test: Crash
iterable_generate_test/01: Crash
iterable_generate_test/none: Crash
iterable_join_test: Crash
iterable_last_test: Crash
iterable_last_where_test: Crash
iterable_length_test: Crash
iterable_mapping_test: Crash
iterable_reduce_test: Crash
iterable_return_type_test/01: Crash
iterable_return_type_test/02: Crash
iterable_return_type_test/none: Crash
iterable_single_test: Crash
iterable_single_where_test: Crash
iterable_skip_test: Crash
iterable_skip_while_test: Crash
iterable_take_test: Crash
iterable_take_while_test: Crash
@ -241,20 +224,6 @@ iterable_expand_test: Crash
iterable_first_test: Crash
iterable_first_where_test: Crash
iterable_fold_test: Crash
iterable_generate_test/01: Crash
iterable_generate_test/none: Crash
iterable_join_test: Crash
iterable_last_test: Crash
iterable_last_where_test: Crash
iterable_length_test: Crash
iterable_mapping_test: Crash
iterable_reduce_test: Crash
iterable_return_type_test/01: Crash
iterable_return_type_test/02: Crash
iterable_return_type_test/none: Crash
iterable_single_test: Crash
iterable_single_where_test: Crash
iterable_skip_test: Crash
iterable_skip_while_test: Crash
iterable_take_test: Crash
iterable_take_while_test: Crash
@ -347,5 +316,4 @@ symbol_reserved_word_test/06: Crash
symbol_reserved_word_test/07: MissingCompileTimeError
symbol_reserved_word_test/09: Crash
symbol_reserved_word_test/10: MissingCompileTimeError
symbol_reserved_word_test/12: Crash
symbol_reserved_word_test/12: Crash

View file

@ -1,148 +0,0 @@
// Copyright (c) 2012, 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";
class IC {
int count = 0;
String toString() => "${count++}";
}
testJoin(String expect, Iterable iterable, [String separator]) {
if (separator != null) {
Expect.equals(expect, iterable.join(separator));
} else {
Expect.equals(expect, iterable.join());
}
}
testCollections() {
testJoin("", [], ",");
testJoin("", [], "");
testJoin("", []);
testJoin("", new Set(), ",");
testJoin("", new Set(), "");
testJoin("", new Set());
testJoin("42", [42], ",");
testJoin("42", [42], "");
testJoin("42", [42]);
testJoin("42", new Set()..add(42), ",");
testJoin("42", new Set()..add(42), "");
testJoin("42", new Set()..add(42));
testJoin("a,b,c,d", ["a", "b", "c", "d"], ",");
testJoin("abcd", ["a", "b", "c", "d"], "");
testJoin("abcd", ["a", "b", "c", "d"]);
testJoin("null,b,c,d", [null, "b", "c", "d"], ",");
testJoin("1,2,3,4", [1, 2, 3, 4], ",");
var ic = new IC();
testJoin("0,1,2,3", [ic, ic, ic, ic], ",");
var set = new Set()..add(1)..add(2)..add(3);
var perm = new Set()
..add("123")
..add("132")
..add("213")
..add("231")
..add("312")
..add("321");
var setString = set.join();
Expect.isTrue(perm.contains(setString), "set: $setString");
void testArray(array) {
testJoin("1,3,5,7,9", array.where((i) => i.isOdd), ",");
testJoin("0,2,4,6,8,10,12,14,16,18", array.map((i) => i * 2), ",");
testJoin("5,6,7,8,9", array.skip(5), ",");
testJoin("5,6,7,8,9", array.skipWhile((i) => i < 5), ",");
testJoin("0,1,2,3,4", array.take(5), ",");
testJoin("0,1,2,3,4", array.takeWhile((i) => i < 5), ",");
}
testArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
var fixedArray = new List(10);
for (int i = 0; i < 10; i++) {
fixedArray[i] = i;
}
testArray(fixedArray);
testArray(const [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
testJoin("a,b,c,d", ["a", "b", "c", "d"].map((x) => x), ",");
testJoin("abcd", ["a", "b", "c", "d"].map((x) => x), "");
testJoin("abcd", ["a", "b", "c", "d"].map((x) => x));
testJoin("null,b,c,d", [null, "b", "c", "d"].map((x) => x), ",");
testJoin("1,2,3,4", [1, 2, 3, 4].map((x) => x), ",");
testJoin("4,5,6,7", [ic, ic, ic, ic].map((x) => x), ",");
}
void testStringVariants() {
// ASCII
testJoin("axbxcxd", ["a", "b", "c", "d"], "x");
testJoin("a\u2000b\u2000c\u2000d", ["a", "b", "c", "d"], "\u2000");
testJoin("abcd", ["a", "b", "c", "d"], "");
testJoin("abcd", ["a", "b", "c", "d"]);
// Non-ASCII
testJoin("axbxcx\u2000", ["a", "b", "c", "\u2000"], "x");
testJoin("a\u2000b\u2000c\u2000\u2000", ["a", "b", "c", "\u2000"], "\u2000");
testJoin("abc\u2000", ["a", "b", "c", "\u2000"], "");
testJoin("abc\u2000", ["a", "b", "c", "\u2000"]);
// Long-ASCII
testJoin("ax" * 255 + "a", new List.generate(256, (_) => "a"), "x");
testJoin("a" * 256, new List.generate(256, (_) => "a"));
// Long-Non-ASCII
testJoin("a\u2000" * 255 + "a", new List.generate(256, (_) => "a"), "\u2000");
testJoin("\u2000" * 256, new List.generate(256, (_) => "\u2000"));
testJoin(
"\u2000x" * 255 + "\u2000", new List.generate(256, (_) => "\u2000"), "x");
var o1 = new Stringable("x");
var o2 = new Stringable("\ufeff");
testJoin("xa" * 3 + "x", [o1, o1, o1, o1], "a");
testJoin("x" * 4, [o1, o1, o1, o1], "");
testJoin("x" * 4, [o1, o1, o1, o1]);
testJoin("\ufeffx" * 3 + "\ufeff", [o2, o2, o2, o2], "x");
testJoin("\ufeff" * 4, [o2, o2, o2, o2], "");
testJoin("\ufeff" * 4, [o2, o2, o2, o2]);
testJoin("a\u2000x\ufeff", ["a", "\u2000", o1, o2]);
testJoin("a\u2000\ufeffx", ["a", "\u2000", o2, o1]);
testJoin("ax\u2000\ufeff", ["a", o1, "\u2000", o2]);
testJoin("ax\ufeff\u2000", ["a", o1, o2, "\u2000"]);
testJoin("a\ufeffx\u2000", ["a", o2, o1, "\u2000"]);
testJoin("a\ufeff\u2000x", ["a", o2, "\u2000", o1]);
testJoin("\u2000ax\ufeff", ["\u2000", "a", o1, o2]);
testJoin("\u2000a\ufeffx", ["\u2000", "a", o2, o1]);
testJoin("xa\u2000\ufeff", [o1, "a", "\u2000", o2]);
testJoin("xa\ufeff\u2000", [o1, "a", o2, "\u2000"]);
testJoin("\ufeffax\u2000", [o2, "a", o1, "\u2000"]);
testJoin("\ufeffa\u2000x", [o2, "a", "\u2000", o1]);
testJoin("\u2000xa\ufeff", ["\u2000", o1, "a", o2]);
testJoin("\u2000\ufeffax", ["\u2000", o2, "a", o1]);
testJoin("x\u2000a\ufeff", [o1, "\u2000", "a", o2]);
testJoin("x\ufeffa\u2000", [o1, o2, "a", "\u2000"]);
testJoin("\ufeffxa\u2000", [o2, o1, "a", "\u2000"]);
testJoin("\ufeff\u2000ax", [o2, "\u2000", "a", o1]);
testJoin("\u2000x\ufeffa", ["\u2000", o1, o2, "a"]);
testJoin("\u2000\ufeffxa", ["\u2000", o2, o1, "a"]);
testJoin("x\u2000\ufeffa", [o1, "\u2000", o2, "a"]);
testJoin("x\ufeff\u2000a", [o1, o2, "\u2000", "a"]);
testJoin("\ufeffx\u2000a", [o2, o1, "\u2000", "a"]);
testJoin("\ufeff\u2000xa", [o2, "\u2000", o1, "a"]);
}
class Stringable {
final String value;
Stringable(this.value);
String toString() => value;
}
main() {
testCollections();
testStringVariants();
// TODO(lrn): test scalar lists.
}

View file

@ -1,205 +0,0 @@
// Copyright (c) 2014, 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";
import 'dart:collection';
import 'dart:typed_data';
class MyList extends ListBase {
List list;
MyList(this.list);
get length => list.length;
set length(val) {
list.length = val;
}
operator [](index) => list[index];
operator []=(index, val) => list[index] = val;
}
id(x) => x;
main() {
// Test functionality.
for (var iterable in [
const [1, 2, 3],
[1, 2, 3],
new List(3)
..[0] = 1
..[1] = 2
..[2] = 3,
{1: 1, 2: 2, 3: 3}.keys,
{1: 1, 2: 2, 3: 3}.values,
new Iterable.generate(3, (x) => x + 1),
new List.generate(3, (x) => x + 1),
[0, 1, 2, 3].where((x) => x > 0),
[0, 1, 2].map((x) => x + 1),
[
[1, 2],
[3]
].expand(id),
[3, 2, 1].reversed,
[0, 1, 2, 3].skip(1),
[1, 2, 3, 4].take(3),
new Uint8List(3)
..[0] = 1
..[1] = 2
..[2] = 3,
(new HashMap()
..[1] = 1
..[2] = 2
..[3] = 3)
.keys,
(new HashMap()
..[1] = 1
..[2] = 2
..[3] = 3)
.values,
(new SplayTreeMap()
..[1] = 0
..[2] = 0
..[3] = 0)
.keys,
(new SplayTreeMap()
..[0] = 1
..[1] = 2
..[2] = 3)
.values,
new HashSet()..add(1)..add(2)..add(3),
new LinkedHashSet()..add(1)..add(2)..add(3),
new SplayTreeSet()..add(1)..add(2)..add(3),
"\x01\x02\x03".codeUnits,
"\x01\x02\x03".runes,
new MyList([1, 2, 3]),
]) {
int callCount = 0;
var result = iterable.reduce((x, y) {
callCount++;
return x + y;
});
Expect.equals(6, result, "${iterable.runtimeType}");
Expect.equals(2, callCount);
}
// Empty iterables not allowed.
for (var iterable in [
const [],
[],
new List(0),
{}.keys,
{}.values,
new Iterable.generate(0, (x) => x + 1),
new List.generate(0, (x) => x + 1),
[0, 1, 2, 3].where((x) => false),
[].map((x) => x + 1),
[[], []].expand(id),
[].reversed,
[0, 1, 2, 3].skip(4),
[1, 2, 3, 4].take(0),
new Uint8List(0),
(new HashMap()).keys,
(new HashMap()).values,
(new SplayTreeMap()).keys,
(new SplayTreeMap()).values,
new HashSet(),
new LinkedHashSet(),
new SplayTreeSet(),
"".codeUnits,
"".runes,
new MyList([]),
]) {
Expect.throws(() {
iterable.reduce((x, y) => throw "Unreachable");
}, (e) => e is StateError);
}
// Singleton iterables not calling reduce function.
for (var iterable in [
const [1],
[1],
new List(1)..[0] = 1,
{1: 1}.keys,
{1: 1}.values,
new Iterable.generate(1, (x) => x + 1),
new List.generate(1, (x) => x + 1),
[0, 1, 2, 3].where((x) => x == 1),
[0].map((x) => x + 1),
[
[],
[1]
].expand(id),
[1].reversed,
[0, 1].skip(1),
[1, 2, 3, 4].take(1),
new Uint8List(1)..[0] = 1,
(new HashMap()..[1] = 0).keys,
(new HashMap()..[0] = 1).values,
(new SplayTreeMap()..[1] = 0).keys,
(new SplayTreeMap()..[0] = 1).values,
new HashSet()..add(1),
new LinkedHashSet()..add(1),
new SplayTreeSet()..add(1),
"\x01".codeUnits,
"\x01".runes,
new MyList([1]),
]) {
Expect.equals(1, iterable.reduce((x, y) => throw "Unreachable"));
}
// Concurrent modifications not allowed.
testModification(base, modify, transform) {
var iterable = transform(base);
Expect.throws(() {
iterable.reduce((x, y) {
modify(base);
return x + y;
});
}, (e) => e is ConcurrentModificationError);
}
void add4(collection) {
collection.add(4);
}
void put4(map) {
map[4] = 4;
}
testModification([1, 2, 3], add4, id);
testModification(new HashSet()..add(1)..add(2)..add(3), add4, id);
testModification(new LinkedHashSet()..add(1)..add(2)..add(3), add4, id);
testModification(new SplayTreeSet()..add(1)..add(2)..add(3), add4, id);
testModification(new MyList([1, 2, 3]), add4, id);
testModification([0, 1, 2, 3], add4, (x) => x.where((x) => x > 0));
testModification([0, 1, 2], add4, (x) => x.map((x) => x + 1));
testModification([
[1, 2],
[3]
], add4, (x) => x.expand((x) => x));
testModification([3, 2, 1], add4, (x) => x.reversed);
testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.keys);
testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.values);
var hashMap = new HashMap()
..[1] = 1
..[2] = 2
..[3] = 3;
testModification(hashMap, put4, (x) => x.keys);
hashMap = new HashMap()
..[1] = 1
..[2] = 2
..[3] = 3;
testModification(hashMap, put4, (x) => x.values);
var splayMap = new SplayTreeMap()
..[1] = 1
..[2] = 2
..[3] = 3;
testModification(splayMap, put4, (x) => x.keys);
splayMap = new SplayTreeMap()
..[1] = 1
..[2] = 2
..[3] = 3;
testModification(splayMap, put4, (x) => x.values);
}

View file

@ -1,258 +0,0 @@
// Copyright (c) 2012, 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";
main() {
List<int> list1 = <int>[1, 2, 3];
List<int> list2 = const <int>[4, 5];
List<String> list3 = <String>[];
Set<int> set1 = new Set<int>();
set1..add(11)..add(12)..add(13);
Set set2 = new Set();
Iterable<int> skip0 = list1.skip(0);
Expect.isTrue(skip0 is! List);
Iterator<int> it = skip0.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.equals(1, it.current);
Expect.isTrue(it.moveNext());
Expect.equals(2, it.current);
Expect.isTrue(it.moveNext());
Expect.equals(3, it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
Iterable<int> skip1 = list1.skip(1);
Expect.isTrue(skip1 is! List);
Expect.isTrue(skip1.skip(2).skip(1) is! List);
it = skip1.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.equals(2, it.current);
Expect.isTrue(it.moveNext());
Expect.equals(3, it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
Iterable<int> skip2 = list1.skip(2);
Expect.isTrue(skip2 is! List);
Expect.isTrue(skip2.skip(2).skip(1) is! List);
it = skip2.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.equals(3, it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
Iterable<int> skip3 = list1.skip(3);
Expect.isTrue(skip3 is! List);
Expect.isTrue(skip3.skip(2).skip(1) is! List);
it = skip3.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
Iterable<int> skip4 = list1.skip(4);
Expect.isTrue(skip4 is! List);
Expect.isTrue(skip4.skip(2).skip(1) is! List);
it = skip4.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip0 = list1.skip(0);
skip1 = skip0.skip(1);
skip2 = skip1.skip(1);
skip3 = skip2.skip(1);
skip4 = skip3.skip(1);
it = skip0.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.equals(1, it.current);
Expect.isTrue(it.moveNext());
Expect.equals(2, it.current);
Expect.isTrue(it.moveNext());
Expect.equals(3, it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
it = skip1.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.equals(2, it.current);
Expect.isTrue(it.moveNext());
Expect.equals(3, it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
it = skip2.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.equals(3, it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
it = skip3.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
it = skip4.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip0 = list2.skip(0);
Expect.isTrue(skip0 is! List);
Expect.isTrue(skip0.skip(2).skip(1) is! List);
it = skip0.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.equals(4, it.current);
Expect.isTrue(it.moveNext());
Expect.equals(5, it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip1 = list2.skip(1);
Expect.isTrue(skip1 is! List);
Expect.isTrue(skip1.skip(2).skip(1) is! List);
it = skip1.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.equals(5, it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip2 = list2.skip(2);
Expect.isTrue(skip2 is! List);
Expect.isTrue(skip2.skip(2).skip(1) is! List);
it = skip2.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip3 = list2.skip(3);
Expect.isTrue(skip3 is! List);
Expect.isTrue(skip3.skip(2).skip(1) is! List);
it = skip3.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
Iterable<String> skip02 = list3.skip(0);
Expect.isTrue(skip02 is! List);
Expect.isTrue(skip02.skip(2).skip(1) is! List);
Iterator<String> it2 = skip02.iterator;
Expect.isNull(it2.current);
Expect.isFalse(it2.moveNext());
Expect.isNull(it2.current);
Iterable<String> skip12 = list3.skip(1);
Expect.isTrue(skip12 is! List);
Expect.isTrue(skip12.skip(2).skip(1) is! List);
it2 = skip12.iterator;
Expect.isNull(it2.current);
Expect.isFalse(it2.moveNext());
Expect.isNull(it2.current);
skip0 = set1.skip(0);
List<int> copied = skip0.toList();
Expect.equals(3, copied.length);
Expect.isTrue(set1.contains(copied[0]));
Expect.isTrue(set1.contains(copied[1]));
Expect.isTrue(set1.contains(copied[2]));
Expect.isTrue(copied[0] != copied[1]);
Expect.isTrue(copied[0] != copied[2]);
Expect.isTrue(copied[1] != copied[2]);
it = skip0.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.isNotNull(it.current);
Expect.isTrue(it.moveNext());
Expect.isNotNull(it.current);
Expect.isTrue(it.moveNext());
Expect.isNotNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip1 = set1.skip(1);
copied = skip1.toList();
Expect.equals(2, copied.length);
Expect.isTrue(set1.contains(copied[0]));
Expect.isTrue(set1.contains(copied[1]));
Expect.isTrue(copied[0] != copied[1]);
it = skip1.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.isNotNull(it.current);
Expect.isTrue(it.moveNext());
Expect.isNotNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip2 = set1.skip(2);
copied = skip2.toList();
Expect.equals(1, copied.length);
Expect.isTrue(set1.contains(copied[0]));
it = skip2.iterator;
Expect.isNull(it.current);
Expect.isTrue(it.moveNext());
Expect.isNotNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip3 = set1.skip(3);
it = skip3.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip4 = set1.skip(4);
it = skip4.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip0 = set2.skip(0);
it = skip0.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
skip1 = set2.skip(1);
it = skip1.iterator;
Expect.isNull(it.current);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
testSkipTake(Iterable input, int skip, int take) {
List expected = [];
Iterator iter = input.iterator;
for (int i = 0; i < skip; i++) iter.moveNext();
for (int i = 0; i < take; i++) {
if (!iter.moveNext()) break;
expected.add(iter.current);
}
Expect.listEquals(expected, input.skip(skip).take(take).toList());
}
List longList = [1, 4, 5, 3, 8, 11, 12, 6, 9, 10, 13, 7, 2, 14, 15];
Set bigSet = longList.toSet();
for (Iterable collection in [longList, longList.reversed, bigSet]) {
testSkipTake(collection, 0, 0);
testSkipTake(collection, 0, 5);
testSkipTake(collection, 0, 15);
testSkipTake(collection, 0, 25);
testSkipTake(collection, 5, 0);
testSkipTake(collection, 5, 5);
testSkipTake(collection, 5, 10);
testSkipTake(collection, 5, 20);
testSkipTake(collection, 15, 0);
testSkipTake(collection, 15, 5);
testSkipTake(collection, 20, 0);
testSkipTake(collection, 20, 5);
Expect.throws(() => collection.skip(-1), (e) => e is RangeError);
Expect.throws(() => collection.skip(1).skip(-1), (e) => e is RangeError);
}
}

View file

@ -22,6 +22,9 @@ string_static_test: MissingCompileTimeError
[ (!$checked && $runtime == vm) || (!$checked && $compiler == dart2js) || $compiler == precompiler ]
int_parse_radix_test/badTypes: RuntimeError # wrong exception returned
[ ($compiler == dart2analyzer && $strong) || $compiler == dartdevc ]
iterable_reduce_test/01: CompileTimeError
[ !$strong && !$checked ]
core_runtime_types_static_test: MissingCompileTimeError
splay_tree_test/01: MissingCompileTimeError
@ -36,6 +39,9 @@ int_parse_radix_bad_handler_test: MissingCompileTimeError
[ $compiler == dart2analyzer && !$strong ]
symbol_reserved_word_test/05: MissingCompileTimeError # Issue 30245
[ $compiler != dartdevc && ($compiler != dart2analyzer || !$strong) ]
iterable_mapping_test/01: MissingCompileTimeError
[ $compiler == dart2analyzer && !$strong && !$checked ]
from_environment_const_type_test/02: MissingCompileTimeError
from_environment_const_type_test/03: MissingCompileTimeError
@ -88,6 +94,7 @@ compare_to2_test: RuntimeError # Issue 30170
date_time10_test: RuntimeError # Issue 29921
growable_list_test: RuntimeError # Issue 29921
hash_set_test/01: RuntimeError # Issue 29921
iterable_reduce_test/none: RuntimeError
iterable_to_list_test/*: RuntimeError
list_test/none: RuntimeError
list_test/01: RuntimeError
@ -151,6 +158,7 @@ symbol_reserved_word_test/12: RuntimeError # Issue 29921
int_parse_with_limited_ints_test: Skip # dartdevc doesn't know about --limit-ints-to-64-bits
typed_data_with_limited_ints_test: Skip # dartdevc doesn't know about --limit-ints-to-64-bits
int_modulo_arith_test/none: RuntimeError # Issue 29921
iterable_return_type_test/02: RuntimeError # Issue 29921
[ ($compiler == dart2js || $compiler == dartdevc) && $runtime != none ]
big_integer_arith_vm_test: RuntimeError # Issues 10245, 30170
@ -431,6 +439,7 @@ from_environment_const_type_undefined_test/04: MissingCompileTimeError
from_environment_const_type_undefined_test/06: MissingCompileTimeError
from_environment_const_type_undefined_test/07: MissingCompileTimeError
from_environment_const_type_undefined_test/08: MissingCompileTimeError
iterable_generate_test/01: RuntimeError
[ ($compiler == none && $runtime == vm) || $compiler == dart2js ]
@ -713,6 +722,19 @@ uri_path_test: Crash
uri_query_test: Crash
uri_scheme_test: Crash
uri_test: Crash
iterable_generate_test/01: Crash
iterable_generate_test/none: Crash
iterable_join_test: Crash
iterable_last_test: Crash
iterable_last_where_test: Crash
iterable_length_test: Crash
iterable_reduce_test: Crash
iterable_return_type_test/01: Crash
iterable_return_type_test/02: Crash
iterable_return_type_test/none: Crash
iterable_single_test: Crash
iterable_single_where_test: Crash
iterable_skip_test: Crash
[ $compiler == dart2js && $dart2js_with_kernel && $host_checked ]
stopwatch_test: Crash
@ -1007,6 +1029,19 @@ uri_path_test: Crash
uri_query_test: Crash
uri_scheme_test: Crash
uri_test: Crash
iterable_generate_test/01: Crash
iterable_generate_test/none: Crash
iterable_join_test: Crash
iterable_last_test: Crash
iterable_last_where_test: Crash
iterable_length_test: Crash
iterable_reduce_test: Crash
iterable_return_type_test/01: Crash
iterable_return_type_test/02: Crash
iterable_return_type_test/none: Crash
iterable_single_test: Crash
iterable_single_where_test: Crash
iterable_skip_test: Crash
[$arch == simdbc || $arch == simdbc64]
regexp/stack-overflow_test: RuntimeError, OK # Smaller limit with irregex interpreter
@ -1015,9 +1050,11 @@ regexp/stack-overflow_test: RuntimeError, OK # Smaller limit with irregex interp
splay_tree_from_iterable_test: RuntimeError
[ ($compiler == none || $compiler == app_jit || $compiler == dartk) && $runtime == vm && !$checked ]
iterable_generate_test/01: RuntimeError
splay_tree_from_iterable_test: RuntimeError
[ $compiler == precompiler && $runtime == dart_precompiled && !$checked ]
iterable_generate_test/01: RuntimeError
splay_tree_from_iterable_test: RuntimeError
[ $runtime == vm || $runtime == dart_precompiled || $runtime == flutter ]
@ -1033,6 +1070,8 @@ package_resource_test: RuntimeError # Issue 26842
[ $compiler == dart2js && ! $dart2js_with_kernel ]
list_unmodifiable_test: Pass, RuntimeError # Issue 28712
iterable_to_list_test/01: RuntimeError # Issue 26501
iterable_return_type_test/01: RuntimeError # Issue 20085
iterable_return_type_test/02: RuntimeError # Dart2js does not support Uint64*.
[ $compiler == dart2analyzer ]
int_parse_radix_bad_handler_test: MissingCompileTimeError

View file

@ -37,9 +37,7 @@ main() {
Expect.isFalse(st.iterator is Iterator<int>);
test(["0", "1", "2", "3", "4"], st);
if (typeAssertionsEnabled) {
Expect.throws(() => new Iterable<String>.generate(5));
}
Expect.throws(() => new Iterable<String>.generate(5));
// Omitted generator function means `(int x) => x`, and the type parameters
// must then be compatible with `int`.
@ -57,12 +55,7 @@ main() {
// Invalid types:
Expect.throws(() => new Iterable<String>.generate(5));
if (typeAssertionsEnabled) { // //# 01: ok
Expect.throws(() => new Iterable<Null>.generate(5).elementAt(2)); //# 01: continued
} else { // //# 01: continued
Iterable<dynamic> iter5 = new Iterable<Null>.generate(5); // //# 01: continued
Expect.equals(2, iter5.elementAt(2)); // //# 01: continued
} // //# 01: continued
Expect.throws(() => new Iterable<Null>.generate(5).elementAt(2)); //# 01: ok
Expect.throws(() => new Iterable<bool>.generate(5));
// Regression: https://github.com/dart-lang/sdk/issues/26358

View file

@ -24,11 +24,11 @@ main() {
mapped = mapped.map((x) => x + 1);
Expect.listEquals([6, 7], mapped.toList());
mapped = list3.map((x) => x + 1);
Expect.listEquals([], mapped.toList());
mapped = list3.map((x) => x + 1); //# 01: compile-time error
Expect.listEquals([], mapped.toList()); //# 01: continued
mapped = mapped.map((x) => x + 1);
Expect.listEquals([], mapped.toList());
mapped = mapped.map((x) => x + 1); //# 01: continued
Expect.listEquals([], mapped.toList()); //# 01: continued
var expected = new Set<int>()..addAll([12, 13, 14]);
mapped = set1.map((x) => x + 1);

View file

@ -36,10 +36,10 @@ main() {
new List.generate(3, (x) => x + 1),
[0, 1, 2, 3].where((x) => x > 0),
[0, 1, 2].map((x) => x + 1),
[
[1, 2],
[3]
].expand(id),
[ //# 01: ok
[1, 2], //# 01: ok
[3] //# 01: ok
].expand(id), //# 01: ok
[3, 2, 1].reversed,
[0, 1, 2, 3].skip(1),
[1, 2, 3, 4].take(3),
@ -75,12 +75,12 @@ main() {
new MyList([1, 2, 3]),
]) {
int callCount = 0;
var result = iterable.reduce((x, y) {
callCount++;
return x + y;
});
Expect.equals(6, result, "${iterable.runtimeType}");
Expect.equals(2, callCount);
var result = iterable.reduce((x, y) { //# 01: ok
callCount++; //# 01: ok
return x + y; //# 01: ok
}); //# 01: ok
Expect.equals(6, result, "${iterable.runtimeType}"); //# 01: ok
Expect.equals(2, callCount); //# 01: ok
}
// Empty iterables not allowed.
@ -94,7 +94,7 @@ main() {
new List.generate(0, (x) => x + 1),
[0, 1, 2, 3].where((x) => false),
[].map((x) => x + 1),
[[], []].expand(id),
[[], []].expand(id), //# 01: ok
[].reversed,
[0, 1, 2, 3].skip(4),
[1, 2, 3, 4].take(0),
@ -126,10 +126,10 @@ main() {
new List.generate(1, (x) => x + 1),
[0, 1, 2, 3].where((x) => x == 1),
[0].map((x) => x + 1),
[
[],
[1]
].expand(id),
[ //# 01: ok
[], //# 01: ok
[1] //# 01: ok
].expand(id), //# 01: ok
[1].reversed,
[0, 1].skip(1),
[1, 2, 3, 4].take(1),
@ -145,7 +145,7 @@ main() {
"\x01".runes,
new MyList([1]),
]) {
Expect.equals(1, iterable.reduce((x, y) => throw "Unreachable"));
Expect.equals(1, iterable.reduce((x, y) => throw "Unreachable")); //# 01: ok
}
// Concurrent modifications not allowed.

View file

@ -11,8 +11,6 @@
duration2_test: Skip
error_stack_trace_test: Skip
http_resource_test: Skip
iterable_mapping_test: Skip
iterable_reduce_test: Skip
linked_hash_map_from_iterable_test: Skip
regexp/regress-regexp-codeflush_test: Skip
regexp/standalones_test: Skip
@ -20,7 +18,6 @@ string_replace_test: Skip
[ $compiler == dartdevc && $runtime != none ]
hash_set_test/01: RuntimeError # Issue 29921
iterable_return_type_test/02: RuntimeError # Issue 29921
regress_r21715_test: RuntimeError # Issue 29921
string_operations_with_null_test: RuntimeError # Issue 29921
from_environment_const_type_test/01: RuntimeError # Issue 29921

View file

@ -10,10 +10,6 @@ const_list_remove_range_test: DartkCompileTimeError
const_list_set_range_test: DartkCompileTimeError
hash_map2_test: Crash # VM does not support BottomType
int_from_environment_test: RuntimeError
iterable_return_type_test/01: RuntimeError
iterable_return_type_test/02: RuntimeError
iterable_return_type_test/none: RuntimeError
iterable_skip_test: DartkCompileTimeError
set_test: DartkCompileTimeError
shuffle_test: DartkCompileTimeError
sort_test: DartkCompileTimeError

View file

@ -1,45 +0,0 @@
// Copyright (c) 2013, 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";
main() {
bool checkedMode = false;
assert((checkedMode = true));
void test(expectedList, generatedIterable) {
Expect.equals(expectedList.length, generatedIterable.length);
Expect.listEquals(expectedList, generatedIterable.toList());
}
test([], new Iterable.generate(0));
test([0], new Iterable.generate(1));
test([0, 1, 2, 3, 4], new Iterable.generate(5));
test(["0", "1", "2", "3", "4"], new Iterable.generate(5, (x) => "$x"));
test([2, 3, 4, 5, 6], new Iterable.generate(7).skip(2));
test([0, 1, 2, 3, 4], new Iterable.generate(7).take(5));
test([], new Iterable.generate(5).skip(6));
test([], new Iterable.generate(5).take(0));
test([], new Iterable.generate(5).take(3).skip(3));
test([], new Iterable.generate(5).skip(6).take(0));
// Test types.
Iterable<int> it = new Iterable<int>.generate(5);
Expect.isTrue(it is Iterable<int>);
Expect.isTrue(it.iterator is Iterator<int>);
Expect.isTrue(it is! Iterable<String>);
Expect.isTrue(it.iterator is! Iterator<String>);
test([0, 1, 2, 3, 4], it);
Iterable<String> st = new Iterable<String>.generate(5, (x) => "$x");
Expect.isTrue(st is Iterable<String>);
Expect.isTrue(st.iterator is Iterator<String>);
Expect.isFalse(st is Iterable<int>);
Expect.isFalse(st.iterator is Iterator<int>);
test(["0", "1", "2", "3", "4"], st);
if (checkedMode) {
Expect.throws(() => new Iterable<String>.generate(5));
}
}

View file

@ -1,22 +0,0 @@
// Copyright (c) 2012, 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";
main() {
List<int> list1 = <int>[1, 2, 3];
List<int> list2 = const <int>[4, 5];
List<String> list3 = <String>[];
Set<int> set1 = new Set<int>();
set1..add(11)..add(12)..add(13);
Set set2 = new Set();
Expect.equals(3, list1.last);
Expect.equals(5, list2.last);
Expect.throws(() => list3.last, (e) => e is StateError);
Expect.isTrue(set1.contains(set1.last));
Expect.throws(() => set2.last, (e) => e is StateError);
}

View file

@ -1,43 +0,0 @@
// Copyright (c) 2012, 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';
main() {
List<int> list1 = <int>[1, 2, 3];
List<int> list2 = const <int>[4, 5, 6];
List<String> list3 = <String>[];
Set<int> set1 = new Set<int>();
set1..add(11)..add(12)..add(13);
Set set2 = new Set();
Expect.equals(2, list1.lastWhere((x) => x.isEven));
Expect.equals(3, list1.lastWhere((x) => x.isOdd));
Expect.throws(() => list1.lastWhere((x) => x > 3), (e) => e is StateError);
Expect.equals(null, list1.lastWhere((x) => x > 3, orElse: () => null));
Expect.equals(499, list1.lastWhere((x) => x > 3, orElse: () => 499));
Expect.equals(6, list2.lastWhere((x) => x.isEven));
Expect.equals(5, list2.lastWhere((x) => x.isOdd));
Expect.throws(() => list2.lastWhere((x) => x == 0), (e) => e is StateError);
Expect.equals(null, list2.lastWhere((x) => false, orElse: () => null));
Expect.equals(499, list2.lastWhere((x) => false, orElse: () => 499));
Expect.throws(() => list3.lastWhere((x) => x == 0), (e) => e is StateError);
Expect.throws(() => list3.lastWhere((x) => true), (e) => e is StateError);
Expect.equals(null, list3.lastWhere((x) => true, orElse: () => null));
Expect.equals("str", list3.lastWhere((x) => false, orElse: () => "str"));
Expect.equals(12, set1.lastWhere((x) => x.isEven));
var odd = set1.lastWhere((x) => x.isOdd);
Expect.isTrue(odd == 11 || odd == 13);
Expect.throws(() => set1.lastWhere((x) => false), (e) => e is StateError);
Expect.equals(null, set1.lastWhere((x) => false, orElse: () => null));
Expect.equals(499, set1.lastWhere((x) => false, orElse: () => 499));
Expect.throws(() => set2.lastWhere((x) => false), (e) => e is StateError);
Expect.throws(() => set2.lastWhere((x) => true), (e) => e is StateError);
Expect.equals(null, set2.lastWhere((x) => true, orElse: () => null));
Expect.equals(499, set2.lastWhere((x) => false, orElse: () => 499));
}

View file

@ -1,44 +0,0 @@
// Copyright (c) 2012, 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 "dart:collection";
import "package:expect/expect.dart";
class A extends IterableBase {
int count;
A(this.count);
Iterator get iterator {
return new AIterator(count);
}
}
class AIterator implements Iterator {
int _count;
int _current;
AIterator(this._count);
bool moveNext() {
if (_count > 0) {
_current = _count;
_count--;
return true;
}
_current = null;
return false;
}
get current => _current;
}
main() {
var a = new A(10);
Expect.equals(10, a.length);
a = new A(0);
Expect.equals(0, a.length);
a = new A(5);
Expect.equals(5, a.map((e) => e + 1).length);
Expect.equals(3, a.where((e) => e >= 3).length);
}

View file

@ -1,50 +0,0 @@
// Copyright (c) 2013, 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";
main() {
List<int> list1 = <int>[1, 2, 3];
List<int> list2 = const <int>[4, 5];
List<String> list3 = <String>[];
Set<int> set1 = new Set<int>();
set1.addAll([11, 12, 13]);
Set set2 = new Set();
Iterable mapped = list1.map((x) => x + 1);
Expect.listEquals([2, 3, 4], mapped.toList());
mapped = mapped.map((x) => x + 1);
Expect.listEquals([3, 4, 5], mapped.toList());
mapped = list2.map((x) => x + 1);
Expect.listEquals([5, 6], mapped.toList());
mapped = mapped.map((x) => x + 1);
Expect.listEquals([6, 7], mapped.toList());
mapped = list3.map((x) => x + 1);
Expect.listEquals([], mapped.toList());
mapped = mapped.map((x) => x + 1);
Expect.listEquals([], mapped.toList());
var expected = new Set<int>()..addAll([12, 13, 14]);
mapped = set1.map((x) => x + 1);
Expect.isFalse(mapped is List);
Expect.setEquals(expected, mapped.toSet());
expected = new Set<int>()..addAll([13, 14, 15]);
mapped = mapped.map((x) => x + 1);
Expect.isFalse(mapped is List);
Expect.setEquals(expected, mapped.toSet());
mapped = set2.map((x) => x + 1);
Expect.isFalse(mapped is List);
Expect.listEquals([], mapped.toList());
mapped = mapped.map((x) => x + 1);
Expect.isFalse(mapped is List);
Expect.listEquals([], mapped.toList());
}

View file

@ -1,90 +0,0 @@
// Copyright (c) 2013, 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.
// Regression test for dart2js where [List.addAll] was not typed
// correctly.
import "package:expect/expect.dart";
import 'dart:collection';
import 'dart:typed_data';
testIntIterable(iterable) {
Expect.isTrue(iterable is Iterable<int>);
Expect.isFalse(iterable is Iterable<String>);
}
void testIterable(Iterable<int> iterable, [int depth = 3]) {
testIntIterable(iterable);
if (depth > 0) {
testIterable(iterable.where((x) => true), depth - 1);
testIterable(iterable.skip(1), depth - 1);
testIterable(iterable.take(1), depth - 1);
testIterable(iterable.skipWhile((x) => false), depth - 1);
testIterable(iterable.takeWhile((x) => true), depth - 1);
testList(iterable.toList(growable: true), depth - 1);
testList(iterable.toList(growable: false), depth - 1);
testIterable(iterable.toSet(), depth - 1);
}
}
void testList(List<int> list, [int depth = 3]) {
testIterable(list, depth);
if (depth > 0) {
testIterable(list.getRange(0, list.length), depth - 1);
testIterable(list.reversed, depth - 1);
testMap(list.asMap(), depth - 1);
}
}
void testMap(Map<int, int> map, [int depth = 3]) {
Expect.isTrue(map is Map<int, int>);
Expect.isFalse(map is Map<int, String>);
Expect.isFalse(map is Map<String, int>);
if (depth > 0) {
testIterable(map.keys, depth - 1);
testIterable(map.values, depth - 1);
}
}
main() {
// Empty lists.
testList(<int>[]);
testList(new List<int>(0));
testList(new List<int>());
testList(const <int>[]);
testList(new List<int>.generate(0, (x) => x + 1));
// Singleton lists.
testList(<int>[1]);
testList(new List<int>(1)..[0] = 1);
testList(new List<int>()..add(1));
testList(const <int>[1]);
testList(new List<int>.generate(1, (x) => x + 1));
// Typed lists.
testList(new Uint8List(1)..[0] = 1); // //# 01: ok
testList(new Int8List(1)..[0] = 1); // //# 01: continued
testList(new Uint16List(1)..[0] = 1); // //# 01: continued
testList(new Int16List(1)..[0] = 1); // //# 01: continued
testList(new Uint32List(1)..[0] = 1); // //# 01: continued
testList(new Int32List(1)..[0] = 1); // //# 01: continued
testList(new Uint64List(1)..[0] = 1); // //# 02: ok
testList(new Int64List(1)..[0] = 1); // //# 02: continued
testIterable(new Set<int>()..add(1));
testIterable(new HashSet<int>()..add(1));
testIterable(new LinkedHashSet<int>()..add(1));
testIterable(new SplayTreeSet<int>()..add(1));
testIterable(new Queue<int>()..add(1));
testIterable(new DoubleLinkedQueue<int>()..add(1));
testIterable(new ListQueue<int>()..add(1));
testMap(new Map<int, int>()..[1] = 1);
testMap(new HashMap<int, int>()..[1] = 1);
testMap(new LinkedHashMap<int, int>()..[1] = 1);
testMap(new SplayTreeMap<int, int>()..[1] = 1);
testMap(<int, int>{1: 1});
testMap(const <int, int>{1: 1});
}

View file

@ -1,31 +0,0 @@
// Copyright (c) 2012, 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";
main() {
List<int> list1a = <int>[1];
List<int> list1b = <int>[1, 2, 3];
List<int> list1c = <int>[];
List<int> list2a = const <int>[5];
List<int> list2b = const <int>[4, 5];
List<int> list2c = const <int>[];
Set<int> set1 = new Set<int>();
set1..add(22);
Set set2 = new Set();
set2..add(11)..add(12)..add(13);
Set set3 = new Set();
Expect.equals(1, list1a.single);
Expect.throws(() => list1b.single, (e) => e is StateError);
Expect.throws(() => list1c.single, (e) => e is StateError);
Expect.equals(5, list2a.single);
Expect.throws(() => list2b.single, (e) => e is StateError);
Expect.throws(() => list2c.single, (e) => e is StateError);
Expect.equals(22, set1.single);
Expect.throws(() => set2.single, (e) => e is StateError);
Expect.throws(() => set3.single, (e) => e is StateError);
}

View file

@ -1,32 +0,0 @@
// Copyright (c) 2012, 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';
main() {
List<int> list1 = <int>[1, 2, 3];
List<int> list2 = const <int>[4, 5, 6];
List<String> list3 = <String>[];
Set<int> set1 = new Set<int>();
set1..add(11)..add(12)..add(13);
Set set2 = new Set();
Expect.equals(2, list1.singleWhere((x) => x.isEven));
Expect.equals(3, list1.singleWhere((x) => x == 3));
Expect.throws(
() => list1.singleWhere((x) => x.isOdd), (e) => e is StateError);
Expect.equals(6, list2.singleWhere((x) => x == 6));
Expect.equals(5, list2.singleWhere((x) => x.isOdd));
Expect.throws(
() => list2.singleWhere((x) => x.isEven), (e) => e is StateError);
Expect.throws(() => list3.singleWhere((x) => x == 0), (e) => e is StateError);
Expect.equals(12, set1.singleWhere((x) => x.isEven));
Expect.equals(11, set1.singleWhere((x) => x == 11));
Expect.throws(() => set1.singleWhere((x) => x.isOdd));
Expect.throws(() => set2.singleWhere((x) => true), (e) => e is StateError);
}