| 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 main() { |
| 6 test(expectation, iterable) { |
| 7 Expect.listEquals(expectation, iterable.toList()); |
| 8 } |
| 9 |
| 10 // Function not called on empty iterable. |
| 11 test([], [].expand((x) { throw "not called"; })); |
| 12 |
| 13 // Creating the iterable doesn't call the function. |
| 14 [1].expand((x) { throw "not called"; }); |
| 15 |
| 16 test([1], [1].expand((x) => [x])); |
| 17 test([1, 2, 3], [1, 2, 3].expand((x) => [x])); |
| 18 |
| 19 test([], [1].expand((x) => [])); |
| 20 test([], [1, 2, 3].expand((x) => [])); |
| 21 test([2], [1, 2, 3].expand((x) => x == 2 ? [2] : [])); |
| 22 |
| 23 test([1, 1, 2, 2, 3, 3], [1, 2, 3].expand((x) => [x, x])); |
| 24 test([1, 1, 2], [1, 2, 3].expand((x) => [x, x, x].skip(x))); |
| 25 |
| 26 // if function throws, iteration is stopped. |
| 27 Iterable iterable = [1, 2, 3].expand((x) { |
| 28 if (x == 2) throw "FAIL"; |
| 29 return [x, x]; |
| 30 }); |
| 31 Iterator it = iterable.iterator; |
| 32 Expect.isTrue(it.moveNext()); |
| 33 Expect.equals(1, it.current); |
| 34 Expect.isTrue(it.moveNext()); |
| 35 Expect.equals(1, it.current); |
| 36 Expect.throws(it.moveNext, (e) => e == "FAIL"); |
| 37 // After throwing, iteration is ended. |
| 38 Expect.equals(null, it.current); |
| 39 Expect.isFalse(it.moveNext()); |
| 40 } |
| OLD | NEW |