|
1 | 1 | library angular2.test.transform.common.annotation_matcher_test; |
2 | 2 |
|
3 | 3 | import 'dart:async'; |
| 4 | + |
4 | 5 | import 'package:analyzer/analyzer.dart'; |
5 | | -import 'package:angular2/src/transform/common/annotation_matcher.dart'; |
6 | 6 | import 'package:barback/barback.dart' show AssetId; |
7 | | -import 'package:guinness/guinness.dart'; |
| 7 | +import 'package:test/test.dart'; |
| 8 | + |
| 9 | +import 'package:angular2/src/transform/common/annotation_matcher.dart'; |
8 | 10 |
|
9 | 11 | main() { |
10 | 12 | allTests(); |
@@ -39,66 +41,69 @@ var foo; |
39 | 41 | '''); |
40 | 42 |
|
41 | 43 | void allTests() { |
42 | | - it('should be able to match basic annotations.', () { |
| 44 | + test('should be able to match basic annotations.', () { |
43 | 45 | var matcher = new AnnotationMatcher() |
44 | | - ..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null)); |
| 46 | + ..add(const ClassDescriptor('Test', 'package:test/test.dart')); |
45 | 47 | var visitor = new MatchRecordingVisitor(matcher); |
46 | 48 | simpleAst.accept(visitor); |
47 | | - expect(visitor.matches.length).toBe(1); |
| 49 | + expect(visitor.matches.length, equals(1)); |
48 | 50 | }); |
49 | 51 |
|
50 | | - it('should be able to match namespaced annotations.', () { |
| 52 | + test('should be able to match namespaced annotations.', () { |
51 | 53 | var matcher = new AnnotationMatcher() |
52 | | - ..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null)); |
| 54 | + ..add(const ClassDescriptor('Test', 'package:test/test.dart')); |
53 | 55 | var visitor = new MatchRecordingVisitor(matcher); |
54 | 56 | namespacedAst.accept(visitor); |
55 | | - expect(visitor.matches.length).toBe(1); |
| 57 | + expect(visitor.matches.length, equals(1)); |
56 | 58 | }); |
57 | 59 |
|
58 | | - it('should be able to match relative imports.', () { |
| 60 | + test('should be able to match relative imports.', () { |
59 | 61 | var matcher = new AnnotationMatcher() |
60 | | - ..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null)); |
| 62 | + ..add(const ClassDescriptor('Test', 'package:test/test.dart')); |
61 | 63 | var visitor = |
62 | 64 | new MatchRecordingVisitor(matcher, new AssetId('test', 'lib/foo.dart')); |
63 | 65 | relativePathAst.accept(visitor); |
64 | | - expect(visitor.matches.length).toBe(1); |
| 66 | + expect(visitor.matches.length, equals(1)); |
65 | 67 | }); |
66 | 68 |
|
67 | | - it('should be able to match relative imports with a namespace.', () { |
| 69 | + test('should be able to match relative imports with a namespace.', () { |
68 | 70 | var matcher = new AnnotationMatcher() |
69 | | - ..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null)); |
| 71 | + ..add(const ClassDescriptor('Test', 'package:test/test.dart')); |
70 | 72 | var visitor = |
71 | 73 | new MatchRecordingVisitor(matcher, new AssetId('test', 'lib/foo.dart')); |
72 | 74 | namespacedRelativePathAst.accept(visitor); |
73 | | - expect(visitor.matches.length).toBe(1); |
| 75 | + expect(visitor.matches.length, equals(1)); |
74 | 76 | }); |
75 | 77 |
|
76 | | - it('should not match annotations if the import is missing.', () { |
| 78 | + test('should not match annotations if the import is missing.', () { |
77 | 79 | var matcher = new AnnotationMatcher() |
78 | | - ..add(const AnnotationDescriptor('Test', 'package:test/foo.dart', null)); |
| 80 | + ..add(const ClassDescriptor('Test', 'package:test/foo.dart')); |
79 | 81 | var visitor = new MatchRecordingVisitor(matcher); |
80 | 82 | simpleAst.accept(visitor); |
81 | | - expect(visitor.matches.isEmpty).toBeTrue(); |
| 83 | + expect(visitor.matches.isEmpty, isTrue); |
82 | 84 | }); |
83 | 85 |
|
84 | | - it('should not match annotations if the name is different.', () { |
| 86 | + test('should not match annotations if the name is different.', () { |
85 | 87 | var matcher = new AnnotationMatcher() |
86 | | - ..add(const AnnotationDescriptor('Foo', 'package:test/test.dart', null)); |
| 88 | + ..add(const ClassDescriptor('Foo', 'package:test/test.dart')); |
87 | 89 | var visitor = new MatchRecordingVisitor(matcher); |
88 | 90 | simpleAst.accept(visitor); |
89 | | - expect(visitor.matches.isEmpty).toBeTrue(); |
| 91 | + expect(visitor.matches.isEmpty, isTrue); |
90 | 92 | }); |
91 | 93 | } |
92 | 94 |
|
93 | 95 | class MatchRecordingVisitor extends RecursiveAstVisitor { |
94 | 96 | final AssetId assetId; |
95 | 97 | final AnnotationMatcher matcher; |
96 | | - final List<Annotation> matches = []; |
| 98 | + final matches = <Annotation>[]; |
97 | 99 |
|
98 | | - MatchRecordingVisitor(this.matcher, [this.assetId]) : super(); |
| 100 | + MatchRecordingVisitor(this.matcher, [AssetId assetId]) |
| 101 | + : super(), |
| 102 | + this.assetId = |
| 103 | + assetId != null ? assetId : new AssetId('a', 'lib/a.dart'); |
99 | 104 |
|
100 | 105 | @override |
101 | 106 | void visitAnnotation(Annotation annotation) { |
102 | | - if (matcher.hasMatch(annotation, assetId)) matches.add(annotation); |
| 107 | + if (matcher.hasMatch(annotation.name, assetId)) matches.add(annotation); |
103 | 108 | } |
104 | 109 | } |
0 commit comments