Skip to content

Commit 756f5d8

Browse files
Tim Blasikegluneq
authored andcommitted
refactor(dart/transform): AnnotationMatcher tests
These were previously not being run. Bring them up to modern usage, move them to package:test, and include them in transform.server.spec.dart. Closes angular#7463
1 parent 45fd6f0 commit 756f5d8

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

modules_dart/transform/test/transform/common/annotation_matcher_test.dart

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
library angular2.test.transform.common.annotation_matcher_test;
22

33
import 'dart:async';
4+
45
import 'package:analyzer/analyzer.dart';
5-
import 'package:angular2/src/transform/common/annotation_matcher.dart';
66
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';
810

911
main() {
1012
allTests();
@@ -39,66 +41,69 @@ var foo;
3941
''');
4042

4143
void allTests() {
42-
it('should be able to match basic annotations.', () {
44+
test('should be able to match basic annotations.', () {
4345
var matcher = new AnnotationMatcher()
44-
..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null));
46+
..add(const ClassDescriptor('Test', 'package:test/test.dart'));
4547
var visitor = new MatchRecordingVisitor(matcher);
4648
simpleAst.accept(visitor);
47-
expect(visitor.matches.length).toBe(1);
49+
expect(visitor.matches.length, equals(1));
4850
});
4951

50-
it('should be able to match namespaced annotations.', () {
52+
test('should be able to match namespaced annotations.', () {
5153
var matcher = new AnnotationMatcher()
52-
..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null));
54+
..add(const ClassDescriptor('Test', 'package:test/test.dart'));
5355
var visitor = new MatchRecordingVisitor(matcher);
5456
namespacedAst.accept(visitor);
55-
expect(visitor.matches.length).toBe(1);
57+
expect(visitor.matches.length, equals(1));
5658
});
5759

58-
it('should be able to match relative imports.', () {
60+
test('should be able to match relative imports.', () {
5961
var matcher = new AnnotationMatcher()
60-
..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null));
62+
..add(const ClassDescriptor('Test', 'package:test/test.dart'));
6163
var visitor =
6264
new MatchRecordingVisitor(matcher, new AssetId('test', 'lib/foo.dart'));
6365
relativePathAst.accept(visitor);
64-
expect(visitor.matches.length).toBe(1);
66+
expect(visitor.matches.length, equals(1));
6567
});
6668

67-
it('should be able to match relative imports with a namespace.', () {
69+
test('should be able to match relative imports with a namespace.', () {
6870
var matcher = new AnnotationMatcher()
69-
..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null));
71+
..add(const ClassDescriptor('Test', 'package:test/test.dart'));
7072
var visitor =
7173
new MatchRecordingVisitor(matcher, new AssetId('test', 'lib/foo.dart'));
7274
namespacedRelativePathAst.accept(visitor);
73-
expect(visitor.matches.length).toBe(1);
75+
expect(visitor.matches.length, equals(1));
7476
});
7577

76-
it('should not match annotations if the import is missing.', () {
78+
test('should not match annotations if the import is missing.', () {
7779
var matcher = new AnnotationMatcher()
78-
..add(const AnnotationDescriptor('Test', 'package:test/foo.dart', null));
80+
..add(const ClassDescriptor('Test', 'package:test/foo.dart'));
7981
var visitor = new MatchRecordingVisitor(matcher);
8082
simpleAst.accept(visitor);
81-
expect(visitor.matches.isEmpty).toBeTrue();
83+
expect(visitor.matches.isEmpty, isTrue);
8284
});
8385

84-
it('should not match annotations if the name is different.', () {
86+
test('should not match annotations if the name is different.', () {
8587
var matcher = new AnnotationMatcher()
86-
..add(const AnnotationDescriptor('Foo', 'package:test/test.dart', null));
88+
..add(const ClassDescriptor('Foo', 'package:test/test.dart'));
8789
var visitor = new MatchRecordingVisitor(matcher);
8890
simpleAst.accept(visitor);
89-
expect(visitor.matches.isEmpty).toBeTrue();
91+
expect(visitor.matches.isEmpty, isTrue);
9092
});
9193
}
9294

9395
class MatchRecordingVisitor extends RecursiveAstVisitor {
9496
final AssetId assetId;
9597
final AnnotationMatcher matcher;
96-
final List<Annotation> matches = [];
98+
final matches = <Annotation>[];
9799

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');
99104

100105
@override
101106
void visitAnnotation(Annotation annotation) {
102-
if (matcher.hasMatch(annotation, assetId)) matches.add(annotation);
107+
if (matcher.hasMatch(annotation.name, assetId)) matches.add(annotation);
103108
}
104109
}

modules_dart/transform/test/transform/transform.server.spec.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ library angular2.test.transform.transform.server.spec;
33

44
import 'package:test/test.dart';
55

6+
import 'common/annotation_matcher_test.dart' as annotationMatcher;
67
import 'common/async_string_writer_tests.dart' as asyncStringWriter;
78
import 'common/code/ng_deps_code_tests.dart' as ngDepsCode;
89
import 'common/ng_meta_test.dart' as ngMetaTest;
910
import 'common/url_resolver_tests.dart' as urlResolver;
1011

1112
main() {
13+
group('AnnotationMatcher', annotationMatcher.allTests);
1214
group('AsyncStringWriter', asyncStringWriter.allTests);
1315
group('NgDepsCode', ngDepsCode.allTests);
1416
group('NgMeta', ngMetaTest.allTests);

0 commit comments

Comments
 (0)