| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import "package:expect/expect.dart"; | |
| 6 | |
| 7 main() { | |
| 8 testEmpty(name, Iterable<int> it, [depth = 2]) { | |
| 9 Expect.isTrue(it.isEmpty, name); | |
| 10 Expect.isFalse(it.isNotEmpty, name); | |
| 11 Expect.equals(0, it.length, name); | |
| 12 Expect.isFalse(it.contains(null), name); | |
| 13 Expect.isFalse(it.any((x) => true), name); | |
| 14 Expect.isTrue(it.every((x) => false), name); | |
| 15 Expect.throws(() => it.first, (e) => e is StateError, name); | |
| 16 Expect.throws(() => it.last, (e) => e is StateError, name); | |
| 17 Expect.throws(() => it.single, (e) => e is StateError, name); | |
| 18 Expect.throws(() => it.elementAt(0), (e) => e is RangeError, name); | |
| 19 Expect.throws(() => it.reduce((a, b) => a), (e) => e is StateError, name); | |
| 20 Expect.throws( | |
| 21 () => it.singleWhere((_) => true), (e) => e is StateError, name); | |
| 22 Expect.equals(42, it.fold(42, (a, b) => "not 42"), name); | |
| 23 Expect.equals(42, it.firstWhere((v) => true, orElse: () => 42), name); | |
| 24 Expect.equals(42, it.lastWhere((v) => true, orElse: () => 42), name); | |
| 25 Expect.equals("", it.join("separator"), name); | |
| 26 Expect.equals("()", it.toString(), name); | |
| 27 Expect.listEquals([], it.toList(), name); | |
| 28 Expect.listEquals([], it.toList(growable: false), name); | |
| 29 Expect.listEquals([], it.toList(growable: true), name); | |
| 30 Expect.equals(0, it.toSet().length, name); | |
| 31 // Doesn't throw: | |
| 32 it.forEach((v) => throw v); | |
| 33 for (var v in it) { | |
| 34 throw v; | |
| 35 } | |
| 36 // Check that returned iterables are also empty. | |
| 37 if (depth > 0) { | |
| 38 testEmpty("$name-map", it.map((x) => x), depth - 1); | |
| 39 testEmpty("$name-where", it.where((x) => true), depth - 1); | |
| 40 testEmpty("$name-expand", it.expand((x) => [x]), depth - 1); | |
| 41 testEmpty("$name-skip", it.skip(1), depth - 1); | |
| 42 testEmpty("$name-take", it.take(2), depth - 1); | |
| 43 testEmpty("$name-skipWhile", it.skipWhile((v) => false), depth - 1); | |
| 44 testEmpty("$name-takeWhile", it.takeWhile((v) => true), depth - 1); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 testType(name, it, [depth = 2]) { | |
| 49 Expect.isTrue(it is Iterable<int>, name); | |
| 50 Expect.isFalse(it is Iterable<String>, name); | |
| 51 if (depth > 0) { | |
| 52 testType("$name-where", it.where((_) => true), depth - 1); | |
| 53 testType("$name-skip", it.skip(1), depth - 1); | |
| 54 testType("$name-take", it.take(1), depth - 1); | |
| 55 testType("$name-skipWhile", it.skipWhile((_) => false), depth - 1); | |
| 56 testType("$name-takeWhile", it.takeWhile((_) => true), depth - 1); | |
| 57 testType("$name-toList", it.toList(), depth - 1); | |
| 58 testType("$name-toList", it.toList(growable: false), depth - 1); | |
| 59 testType("$name-toList", it.toList(growable: true), depth - 1); | |
| 60 testType("$name-toSet", it.toSet(), depth - 1); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 test(name, it) { | |
| 65 testEmpty(name, it); | |
| 66 testType(name, it); | |
| 67 } | |
| 68 | |
| 69 test("const", const Iterable<int>.empty()); | |
| 70 test("new", new Iterable<int>.empty()); | |
| 71 } | |
| OLD | NEW |