|
| 1 | +library annotation_src_spec; |
| 2 | + |
| 3 | +import 'package:angular/core/annotation_src.dart'; |
| 4 | +import 'dart:mirrors'; |
| 5 | +import '../_specs.dart'; |
| 6 | + |
| 7 | +var _SYMBOL_NAME = new RegExp('"([^@]*).*"'); |
| 8 | +_getName(VariableMirror v) => _SYMBOL_NAME.firstMatch(v.simpleName.toString()).group(1); |
| 9 | + |
| 10 | +Map<String, dynamic> variables(x) { |
| 11 | + Map variables = {}; |
| 12 | + InstanceMirror mirror = reflect(x) as InstanceMirror; |
| 13 | + ClassMirror type = mirror.type; |
| 14 | + do { |
| 15 | + type.declarations.forEach((k,v) { |
| 16 | + if (v is VariableMirror && !v.isStatic) { |
| 17 | + variables[_getName(v)] = mirror.getField(v.simpleName).reflectee; |
| 18 | + } |
| 19 | + }); |
| 20 | + } while ((type = type.superclass) != null); |
| 21 | + |
| 22 | + return variables; |
| 23 | +} |
| 24 | + |
| 25 | +List<String> nullFields(x) { |
| 26 | + var ret = []; |
| 27 | + variables(x).forEach((k, v) { |
| 28 | + if (v == null) ret.add(k); |
| 29 | + }); |
| 30 | + return ret; |
| 31 | +} |
| 32 | + |
| 33 | +void main() => describe('annotations', () { |
| 34 | + describe('component', () { |
| 35 | + it('should set all fields on clone when all the fields are set', () { |
| 36 | + var component = new Component( |
| 37 | + template: '', |
| 38 | + templateUrl: '', |
| 39 | + cssUrl: [''], |
| 40 | + applyAuthorStyles: true, |
| 41 | + resetStyleInheritance: true, |
| 42 | + publishAs: '', |
| 43 | + module: (){}, |
| 44 | + map: {}, |
| 45 | + selector: '', |
| 46 | + visibility: Directive.LOCAL_VISIBILITY, |
| 47 | + exportExpressions: [], |
| 48 | + exportExpressionAttrs: [] |
| 49 | + ); |
| 50 | + |
| 51 | + // Check that no fields are null |
| 52 | + expect(nullFields(component)).toEqual([]); |
| 53 | + |
| 54 | + // Check that the clone is the same as the original. |
| 55 | + expect(variables(cloneWithNewMap(component, {}))).toEqual(variables(component)); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('decorator', () { |
| 60 | + it('should set all fields on clone when all the fields are set', () { |
| 61 | + var decorator = new Decorator( |
| 62 | + children: 'xxx', |
| 63 | + map: {}, |
| 64 | + selector: '', |
| 65 | + module: (){}, |
| 66 | + visibility: Directive.LOCAL_VISIBILITY, |
| 67 | + exportExpressions: [], |
| 68 | + exportExpressionAttrs: [] |
| 69 | + ); |
| 70 | + |
| 71 | + // Check that no fields are null |
| 72 | + expect(nullFields(decorator)).toEqual([]); |
| 73 | + |
| 74 | + // Check that the clone is the same as the original. |
| 75 | + expect(variables(cloneWithNewMap(decorator, {}))).toEqual(variables(decorator)); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + describe('controller', () { |
| 80 | + it('should set all fields on clone when all the fields are set', () { |
| 81 | + var controller = new Controller( |
| 82 | + publishAs: '', |
| 83 | + children: 'xxx', |
| 84 | + map: {}, |
| 85 | + selector: '', |
| 86 | + module: (){}, |
| 87 | + visibility: Directive.LOCAL_VISIBILITY, |
| 88 | + exportExpressions: [], |
| 89 | + exportExpressionAttrs: [] |
| 90 | + ); |
| 91 | + |
| 92 | + // Check that no fields are null |
| 93 | + expect(nullFields(controller)).toEqual([]); |
| 94 | + |
| 95 | + // Check that the clone is the same as the original. |
| 96 | + expect(variables(cloneWithNewMap(controller, {}))).toEqual(variables(controller)); |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
0 commit comments