OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 Google Inc. All Rights Reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 library quiver.collection.delegates.list_test; |
| 16 |
| 17 import 'package:quiver/collection.dart'; |
| 18 import 'package:test/test.dart'; |
| 19 |
| 20 class MyList extends DelegatingList<String> { |
| 21 final List<String> _delegate; |
| 22 |
| 23 MyList(this._delegate); |
| 24 |
| 25 List<String> get delegate => _delegate; |
| 26 } |
| 27 |
| 28 void main() { |
| 29 group('DelegatingList', () { |
| 30 DelegatingList<String> delegatingList; |
| 31 |
| 32 setUp(() { |
| 33 delegatingList = new MyList(['a', 'b', 'cc']); |
| 34 }); |
| 35 |
| 36 test('[]', () { |
| 37 expect(delegatingList[0], equals('a')); |
| 38 expect(delegatingList[1], equals('b')); |
| 39 expect(delegatingList[2], equals('cc')); |
| 40 expect(() => delegatingList[3], throws); |
| 41 }); |
| 42 |
| 43 test('[]=', () { |
| 44 delegatingList[0] = 'd'; |
| 45 expect(delegatingList, equals(['d', 'b', 'cc'])); |
| 46 }); |
| 47 |
| 48 test('add', () { |
| 49 delegatingList.add('d'); |
| 50 expect(delegatingList, equals(['a', 'b', 'cc', 'd'])); |
| 51 }); |
| 52 |
| 53 test('addAll', () { |
| 54 delegatingList.addAll(['d', 'e']); |
| 55 expect(delegatingList, equals(['a', 'b', 'cc', 'd', 'e'])); |
| 56 }); |
| 57 |
| 58 test('asMap', () { |
| 59 expect(delegatingList.asMap(), equals({0: 'a', 1: 'b', 2: 'cc'})); |
| 60 }); |
| 61 |
| 62 test('clear', () { |
| 63 delegatingList.clear(); |
| 64 expect(delegatingList, equals([])); |
| 65 }); |
| 66 |
| 67 test('fillRange', () { |
| 68 delegatingList.fillRange(0, 2); |
| 69 expect(delegatingList, equals([null, null, 'cc'])); |
| 70 delegatingList.fillRange(0, 2, 'd'); |
| 71 expect(delegatingList, equals(['d', 'd', 'cc'])); |
| 72 }); |
| 73 |
| 74 test('getRange', () { |
| 75 expect(delegatingList.getRange(1, 2), equals(['b'])); |
| 76 expect(delegatingList.getRange(1, 3), equals(['b', 'cc'])); |
| 77 }); |
| 78 |
| 79 test('indexOf', () { |
| 80 expect(delegatingList.indexOf('b'), equals(1)); |
| 81 expect(delegatingList.indexOf('a', 1), equals(-1)); |
| 82 expect(delegatingList.indexOf('cc', 1), equals(2)); |
| 83 }); |
| 84 |
| 85 test('insert', () { |
| 86 delegatingList.insert(1, 'd'); |
| 87 expect(delegatingList, equals(['a', 'd', 'b', 'cc'])); |
| 88 }); |
| 89 |
| 90 test('insertAll', () { |
| 91 delegatingList.insertAll(1, ['d', 'e']); |
| 92 expect(delegatingList, equals(['a', 'd', 'e', 'b', 'cc'])); |
| 93 }); |
| 94 |
| 95 test('lastIndexOf', () { |
| 96 expect(delegatingList.lastIndexOf('b'), equals(1)); |
| 97 expect(delegatingList.lastIndexOf('a', 1), equals(0)); |
| 98 expect(delegatingList.lastIndexOf('cc', 1), equals(-1)); |
| 99 }); |
| 100 |
| 101 test('set length', () { |
| 102 delegatingList.length = 2; |
| 103 expect(delegatingList, equals(['a', 'b'])); |
| 104 }); |
| 105 |
| 106 test('remove', () { |
| 107 delegatingList.remove('b'); |
| 108 expect(delegatingList, equals(['a', 'cc'])); |
| 109 }); |
| 110 |
| 111 test('removeAt', () { |
| 112 delegatingList.removeAt(1); |
| 113 expect(delegatingList, equals(['a', 'cc'])); |
| 114 }); |
| 115 |
| 116 test('removeLast', () { |
| 117 delegatingList.removeLast(); |
| 118 expect(delegatingList, equals(['a', 'b'])); |
| 119 }); |
| 120 |
| 121 test('removeRange', () { |
| 122 delegatingList.removeRange(1, 2); |
| 123 expect(delegatingList, equals(['a', 'cc'])); |
| 124 }); |
| 125 |
| 126 test('removeWhere', () { |
| 127 delegatingList.removeWhere((e) => e.length == 1); |
| 128 expect(delegatingList, equals(['cc'])); |
| 129 }); |
| 130 |
| 131 test('replaceRange', () { |
| 132 delegatingList.replaceRange(1, 2, ['d', 'e']); |
| 133 expect(delegatingList, equals(['a', 'd', 'e', 'cc'])); |
| 134 }); |
| 135 |
| 136 test('retainWhere', () { |
| 137 delegatingList.retainWhere((e) => e.length == 1); |
| 138 expect(delegatingList, equals(['a', 'b'])); |
| 139 }); |
| 140 |
| 141 test('reversed', () { |
| 142 expect(delegatingList.reversed, equals(['cc', 'b', 'a'])); |
| 143 }); |
| 144 |
| 145 test('setAll', () { |
| 146 delegatingList.setAll(1, ['d', 'e']); |
| 147 expect(delegatingList, equals(['a', 'd', 'e'])); |
| 148 }); |
| 149 |
| 150 test('setRange', () { |
| 151 delegatingList.setRange(1, 3, ['d', 'e']); |
| 152 expect(delegatingList, equals(['a', 'd', 'e'])); |
| 153 }); |
| 154 |
| 155 test('sort', () { |
| 156 delegatingList.sort((a, b) => b.codeUnitAt(0) - a.codeUnitAt(0)); |
| 157 expect(delegatingList, equals(['cc', 'b', 'a'])); |
| 158 }); |
| 159 |
| 160 test('sublist', () { |
| 161 expect(delegatingList.sublist(1), equals(['b', 'cc'])); |
| 162 expect(delegatingList.sublist(1, 2), equals(['b'])); |
| 163 }); |
| 164 }); |
| 165 } |
OLD | NEW |