Chromium Code Reviews| 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, 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(() => it.singleWhere((_) => true), (e) => e is StateError, nam e); | |
|
Søren Gjesse
2015/05/21 09:10:06
Long line.
| |
| 21 Expect.equals(42, it.fold(42, (a, b) => "not 42"), name); | |
| 22 Expect.equals(42, it.firstWhere((v) => true, orElse: () => 42), name); | |
| 23 Expect.equals(42, it.lastWhere((v) => true, orElse: () => 42), name); | |
| 24 Expect.equals("", it.join("separator"), name); | |
| 25 Expect.equals("()", it.toString(), name); | |
| 26 Expect.listEquals([], it.toList(), name); | |
| 27 Expect.listEquals([], it.toList(growable: false), name); | |
| 28 Expect.listEquals([], it.toList(growable: true), name); | |
| 29 Expect.equals(0, it.toSet().length, name); | |
| 30 // Doesn't throw: | |
| 31 it.forEach((v) => throw v); | |
| 32 for (var v in it) { | |
| 33 throw v; | |
| 34 } | |
| 35 // Check that returned iterables are also empty. | |
| 36 if (depth > 0) { | |
| 37 testEmpty("$name-map", it.map((x)=>x), depth - 1); | |
| 38 testEmpty("$name-where", it.where((x)=>true), depth - 1); | |
| 39 testEmpty("$name-expand", it.expand((x)=>[x]), depth - 1); | |
| 40 testEmpty("$name-skip", it.skip(1), depth - 1); | |
| 41 testEmpty("$name-take", it.take(2), depth - 1); | |
| 42 testEmpty("$name-skipWhile", it.skipWhile((v) => false), depth - 1); | |
| 43 testEmpty("$name-takeWhile", it.takeWhile((v) => true), depth - 1); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 testType(name, it, [depth = 2]) { | |
| 48 Expect.isTrue(it is Iterable<int>, name); | |
| 49 Expect.isFalse(it is Iterable<String>, name); | |
| 50 if (depth > 0) { | |
| 51 testType("$name-where", it.where((_)=>true), depth - 1); | |
| 52 testType("$name-skip", it.skip(1), depth - 1); | |
| 53 testType("$name-take", it.take(1), depth - 1); | |
| 54 testType("$name-skipWhile", it.skipWhile((_)=>false), depth - 1); | |
| 55 testType("$name-takeWhile", it.takeWhile((_)=>true), depth - 1); | |
| 56 testType("$name-toList", it.toList(), depth - 1); | |
| 57 testType("$name-toList", it.toList(growable: false), depth - 1); | |
| 58 testType("$name-toList", it.toList(growable: true), depth - 1); | |
| 59 testType("$name-toSet", it.toSet(), depth - 1); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 test(name, it) { | |
| 64 testEmpty(name, it); | |
| 65 testType(name, it); | |
| 66 } | |
| 67 | |
| 68 test("const", const Iterable<int>.empty()); | |
| 69 test("new", new Iterable<int>.empty()); | |
| 70 } | |
| 71 | |
| OLD | NEW |