Skip to content

Commit 329b2ed

Browse files
Tim Blasimhevery
Tim Blasi
authored andcommitted
refactor(dart/transform tests): Use actual directive def'n instead of mock.
In the transformer unit tests, we previously used a mock directive annotation. This update substitutes the actual Angular2 directive annotations. Closes angular#706
1 parent 85211f0 commit 329b2ed

File tree

18 files changed

+53
-91
lines changed

18 files changed

+53
-91
lines changed

modules/angular2/src/transform/codegen.dart

+9
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ abstract class _TransformVisitor extends ToSourceVisitor {
224224
}
225225
}
226226

227+
@override
228+
Object visitPrefixedIdentifier(PrefixedIdentifier node) {
229+
// We add our own prefixes in [visitSimpleIdentifier], discard any used in
230+
// the original source.
231+
_visitNode(node.identifier);
232+
return null;
233+
}
234+
227235
@override
228236
Object visitSimpleIdentifier(SimpleIdentifier node) {
229237
// Make sure the identifier is prefixed if necessary.
@@ -281,6 +289,7 @@ class _CtorTransformVisitor extends _TransformVisitor {
281289
@override
282290
Object visitDefaultFormalParameter(DefaultFormalParameter node) {
283291
_visitNode(node.parameter);
292+
// Ignore the declared default value.
284293
return null;
285294
}
286295

modules/angular2/test/transform/common.dart

-11
This file was deleted.

modules/angular2/test/transform/ctor_with_default_value_files/bar.dart

-9
This file was deleted.

modules/angular2/test/transform/ctor_with_default_value_files/expected/index.bootstrap.dart

-14
This file was deleted.

modules/angular2/test/transform/ctor_with_default_value_files/index.dart

-7
This file was deleted.

modules/angular2/test/transform/list_of_types_files/bar.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ library bar;
33
import 'package:angular2/src/core/annotations/annotations.dart';
44
import 'foo.dart';
55

6-
@Directive(context: const [MyContext])
7-
class Component {
6+
@Component(componentServices: const [MyContext])
7+
class MyComponent {
88
final MyContext c;
9-
Component(this.c);
9+
MyComponent(this.c);
1010
}

modules/angular2/test/transform/list_of_types_files/expected/index.bootstrap.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import 'index.dart' as i3;
66

77
main() {
88
reflector
9-
..registerType(i0.Component, {
10-
"factory": (i1.MyContext c) => new i0.Component(c),
9+
..registerType(i0.MyComponent, {
10+
"factory": (i1.MyContext c) => new i0.MyComponent(c),
1111
"parameters": const [const [i1.MyContext]],
12-
"annotations": const [const i2.Directive(context: const [i1.MyContext])]
12+
"annotations": const [
13+
const i2.Component(componentServices: const [i1.MyContext])
14+
]
1315
});
1416
i3.main();
1517
}

modules/angular2/test/transform/simple_annotation_files/bar.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ library bar;
22

33
import 'package:angular2/src/core/annotations/annotations.dart';
44

5-
@Directive(context: 'soup')
6-
class Component {
7-
Component();
5+
@Component(selector: '[soup]')
6+
class MyComponent {
7+
MyComponent();
88
}

modules/angular2/test/transform/simple_annotation_files/expected/index.bootstrap.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import 'index.dart' as i2;
55

66
main() {
77
reflector
8-
..registerType(i0.Component, {
9-
"factory": () => new i0.Component(),
8+
..registerType(i0.MyComponent, {
9+
"factory": () => new i0.MyComponent(),
1010
"parameters": const [const []],
11-
"annotations": const [const i1.Directive(context: 'soup')]
11+
"annotations": const [const i1.Component(selector: '[soup]')]
1212
});
1313
i2.main();
1414
}

modules/angular2/test/transform/simple_annotation_files/index.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ library web_foo;
33
import 'bar.dart';
44

55
void main() {
6-
new Component('Things');
6+
new MyComponent('Things');
77
}

modules/angular2/test/transform/synthetic_ctor_files/bar.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ library bar;
22

33
import 'package:angular2/src/core/annotations/annotations.dart';
44

5-
@Directive(context: 'soup')
6-
class Component {}
5+
@Component(selector: '[soup]')
6+
class MyComponent {}

modules/angular2/test/transform/synthetic_ctor_files/expected/index.bootstrap.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import 'index.dart' as i2;
55

66
main() {
77
reflector
8-
..registerType(i0.Component, {
9-
"factory": () => new i0.Component(),
8+
..registerType(i0.MyComponent, {
9+
"factory": () => new i0.MyComponent(),
1010
"parameters": const [const []],
11-
"annotations": const [const i1.Directive(context: 'soup')]
11+
"annotations": const [const i1.Component(selector: '[soup]')]
1212
});
1313
i2.main();
1414
}

modules/angular2/test/transform/synthetic_ctor_files/index.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ library web_foo;
33
import 'bar.dart';
44

55
void main() {
6-
new Component();
6+
new MyComponent();
77
}

modules/angular2/test/transform/transform_test.dart

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
library angular2.test.transform;
1+
library angular2.test;
22

33
import 'dart:io';
44
import 'package:barback/barback.dart';
@@ -8,8 +8,6 @@ import 'package:dart_style/dart_style.dart';
88
import 'package:unittest/unittest.dart';
99
import 'package:unittest/vm_config.dart';
1010

11-
import 'common.dart';
12-
1311
main() {
1412
useVMConfiguration();
1513

@@ -41,7 +39,8 @@ void _runTests() {
4139
inputs: {
4240
'a|web/index.html': 'common.html',
4341
'a|web/index.dart': 'html_entry_point_files/index.dart',
44-
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
42+
'angular2|lib/src/core/annotations/annotations.dart':
43+
'../../lib/src/core/annotations/annotations.dart'
4544
},
4645
outputs: {
4746
'a|web/index.html': 'html_entry_point_files/expected/index.html'
@@ -51,7 +50,8 @@ void _runTests() {
5150
'a|web/index.html': 'common.html',
5251
'a|web/index.dart': 'simple_annotation_files/index.dart',
5352
'a|web/bar.dart': 'simple_annotation_files/bar.dart',
54-
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
53+
'angular2|lib/src/core/annotations/annotations.dart':
54+
'../../lib/src/core/annotations/annotations.dart'
5555
},
5656
outputs: {
5757
'a|web/index.bootstrap.dart':
@@ -63,7 +63,8 @@ void _runTests() {
6363
'a|web/index.dart': 'two_deps_files/index.dart',
6464
'a|web/foo.dart': 'two_deps_files/foo.dart',
6565
'a|web/bar.dart': 'two_deps_files/bar.dart',
66-
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
66+
'angular2|lib/src/core/annotations/annotations.dart':
67+
'../../lib/src/core/annotations/annotations.dart'
6768
},
6869
outputs: {
6970
'a|web/index.bootstrap.dart':
@@ -75,29 +76,20 @@ void _runTests() {
7576
'a|web/index.dart': 'list_of_types_files/index.dart',
7677
'a|web/foo.dart': 'list_of_types_files/foo.dart',
7778
'a|web/bar.dart': 'list_of_types_files/bar.dart',
78-
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
79+
'angular2|lib/src/core/annotations/annotations.dart':
80+
'../../lib/src/core/annotations/annotations.dart'
7981
},
8082
outputs: {
8183
'a|web/index.bootstrap.dart':
8284
'list_of_types_files/expected/index.bootstrap.dart'
8385
}),
84-
new TestConfig('Component ctor with default value',
85-
inputs: {
86-
'a|web/index.html': 'common.html',
87-
'a|web/index.dart': 'ctor_with_default_value_files/index.dart',
88-
'a|web/bar.dart': 'ctor_with_default_value_files/bar.dart',
89-
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
90-
},
91-
outputs: {
92-
'a|web/index.bootstrap.dart':
93-
'ctor_with_default_value_files/expected/index.bootstrap.dart'
94-
}),
9586
new TestConfig('Component with synthetic Constructor',
9687
inputs: {
9788
'a|web/index.html': 'common.html',
9889
'a|web/index.dart': 'synthetic_ctor_files/index.dart',
9990
'a|web/bar.dart': 'synthetic_ctor_files/bar.dart',
100-
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
91+
'angular2|lib/src/core/annotations/annotations.dart':
92+
'../../lib/src/core/annotations/annotations.dart'
10193
},
10294
outputs: {
10395
'a|web/index.bootstrap.dart':
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
library bar;
22

33
import 'package:angular2/src/core/annotations/annotations.dart';
4-
import 'foo.dart';
4+
import 'foo.dart' as prefix;
55

6-
@Directive(context: const MyContext(contextString))
7-
class Component2 {
8-
final MyContext c;
6+
@Component(selector: prefix.preDefinedSelector)
7+
class MyComponent {
8+
final prefix.MyContext c;
99
final String generatedValue;
10-
Component2(this.c, String inValue) {
10+
MyComponent(this.c, String inValue) {
1111
generatedValue = 'generated ' + inValue;
1212
}
1313
}

modules/angular2/test/transform/two_deps_files/expected/index.bootstrap.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import 'index.dart' as i3;
66

77
main() {
88
reflector
9-
..registerType(i0.Component2, {
9+
..registerType(i0.MyComponent, {
1010
"factory":
11-
(i1.MyContext c, String inValue) => new i0.Component2(c, inValue),
11+
(i1.MyContext c, String inValue) => new i0.MyComponent(c, inValue),
1212
"parameters": const [const [i1.MyContext, String]],
1313
"annotations": const [
14-
const i2.Directive(context: const i1.MyContext(i1.contextString))
14+
const i2.Component(selector: i1.preDefinedSelector)
1515
]
1616
});
1717
i3.main();
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
library foo;
22

3-
const contextString = 'soup';
3+
const preDefinedSelector = 'soup';
44

55
class MyContext {
6-
final String s;
7-
const MyContext(this.s);
6+
final String selector;
7+
const MyContext(this.selector);
88
}

modules/angular2/test/transform/two_deps_files/index.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ library web_foo;
33
import 'bar.dart';
44

55
void main() {
6-
new Component('Things');
6+
new MyComponent('Things');
77
}

0 commit comments

Comments
 (0)