| OLD | NEW |
| 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 main() => describe('SourceMetadataExtractor', () { | 11 main() => describe('SourceMetadataExtractor', () { |
| 12 | 12 |
| 13 it('should extract expressions and attribute names with expressions', () { | 13 it('should extract expressions and attribute names with expressions', () { |
| 14 var info = extractDirectiveInfo([ | 14 var info = extractDirectiveInfo([ |
| 15 new DirectiveMetadata('FooComponent', COMPONENT, 'foo-component', { | 15 new DirectiveMetadata('FooComponent', COMPONENT, null, { |
| 16 'barVal': '@bar', | 16 'barVal': '@bar', |
| 17 'baz-expr1': '<=>baz1', | 17 'bazExpr1': '<=>baz1', |
| 18 'baz-expr2': '=>baz2', | 18 'bazExpr2': '=>baz2', |
| 19 'baz-expr3': '=>!baz3', | 19 'bazExpr3': '=>!baz3', |
| 20 'baz-callback': '&aux', | 20 'bazCallback': '&aux', |
| 21 }) | 21 }) |
| 22 ]); | 22 ]); |
| 23 | 23 |
| 24 expect(flattenList(info, (DirectiveInfo i) => i.expressionAttrs), | 24 expect(flattenList(info, (DirectiveInfo i) => i.expressionAttrs), |
| 25 equals(['baz-expr1', | 25 equals(['baz-expr1', |
| 26 'baz-expr2', | 26 'baz-expr2', |
| 27 'baz-expr3', | 27 'baz-expr3', |
| 28 'baz-callback'])); | 28 'baz-callback'])); |
| 29 expect(flattenList(info, (DirectiveInfo i) => i.expressions), | 29 expect(flattenList(info, (DirectiveInfo i) => i.expressions), |
| 30 equals(['bar', | 30 equals(['bar', |
| 31 'baz1', | 31 'baz1', |
| 32 'baz2', | 32 'baz2', |
| 33 'baz3', | 33 'baz3', |
| 34 'aux'])); | 34 'aux'])); |
| 35 }); | 35 }); |
| 36 | 36 |
| 37 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', ()
{ |
| 38 var info = extractDirectiveInfo([ | 38 var info = extractDirectiveInfo([ |
| 39 new DirectiveMetadata('MyFooComponent', COMPONENT, 'my-foo', { | 39 new DirectiveMetadata('MyFooComponent', COMPONENT, null, { |
| 40 'foo-expr': '=>fooExpr' | 40 'foo-expr': '=>fooExpr' |
| 41 }) | 41 }) |
| 42 ]); | 42 ]); |
| 43 | 43 |
| 44 expect(info, hasLength(1)); | 44 expect(info, hasLength(1)); |
| 45 expect(info[0].selector, equals('my-foo')); | 45 expect(info[0].selector, equals('my-foo')); |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 it('should build an element directive selector if one is not explicitly specif
ied', () { | 48 it('should build an element directive selector if one is not explicitly specif
ied', () { |
| 49 var info = extractDirectiveInfo([ | 49 var info = extractDirectiveInfo([ |
| 50 new DirectiveMetadata('MyFooDirective', DIRECTIVE, 'my-foo', { | 50 new DirectiveMetadata('MyFooDirective', DIRECTIVE, null, { |
| 51 'foo-expr': '=>fooExpr' | 51 'foo-expr': '=>fooExpr' |
| 52 }) | 52 }) |
| 53 ]); | 53 ]); |
| 54 | 54 |
| 55 expect(info, hasLength(1)); | 55 expect(info, hasLength(1)); |
| 56 expect(info[0].selector, equals('my-foo')); | 56 expect(info[0].selector, equals('my-foo')); |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 it('should build an attr directive selector if one is not explicitly specified
', () { | 59 it('should build an attr directive selector if one is not explicitly specified
', () { |
| 60 var info = extractDirectiveInfo([ | 60 var info = extractDirectiveInfo([ |
| 61 new DirectiveMetadata('MyFooAttrDirective', '[my-foo]', '[my-foo]', { | 61 new DirectiveMetadata('MyFooAttrDirective', DIRECTIVE, null, { |
| 62 'foo-expr': '=>fooExpr' | 62 'foo-expr': '=>fooExpr' |
| 63 }) | 63 }) |
| 64 ]); | 64 ]); |
| 65 | 65 |
| 66 expect(info, hasLength(1)); | 66 expect(info, hasLength(1)); |
| 67 expect(info[0].selector, equals('[my-foo]')); | 67 expect(info[0].selector, equals('[my-foo]')); |
| 68 }); | 68 }); |
| 69 | 69 |
| 70 it('should figure out attribute name if dot(.) is used', () { | 70 it('should figure out attribute name if dot(.) is used', () { |
| 71 var info = extractDirectiveInfo([ | 71 var info = extractDirectiveInfo([ |
| 72 new DirectiveMetadata('MyFooAttrDirective', DIRECTIVE, '[my-foo]', { | 72 new DirectiveMetadata('MyFooAttrDirective', DIRECTIVE, null, { |
| 73 '.': '=>fooExpr' | 73 '.': '=>fooExpr' |
| 74 }) | 74 }) |
| 75 ]); | 75 ]); |
| 76 | 76 |
| 77 expect(flattenList(info, (DirectiveInfo i) => i.expressionAttrs), | 77 expect(flattenList(info, (DirectiveInfo i) => i.expressionAttrs), |
| 78 equals(['my-foo'])); | 78 equals(['my-foo'])); |
| 79 }); | 79 }); |
| 80 | 80 |
| 81 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', () { |
| 82 var info = extractDirectiveInfo([ | 82 var info = extractDirectiveInfo([ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 112 }); | 112 }); |
| 113 | 113 |
| 114 }); | 114 }); |
| 115 | 115 |
| 116 flattenList(list, map) => list.map(map).fold([], (prev, exprs) => | 116 flattenList(list, map) => list.map(map).fold([], (prev, exprs) => |
| 117 new List.from(prev)..addAll(exprs)); | 117 new List.from(prev)..addAll(exprs)); |
| 118 | 118 |
| 119 List<DirectiveInfo> extractDirectiveInfo(List<DirectiveMetadata> metadata) { | 119 List<DirectiveInfo> extractDirectiveInfo(List<DirectiveMetadata> metadata) { |
| 120 var sourceCrawler = new MockSourceCrawler(); | 120 var sourceCrawler = new MockSourceCrawler(); |
| 121 var metadataCollector = new MockDirectiveMetadataCollectingVisitor(metadata); | 121 var metadataCollector = new MockDirectiveMetadataCollectingVisitor(metadata); |
| 122 var extractor = new SourceMetadataExtractor(metadataCollector); | 122 var extractor = new SourceMetadataExtractor(sourceCrawler, metadataCollector); |
| 123 return extractor.gatherDirectiveInfo('', sourceCrawler); | 123 return extractor.gatherDirectiveInfo(''); |
| 124 } | 124 } |
| 125 | 125 |
| 126 class MockDirectiveMetadataCollectingVisitor | 126 class MockDirectiveMetadataCollectingVisitor |
| 127 implements DirectiveMetadataCollectingVisitor { | 127 implements DirectiveMetadataCollectingVisitor { |
| 128 List<DirectiveMetadata> metadata; | 128 List<DirectiveMetadata> metadata; |
| 129 | 129 |
| 130 MockDirectiveMetadataCollectingVisitor(List<DirectiveMetadata> this.metadata); | 130 MockDirectiveMetadataCollectingVisitor(List<DirectiveMetadata> this.metadata); |
| 131 | 131 |
| 132 call(CompilationUnit cu) { | 132 call(CompilationUnit cu) { |
| 133 // do nothing | 133 // do nothing |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 class MockSourceCrawler implements SourceCrawler { | 137 class MockSourceCrawler implements SourceCrawler { |
| 138 | 138 |
| 139 void crawl(String entryPoint, visitor(CompilationUnit cu)) { | 139 void crawl(String entryPoint, visitor(CompilationUnit cu)) { |
| 140 // do nothing | 140 // do nothing |
| 141 } | 141 } |
| 142 } | 142 } |
| OLD | NEW |