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

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

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

Powered by Google App Engine
This is Rietveld 408576698