| OLD | NEW |
| (Empty) | |
| 1 library registry_spec; |
| 2 |
| 3 import '../_specs.dart'; |
| 4 |
| 5 main() => describe('RegistryMap', () { |
| 6 it('should throw error on identical keys', () { |
| 7 var module = new Module() |
| 8 ..type(MyMap) |
| 9 ..type(MetadataExtractor) |
| 10 ..type(A1) |
| 11 ..type(A2); |
| 12 |
| 13 var injector = new DynamicInjector(modules: [module]); |
| 14 expect(() { |
| 15 injector.get(MyMap); |
| 16 }).toThrow("Duplicate annotation found: MyAnnotation: A. Exisitng:"); |
| 17 }); |
| 18 |
| 19 it('should iterate over all types', () { |
| 20 var module = new Module() |
| 21 ..type(MyMap) |
| 22 ..type(MetadataExtractor) |
| 23 ..type(A1); |
| 24 |
| 25 var injector = new DynamicInjector(modules: [module]); |
| 26 var keys = []; |
| 27 var types = []; |
| 28 var map = injector.get(MyMap); |
| 29 map.forEach((k, t) { keys.add(k); types.add(t); }); |
| 30 expect(keys).toEqual([new MyAnnotation('A'), new MyAnnotation('B')]); |
| 31 expect(types).toEqual([A1, A1]); |
| 32 }); |
| 33 }); |
| 34 |
| 35 class MyMap extends AnnotationMap<MyAnnotation> { |
| 36 MyMap(Injector injector, MetadataExtractor metadataExtractor) |
| 37 : super(injector, metadataExtractor); |
| 38 } |
| 39 |
| 40 |
| 41 class MyAnnotation { |
| 42 final String name; |
| 43 |
| 44 const MyAnnotation(String this.name); |
| 45 |
| 46 toString() => name; |
| 47 get hashCode => name.hashCode; |
| 48 operator==(other) => this.name == other.name; |
| 49 } |
| 50 |
| 51 @MyAnnotation('A') @MyAnnotation('B') class A1 {} |
| 52 @MyAnnotation('A') class A2 {} |
| OLD | NEW |