Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: third_party/pkg/angular/test/tools/source_metadata_extractor_spec.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 library source_metadata_extractor_spec;
2
3 import 'package:analyzer/src/generated/ast.dart';
4 import 'package:angular/tools/common.dart';
5 import 'package:angular/tools/source_crawler.dart';
6 import 'package:angular/tools/source_metadata_extractor.dart';
7 import 'package:unittest/unittest.dart';
8
9 import '../jasmine_syntax.dart';
10
11 main() => describe('SourceMetadataExtractor', () {
12
13 it('should extract expressions and attribute names with expressions', () {
14 var info = extractDirectiveInfo([
15 new DirectiveMetadata('FooComponent', COMPONENT, null, {
16 'barVal': '@bar',
17 'bazExpr1': '<=>baz1',
18 'bazExpr2': '=>baz2',
19 'bazExpr3': '=>!baz3',
20 'bazCallback': '&aux',
21 })
22 ]);
23
24 expect(flattenList(info, (DirectiveInfo i) => i.expressionAttrs),
25 equals(['baz-expr1',
26 'baz-expr2',
27 'baz-expr3',
28 'baz-callback']));
29 expect(flattenList(info, (DirectiveInfo i) => i.expressions),
30 equals(['bar',
31 'baz1',
32 'baz2',
33 'baz3',
34 'aux']));
35 });
36
37 it('should build a component selector if one is not explicitly specified', () {
38 var info = extractDirectiveInfo([
39 new DirectiveMetadata('MyFooComponent', COMPONENT, null, {
40 'foo-expr': '=>fooExpr'
41 })
42 ]);
43
44 expect(info, hasLength(1));
45 expect(info[0].selector, equals('my-foo'));
46 });
47
48 it('should build an element directive selector if one is not explicitly specif ied', () {
49 var info = extractDirectiveInfo([
50 new DirectiveMetadata('MyFooDirective', DIRECTIVE, null, {
51 'foo-expr': '=>fooExpr'
52 })
53 ]);
54
55 expect(info, hasLength(1));
56 expect(info[0].selector, equals('my-foo'));
57 });
58
59 it('should build an attr directive selector if one is not explicitly specified ', () {
60 var info = extractDirectiveInfo([
61 new DirectiveMetadata('MyFooAttrDirective', DIRECTIVE, null, {
62 'foo-expr': '=>fooExpr'
63 })
64 ]);
65
66 expect(info, hasLength(1));
67 expect(info[0].selector, equals('[my-foo]'));
68 });
69
70 it('should figure out attribute name if dot(.) is used', () {
71 var info = extractDirectiveInfo([
72 new DirectiveMetadata('MyFooAttrDirective', DIRECTIVE, null, {
73 '.': '=>fooExpr'
74 })
75 ]);
76
77 expect(flattenList(info, (DirectiveInfo i) => i.expressionAttrs),
78 equals(['my-foo']));
79 });
80
81 it('should figure out attribute name from selector if dot(.) is used', () {
82 var info = extractDirectiveInfo([
83 new DirectiveMetadata('MyFooAttrDirective', DIRECTIVE, '[blah][foo]', {
84 '.': '=>fooExpr'
85 })
86 ]);
87
88 expect(flattenList(info, (DirectiveInfo i) => i.expressionAttrs),
89 equals(['foo']));
90 });
91
92 it('should include exported expression attributes', () {
93 var info = extractDirectiveInfo([
94 new DirectiveMetadata('MyFooAttrDirective', DIRECTIVE, '[blah][foo]', {
95 '.': '=>fooExpr'
96 }, ['baz'])
97 ]);
98
99 expect(flattenList(info, (DirectiveInfo i) => i.expressionAttrs),
100 equals(['foo', 'baz']));
101 });
102
103 it('should include exported expressions', () {
104 var info = extractDirectiveInfo([
105 new DirectiveMetadata('MyFooAttrDirective', DIRECTIVE, '[blah][foo]', {
106 '.': '=>fooExpr'
107 }, null, ['ctrl.baz'])
108 ]);
109
110 expect(flattenList(info, (DirectiveInfo i) => i.expressions),
111 equals(['fooExpr', 'ctrl.baz']));
112 });
113
114 });
115
116 flattenList(list, map) => list.map(map).fold([], (prev, exprs) =>
117 new List.from(prev)..addAll(exprs));
118
119 List<DirectiveInfo> extractDirectiveInfo(List<DirectiveMetadata> metadata) {
120 var sourceCrawler = new MockSourceCrawler();
121 var metadataCollector = new MockDirectiveMetadataCollectingVisitor(metadata);
122 var extractor = new SourceMetadataExtractor(sourceCrawler, metadataCollector);
123 return extractor.gatherDirectiveInfo('');
124 }
125
126 class MockDirectiveMetadataCollectingVisitor
127 implements DirectiveMetadataCollectingVisitor {
128 List<DirectiveMetadata> metadata;
129
130 MockDirectiveMetadataCollectingVisitor(List<DirectiveMetadata> this.metadata);
131
132 call(CompilationUnit cu) {
133 // do nothing
134 }
135 }
136
137 class MockSourceCrawler implements SourceCrawler {
138
139 void crawl(String entryPoint, visitor(CompilationUnit cu)) {
140 // do nothing
141 }
142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698