| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 | 7 |
| 8 class MyList extends ListBase { | 8 class MyList extends ListBase { |
| 9 List list; | 9 List list; |
| 10 MyList(this.list); | 10 MyList(this.list); |
| 11 | 11 |
| 12 get length => list.length; | 12 get length => list.length; |
| 13 set length(val) { list.length = val; } | 13 set length(val) { |
| 14 list.length = val; |
| 15 } |
| 14 | 16 |
| 15 operator [](index) => list[index]; | 17 operator [](index) => list[index]; |
| 16 operator []=(index, val) => list[index] = val; | 18 operator []=(index, val) => list[index] = val; |
| 17 | 19 |
| 18 String toString() => "[" + join(", ") + "]"; | 20 String toString() => "[" + join(", ") + "]"; |
| 19 } | 21 } |
| 20 | 22 |
| 21 | |
| 22 main() { | 23 main() { |
| 23 test(expectation, iterable) { | 24 test(expectation, iterable) { |
| 24 Expect.listEquals(expectation, iterable.toList()); | 25 Expect.listEquals(expectation, iterable.toList()); |
| 25 } | 26 } |
| 26 | 27 |
| 27 // Function not called on empty iterable. | 28 // Function not called on empty iterable. |
| 28 test([], [].expand((x) { throw "not called"; })); | 29 test( |
| 30 [], |
| 31 [].expand((x) { |
| 32 throw "not called"; |
| 33 })); |
| 29 | 34 |
| 30 // Creating the iterable doesn't call the function. | 35 // Creating the iterable doesn't call the function. |
| 31 [1].expand((x) { throw "not called"; }); | 36 [1].expand((x) { |
| 37 throw "not called"; |
| 38 }); |
| 32 | 39 |
| 33 test([1], [1].expand((x) => [x])); | 40 test([1], [1].expand((x) => [x])); |
| 34 test([1, 2, 3], [1, 2, 3].expand((x) => [x])); | 41 test([1, 2, 3], [1, 2, 3].expand((x) => [x])); |
| 35 | 42 |
| 36 test([], [1].expand((x) => [])); | 43 test([], [1].expand((x) => [])); |
| 37 test([], [1, 2, 3].expand((x) => [])); | 44 test([], [1, 2, 3].expand((x) => [])); |
| 38 test([2], [1, 2, 3].expand((x) => x == 2 ? [2] : [])); | 45 test([2], [1, 2, 3].expand((x) => x == 2 ? [2] : [])); |
| 39 | 46 |
| 40 test([1, 1, 2, 2, 3, 3], [1, 2, 3].expand((x) => [x, x])); | 47 test([1, 1, 2, 2, 3, 3], [1, 2, 3].expand((x) => [x, x])); |
| 41 test([1, 1, 2], [1, 2, 3].expand((x) => [x, x, x].skip(x))); | 48 test([1, 1, 2], [1, 2, 3].expand((x) => [x, x, x].skip(x))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 58 Iterator it = iterable.iterator; | 65 Iterator it = iterable.iterator; |
| 59 Expect.isTrue(it.moveNext()); | 66 Expect.isTrue(it.moveNext()); |
| 60 Expect.equals(1, it.current); | 67 Expect.equals(1, it.current); |
| 61 Expect.isTrue(it.moveNext()); | 68 Expect.isTrue(it.moveNext()); |
| 62 Expect.equals(1, it.current); | 69 Expect.equals(1, it.current); |
| 63 Expect.throws(it.moveNext, (e) => e == "FAIL"); | 70 Expect.throws(it.moveNext, (e) => e == "FAIL"); |
| 64 // After throwing, iteration is ended. | 71 // After throwing, iteration is ended. |
| 65 Expect.equals(null, it.current); | 72 Expect.equals(null, it.current); |
| 66 Expect.isFalse(it.moveNext()); | 73 Expect.isFalse(it.moveNext()); |
| 67 } | 74 } |
| OLD | NEW |