1
1
library angular2.test.compiler.static_reflector_spec;
2
2
3
- import "package:angular2/testing_internal.dart"
4
- show
5
- ddescribe,
6
- describe,
7
- xdescribe,
8
- it,
9
- iit,
10
- xit,
11
- expect,
12
- beforeEach,
13
- afterEach,
14
- AsyncTestCompleter,
15
- inject,
16
- beforeEachProviders;
3
+ import "package:angular2/testing_internal.dart" show describe, it, expect;
4
+ import "package:angular2/src/facade/collection.dart" show ListWrapper;
17
5
import "package:angular2/src/compiler/static_reflector.dart"
18
6
show StaticReflector, StaticReflectorHost;
19
7
20
8
main () {
21
- describe ("StaticRefelector " , () {
9
+ describe ("StaticReflector " , () {
22
10
it ("should get annotations for NgFor" , () {
23
11
var host = new MockReflectorHost ();
24
12
var reflector = new StaticReflector (host);
25
13
var NgFor = reflector.getStaticType (
26
- "angular2/src/common/directives/ng_for" , "NgFor" );
14
+ host. resolveModule ( "angular2/src/common/directives/ng_for" ) , "NgFor" );
27
15
var annotations = reflector.annotations (NgFor );
28
16
expect (annotations.length).toEqual (1 );
29
17
var annotation = annotations[0 ];
@@ -35,16 +23,20 @@ main() {
35
23
var host = new MockReflectorHost ();
36
24
var reflector = new StaticReflector (host);
37
25
var NgFor = reflector.getStaticType (
38
- "angular2/src/common/directives/ng_for" , "NgFor" );
26
+ host. resolveModule ( "angular2/src/common/directives/ng_for" ) , "NgFor" );
39
27
var ViewContainerRef = reflector.getStaticType (
40
- "angular2/src/core/linker/view_container_ref" , "ViewContainerRef" );
28
+ host.resolveModule ("angular2/src/core/linker/view_container_ref" ),
29
+ "ViewContainerRef" );
41
30
var TemplateRef = reflector.getStaticType (
42
- "angular2/src/core/linker/template_ref" , "TemplateRef" );
31
+ host.resolveModule ("angular2/src/core/linker/template_ref" ),
32
+ "TemplateRef" );
43
33
var IterableDiffers = reflector.getStaticType (
44
- "angular2/src/core/change_detection/differs/iterable_differs" ,
34
+ host.resolveModule (
35
+ "angular2/src/core/change_detection/differs/iterable_differs" ),
45
36
"IterableDiffers" );
46
37
var ChangeDetectorRef = reflector.getStaticType (
47
- "angular2/src/core/change_detection/change_detector_ref" ,
38
+ host.resolveModule (
39
+ "angular2/src/core/change_detection/change_detector_ref" ),
48
40
"ChangeDetectorRef" );
49
41
var parameters = reflector.parameters (NgFor );
50
42
expect (parameters).toEqual (
@@ -54,7 +46,7 @@ main() {
54
46
var host = new MockReflectorHost ();
55
47
var reflector = new StaticReflector (host);
56
48
var HeroDetailComponent = reflector.getStaticType (
57
- "./ app/hero-detail.component" , "HeroDetailComponent" );
49
+ "/src/ app/hero-detail.component.ts " , "HeroDetailComponent" );
58
50
var annotations = reflector.annotations (HeroDetailComponent );
59
51
expect (annotations.length).toEqual (1 );
60
52
var annotation = annotations[0 ];
@@ -64,31 +56,31 @@ main() {
64
56
var host = new MockReflectorHost ();
65
57
var reflector = new StaticReflector (host);
66
58
var UnknownClass =
67
- reflector.getStaticType ("./ app/app.component" , "UnknownClass" );
59
+ reflector.getStaticType ("/src/ app/app.component.ts " , "UnknownClass" );
68
60
var annotations = reflector.annotations (UnknownClass );
69
61
expect (annotations).toEqual ([]);
70
62
});
71
63
it ("should get propMetadata for HeroDetailComponent" , () {
72
64
var host = new MockReflectorHost ();
73
65
var reflector = new StaticReflector (host);
74
66
var HeroDetailComponent = reflector.getStaticType (
75
- "./ app/hero-detail.component" , "HeroDetailComponent" );
67
+ "/src/ app/hero-detail.component.ts " , "HeroDetailComponent" );
76
68
var props = reflector.propMetadata (HeroDetailComponent );
77
69
expect (props["hero" ]).toBeTruthy ();
78
70
});
79
71
it ("should get an empty object from propMetadata for an unknown class" , () {
80
72
var host = new MockReflectorHost ();
81
73
var reflector = new StaticReflector (host);
82
74
var UnknownClass =
83
- reflector.getStaticType ("./ app/app.component" , "UnknownClass" );
75
+ reflector.getStaticType ("/src/ app/app.component.ts " , "UnknownClass" );
84
76
var properties = reflector.propMetadata (UnknownClass );
85
77
expect (properties).toEqual ({});
86
78
});
87
79
it ("should get empty parameters list for an unknown class " , () {
88
80
var host = new MockReflectorHost ();
89
81
var reflector = new StaticReflector (host);
90
82
var UnknownClass =
91
- reflector.getStaticType ("./ app/app.component" , "UnknownClass" );
83
+ reflector.getStaticType ("/src/ app/app.component.ts " , "UnknownClass" );
92
84
var parameters = reflector.parameters (UnknownClass );
93
85
expect (parameters).toEqual ([]);
94
86
});
@@ -583,7 +575,7 @@ main() {
583
575
"" , ({"___symbolic" : "pre" , "operator" : "!" , "operand" : false })))
584
576
.toBe (! false );
585
577
});
586
- it ("should simpify an array index" , () {
578
+ it ("should simplify an array index" , () {
587
579
var host = new MockReflectorHost ();
588
580
var reflector = new StaticReflector (host);
589
581
expect (reflector.simplify (
@@ -609,7 +601,7 @@ main() {
609
601
var host = new MockReflectorHost ();
610
602
var reflector = new StaticReflector (host);
611
603
expect (reflector.simplify (
612
- ". /cases" ,
604
+ "/src /cases" ,
613
605
({
614
606
"___symbolic" : "reference" ,
615
607
"module" : "./extern" ,
@@ -621,11 +613,46 @@ main() {
621
613
}
622
614
623
615
class MockReflectorHost implements StaticReflectorHost {
616
+ String resolveModule (String moduleName, [String containingFile]) {
617
+ List <String > splitPath (String path) {
618
+ return path.split (new RegExp (r'\/|\\' ));
619
+ }
620
+ String resolvePath (List <String > pathParts) {
621
+ var result = [];
622
+ ListWrapper .forEachWithIndex (pathParts, (part, index) {
623
+ switch (part) {
624
+ case "" :
625
+ case "." :
626
+ if (index > 0 ) return ;
627
+ break ;
628
+ case ".." :
629
+ if (index > 0 && result.length != 0 ) result.removeLast ();
630
+ return ;
631
+ }
632
+ result.add (part);
633
+ });
634
+ return result.join ("/" );
635
+ }
636
+ String pathTo (String from, String to) {
637
+ var result = to;
638
+ if (to.startsWith ("." )) {
639
+ var fromParts = splitPath (from);
640
+ fromParts.removeLast ();
641
+ var toParts = splitPath (to);
642
+ result = resolvePath ((new List .from (fromParts)..addAll (toParts)));
643
+ }
644
+ return result;
645
+ }
646
+ if (identical (moduleName.indexOf ("." ), 0 )) {
647
+ return pathTo (containingFile, moduleName) + ".d.ts" ;
648
+ }
649
+ return "/tmp/" + moduleName + ".d.ts" ;
650
+ }
651
+
624
652
dynamic getMetadataFor (String moduleId) {
625
653
return {
626
- "angular2/src/common/directives/ng_for" : {
654
+ "/tmp/ angular2/src/common/directives/ng_for.d.ts " : {
627
655
"___symbolic" : "module" ,
628
- "module" : "./ng_for" ,
629
656
"metadata" : {
630
657
"NgFor" : {
631
658
"___symbolic" : "class" ,
@@ -679,33 +706,29 @@ class MockReflectorHost implements StaticReflectorHost {
679
706
}
680
707
}
681
708
},
682
- "angular2/src/core/linker/view_container_ref" : {
683
- "module" : "./view_container_ref" ,
709
+ "/tmp/angular2/src/core/linker/view_container_ref.d.ts" : {
684
710
"metadata" : {
685
711
"ViewContainerRef" : {"___symbolic" : "class" }
686
712
}
687
713
},
688
- "angular2/src/core/linker/template_ref" : {
714
+ "/tmp/ angular2/src/core/linker/template_ref.d.ts " : {
689
715
"module" : "./template_ref" ,
690
716
"metadata" : {
691
717
"TemplateRef" : {"___symbolic" : "class" }
692
718
}
693
719
},
694
- "angular2/src/core/change_detection/differs/iterable_differs" : {
695
- "module" : "./iterable_differs" ,
720
+ "/tmp/angular2/src/core/change_detection/differs/iterable_differs.d.ts" : {
696
721
"metadata" : {
697
722
"IterableDiffers" : {"___symbolic" : "class" }
698
723
}
699
724
},
700
- "angular2/src/core/change_detection/change_detector_ref" : {
701
- "module" : "./change_detector_ref" ,
725
+ "/tmp/angular2/src/core/change_detection/change_detector_ref.d.ts" : {
702
726
"metadata" : {
703
727
"ChangeDetectorRef" : {"___symbolic" : "class" }
704
728
}
705
729
},
706
- "./ app/hero-detail.component" : {
730
+ "/src/ app/hero-detail.component.ts " : {
707
731
"___symbolic" : "module" ,
708
- "module" : "./hero-detail.component" ,
709
732
"metadata" : {
710
733
"HeroDetailComponent" : {
711
734
"___symbolic" : "class" ,
@@ -746,9 +769,8 @@ class MockReflectorHost implements StaticReflectorHost {
746
769
}
747
770
}
748
771
},
749
- "./ extern" : {
772
+ "/src/ extern.d.ts " : {
750
773
"___symbolic" : "module" ,
751
- "module" : "./extern" ,
752
774
"metadata" : {"s" : "s" }
753
775
}
754
776
}[moduleId];
0 commit comments