11import { describe , it , iit , ddescribe , expect , beforeEach } from 'angular2/test_lib' ;
22import { Reflector } from 'angular2/src/reflection/reflection' ;
33import { ReflectionCapabilities } from 'angular2/src/reflection/reflection_capabilities' ;
4- import { CONST } from 'angular2/src/facade/lang' ;
5-
6- class Annotation {
7- value ;
8-
9- @CONST ( )
10- constructor ( value ) {
11- this . value = value ;
12- }
13- }
4+ import { ClassDecorator , ParamDecorator , classDecorator , paramDecorator } from './reflector_common' ;
145
156class AType {
167 value ;
178
18- constructor ( value ) {
19- this . value = value ;
20- }
9+ constructor ( value ) { this . value = value ; }
2110}
2211
23- @Annotation ( 'class' )
24- class ClassWithAnnotations {
12+ @ClassDecorator ( 'class' )
13+ class ClassWithDecorators {
2514 a ;
2615 b ;
2716
28- constructor ( @Annotation ( "a" ) a :AType , @Annotation ( "b" ) b :AType ) {
17+ constructor ( @ParamDecorator ( "a" ) a : AType , @ParamDecorator ( "b" ) b : AType ) {
2918 this . a = a ;
3019 this . b = b ;
3120 }
3221}
3322
34- class ClassWithoutAnnotations {
35- constructor ( a , b ) { }
23+ class ClassWithoutDecorators {
24+ constructor ( a , b ) { }
3625}
3726
3827class TestObjWith11Args {
39- constructor ( a1 , a2 , a3 , a4 , a5 , a6 , a7 , a8 , a9 , a10 , a11 ) {
40- }
41- }
42-
43- @Annotation ( 'func' )
44- function testFunc ( @Annotation ( "a" ) a :AType , @Annotation ( "b" ) b :AType ) {
28+ constructor ( a1 , a2 , a3 , a4 , a5 , a6 , a7 , a8 , a9 , a10 , a11 ) { }
4529}
4630
4731class TestObj {
@@ -53,18 +37,14 @@ class TestObj {
5337 this . b = b ;
5438 }
5539
56- identity ( arg ) {
57- return arg ;
58- }
40+ identity ( arg ) { return arg ; }
5941}
6042
6143export function main ( ) {
6244 describe ( 'Reflector' , ( ) => {
6345 var reflector ;
6446
65- beforeEach ( ( ) => {
66- reflector = new Reflector ( new ReflectionCapabilities ( ) ) ;
67- } ) ;
47+ beforeEach ( ( ) => { reflector = new Reflector ( new ReflectionCapabilities ( ) ) ; } ) ;
6848
6949 describe ( "factory" , ( ) => {
7050 it ( "should create a factory for the given type" , ( ) => {
@@ -75,55 +55,46 @@ export function main() {
7555 } ) ;
7656
7757 it ( "should throw when more than 10 arguments" , ( ) => {
78- expect ( ( ) => reflector . factory ( TestObjWith11Args ) ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ) ) . toThrowError ( ) ;
58+ expect ( ( ) => reflector . factory ( TestObjWith11Args ) ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ) )
59+ . toThrowError ( ) ;
7960 } ) ;
8061
8162 it ( "should return a registered factory if available" , ( ) => {
82- reflector . registerType ( TestObj , { "factory" : ( ) => "fake" } ) ;
63+ reflector . registerType ( TestObj , { "factory" : ( ) => "fake" } ) ;
8364 expect ( reflector . factory ( TestObj ) ( ) ) . toEqual ( "fake" ) ;
8465 } ) ;
8566 } ) ;
8667
8768 describe ( "parameters" , ( ) => {
8869 it ( "should return an array of parameters for a type" , ( ) => {
89- var p = reflector . parameters ( ClassWithAnnotations ) ;
90- expect ( p ) . toEqual ( [ [ AType , new Annotation ( 'a' ) ] , [ AType , new Annotation ( 'b' ) ] ] ) ;
91- } ) ;
92-
93- it ( "should return an array of parameters for a function" , ( ) => {
94- var p = reflector . parameters ( testFunc ) ;
95- expect ( p ) . toEqual ( [ [ AType , new Annotation ( 'a' ) ] , [ AType , new Annotation ( 'b' ) ] ] ) ;
70+ var p = reflector . parameters ( ClassWithDecorators ) ;
71+ expect ( p ) . toEqual ( [ [ AType , paramDecorator ( 'a' ) ] , [ AType , paramDecorator ( 'b' ) ] ] ) ;
9672 } ) ;
9773
9874 it ( "should work for a class without annotations" , ( ) => {
99- var p = reflector . parameters ( ClassWithoutAnnotations ) ;
75+ var p = reflector . parameters ( ClassWithoutDecorators ) ;
10076 expect ( p . length ) . toEqual ( 2 ) ;
10177 } ) ;
10278
10379 it ( "should return registered parameters if available" , ( ) => {
104- reflector . registerType ( TestObj , { "parameters" : [ 1 , 2 ] } ) ;
105- expect ( reflector . parameters ( TestObj ) ) . toEqual ( [ 1 , 2 ] ) ;
80+ reflector . registerType ( TestObj , { "parameters" : [ 1 , 2 ] } ) ;
81+ expect ( reflector . parameters ( TestObj ) ) . toEqual ( [ 1 , 2 ] ) ;
10682 } ) ;
10783 } ) ;
10884
10985 describe ( "annotations" , ( ) => {
11086 it ( "should return an array of annotations for a type" , ( ) => {
111- var p = reflector . annotations ( ClassWithAnnotations ) ;
112- expect ( p ) . toEqual ( [ new Annotation ( 'class' ) ] ) ;
113- } ) ;
114-
115- it ( "should return an array of annotations for a function" , ( ) => {
116- var p = reflector . annotations ( testFunc ) ;
117- expect ( p ) . toEqual ( [ new Annotation ( 'func' ) ] ) ;
87+ var p = reflector . annotations ( ClassWithDecorators ) ;
88+ expect ( p ) . toEqual ( [ classDecorator ( 'class' ) ] ) ;
11889 } ) ;
11990
12091 it ( "should return registered annotations if available" , ( ) => {
121- reflector . registerType ( TestObj , { "annotations" : [ 1 , 2 ] } ) ;
122- expect ( reflector . annotations ( TestObj ) ) . toEqual ( [ 1 , 2 ] ) ;
92+ reflector . registerType ( TestObj , { "annotations" : [ 1 , 2 ] } ) ;
93+ expect ( reflector . annotations ( TestObj ) ) . toEqual ( [ 1 , 2 ] ) ;
12394 } ) ;
12495
12596 it ( "should work for a clas without annotations" , ( ) => {
126- var p = reflector . annotations ( ClassWithoutAnnotations ) ;
97+ var p = reflector . annotations ( ClassWithoutDecorators ) ;
12798 expect ( p ) . toEqual ( [ ] ) ;
12899 } ) ;
129100 } ) ;
@@ -135,7 +106,7 @@ export function main() {
135106 } ) ;
136107
137108 it ( "should return a registered getter if available" , ( ) => {
138- reflector . registerGetters ( { "abc" : ( obj ) => "fake" } ) ;
109+ reflector . registerGetters ( { "abc" : ( obj ) => "fake" } ) ;
139110 expect ( reflector . getter ( "abc" ) ( "anything" ) ) . toEqual ( "fake" ) ;
140111 } ) ;
141112 } ) ;
@@ -150,7 +121,7 @@ export function main() {
150121
151122 it ( "should return a registered setter if available" , ( ) => {
152123 var updateMe ;
153- reflector . registerSetters ( { "abc" : ( obj , value ) => { updateMe = value ; } } ) ;
124+ reflector . registerSetters ( { "abc" : ( obj , value ) => { updateMe = value ; } } ) ;
154125 reflector . setter ( "abc" ) ( "anything" , "fake" ) ;
155126
156127 expect ( updateMe ) . toEqual ( "fake" ) ;
@@ -165,7 +136,7 @@ export function main() {
165136 } ) ;
166137
167138 it ( "should return a registered method if available" , ( ) => {
168- reflector . registerMethods ( { "abc" : ( obj , args ) => args } ) ;
139+ reflector . registerMethods ( { "abc" : ( obj , args ) => args } ) ;
169140 expect ( reflector . method ( "abc" ) ( "anything" , [ "fake" ] ) ) . toEqual ( [ 'fake' ] ) ;
170141 } ) ;
171142 } ) ;
0 commit comments