| OLD | NEW |
| 1 library registry_spec; | 1 library registry_spec; |
| 2 | 2 |
| 3 import '../_specs.dart'; | 3 import '../_specs.dart'; |
| 4 import 'package:angular/application_factory.dart'; |
| 4 | 5 |
| 5 main() => describe('RegistryMap', () { | 6 main() { |
| 6 it('should allow for multiple registry keys to be added', () { | 7 describe('RegistryMap', () { |
| 7 var module = new Module() | 8 it('should allow for multiple registry keys to be added', () { |
| 8 ..type(MyMap) | 9 var module = new Module() |
| 9 ..type(MetadataExtractor) | 10 ..type(MyMap) |
| 10 ..type(A1) | 11 ..type(A1) |
| 11 ..type(A2); | 12 ..type(A2); |
| 12 | 13 |
| 13 var injector = new DynamicInjector(modules: [module]); | 14 var injector = applicationFactory().addModule(module).createInjector(); |
| 14 expect(() { | 15 expect(() { |
| 15 injector.get(MyMap); | 16 injector.get(MyMap); |
| 16 }).not.toThrow(); | 17 }).not.toThrow(); |
| 18 }); |
| 19 |
| 20 it('should iterate over all types', () { |
| 21 var module = new Module() |
| 22 ..type(MyMap) |
| 23 ..type(A1); |
| 24 |
| 25 var injector = applicationFactory().addModule(module).createInjector(); |
| 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 it('should safely ignore typedefs', () { |
| 35 var module = new Module() |
| 36 ..type(MyMap) |
| 37 ..value(MyTypedef, (String _) => null); |
| 38 |
| 39 var injector = applicationFactory().addModule(module).createInjector(); |
| 40 expect(() => injector.get(MyMap), isNot(throws)); |
| 41 }); |
| 17 }); | 42 }); |
| 18 | 43 } |
| 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 it('should safely ignore typedefs', () { | |
| 35 var module = new Module() | |
| 36 ..type(MyMap) | |
| 37 ..type(MetadataExtractor) | |
| 38 ..value(MyTypedef, (String _) => null); | |
| 39 | |
| 40 var injector = new DynamicInjector(modules: [module]); | |
| 41 expect(() => injector.get(MyMap), isNot(throws)); | |
| 42 }); | |
| 43 }); | |
| 44 | 44 |
| 45 typedef void MyTypedef(String arg); | 45 typedef void MyTypedef(String arg); |
| 46 | 46 |
| 47 class MyMap extends AnnotationMap<MyAnnotation> { | 47 class MyMap extends AnnotationMap<MyAnnotation> { |
| 48 MyMap(Injector injector, MetadataExtractor metadataExtractor) | 48 MyMap(Injector injector, MetadataExtractor metadataExtractor) |
| 49 : super(injector, metadataExtractor); | 49 : super(injector, metadataExtractor); |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 class MyAnnotation { | 53 class MyAnnotation { |
| 54 final String name; | 54 final String name; |
| 55 | 55 |
| 56 const MyAnnotation(String this.name); | 56 const MyAnnotation(String this.name); |
| 57 | 57 |
| 58 toString() => name; | 58 toString() => name; |
| 59 get hashCode => name.hashCode; | 59 get hashCode => name.hashCode; |
| 60 operator==(other) => this.name == other.name; | 60 operator==(other) => this.name == other.name; |
| 61 } | 61 } |
| 62 | 62 |
| 63 @MyAnnotation('A') @MyAnnotation('B') class A1 {} | 63 @MyAnnotation('A') @MyAnnotation('B') class A1 {} |
| 64 @MyAnnotation('A') class A2 {} | 64 @MyAnnotation('A') class A2 {} |
| OLD | NEW |