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.map_test; |
| 16 |
| 17 import 'package:quiver/collection.dart'; |
| 18 import 'package:test/test.dart'; |
| 19 |
| 20 class MyMap extends DelegatingMap<String, int> { |
| 21 final Map<String, int> _delegate; |
| 22 |
| 23 MyMap(this._delegate); |
| 24 |
| 25 Map<String, int> get delegate => _delegate; |
| 26 } |
| 27 |
| 28 void main() { |
| 29 group('DelegatingMap', () { |
| 30 DelegatingMap<String, int> delegatingMap; |
| 31 |
| 32 setUp(() { |
| 33 delegatingMap = new MyMap({'a': 1, 'bb': 2}); |
| 34 }); |
| 35 |
| 36 test('[]', () { |
| 37 expect(delegatingMap['a'], equals(1)); |
| 38 expect(delegatingMap['bb'], equals(2)); |
| 39 expect(delegatingMap['c'], isNull); |
| 40 }); |
| 41 |
| 42 test('[]=', () { |
| 43 delegatingMap['a'] = 3; |
| 44 delegatingMap['c'] = 4; |
| 45 expect(delegatingMap, equals({'a': 3, 'bb': 2, 'c': 4})); |
| 46 }); |
| 47 |
| 48 test('addAll', () { |
| 49 delegatingMap.addAll({'a': 3, 'c': 4}); |
| 50 expect(delegatingMap, equals({'a': 3, 'bb': 2, 'c': 4})); |
| 51 }); |
| 52 |
| 53 test('clear', () { |
| 54 delegatingMap.clear(); |
| 55 expect(delegatingMap, equals({})); |
| 56 }); |
| 57 |
| 58 test('containsKey', () { |
| 59 expect(delegatingMap.containsKey('a'), isTrue); |
| 60 expect(delegatingMap.containsKey('b'), isFalse); |
| 61 }); |
| 62 |
| 63 test('containsValue', () { |
| 64 expect(delegatingMap.containsValue(1), isTrue); |
| 65 expect(delegatingMap.containsValue('b'), isFalse); |
| 66 }); |
| 67 |
| 68 test('forEach', () { |
| 69 final s = new StringBuffer(); |
| 70 delegatingMap.forEach((k, v) => s.write('$k$v')); |
| 71 expect(s.toString(), equals('a1bb2')); |
| 72 }); |
| 73 |
| 74 test('isEmpty', () { |
| 75 expect(delegatingMap.isEmpty, isFalse); |
| 76 expect(new MyMap({}).isEmpty, isTrue); |
| 77 }); |
| 78 |
| 79 test('isNotEmpty', () { |
| 80 expect(delegatingMap.isNotEmpty, isTrue); |
| 81 expect(new MyMap({}).isNotEmpty, isFalse); |
| 82 }); |
| 83 |
| 84 test('keys', () { |
| 85 expect(delegatingMap.keys, equals(['a', 'bb'])); |
| 86 }); |
| 87 |
| 88 test('length', () { |
| 89 expect(delegatingMap.length, equals(2)); |
| 90 expect(new MyMap({}).length, equals(0)); |
| 91 }); |
| 92 |
| 93 test('putIfAbsent', () { |
| 94 expect(delegatingMap.putIfAbsent('c', () => 4), equals(4)); |
| 95 expect(delegatingMap.putIfAbsent('c', () => throw ''), equals(4)); |
| 96 }); |
| 97 |
| 98 test('remove', () { |
| 99 expect(delegatingMap.remove('a'), equals(1)); |
| 100 expect(delegatingMap, equals({'bb': 2})); |
| 101 }); |
| 102 |
| 103 test('values', () { |
| 104 expect(delegatingMap.values, equals([1, 2])); |
| 105 }); |
| 106 }); |
| 107 } |
OLD | NEW |