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 #706
This commit is contained in:
parent
85211f0a6b
commit
329b2eda66
|
@ -224,6 +224,14 @@ abstract class _TransformVisitor extends ToSourceVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Object visitPrefixedIdentifier(PrefixedIdentifier node) {
|
||||||
|
// We add our own prefixes in [visitSimpleIdentifier], discard any used in
|
||||||
|
// the original source.
|
||||||
|
_visitNode(node.identifier);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Object visitSimpleIdentifier(SimpleIdentifier node) {
|
Object visitSimpleIdentifier(SimpleIdentifier node) {
|
||||||
// Make sure the identifier is prefixed if necessary.
|
// Make sure the identifier is prefixed if necessary.
|
||||||
|
@ -281,6 +289,7 @@ class _CtorTransformVisitor extends _TransformVisitor {
|
||||||
@override
|
@override
|
||||||
Object visitDefaultFormalParameter(DefaultFormalParameter node) {
|
Object visitDefaultFormalParameter(DefaultFormalParameter node) {
|
||||||
_visitNode(node.parameter);
|
_visitNode(node.parameter);
|
||||||
|
// Ignore the declared default value.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
||||||
// for details. All rights reserved. Use of this source code is governed by a
|
|
||||||
// BSD-style license that can be found in the LICENSE file.
|
|
||||||
library angular2.test.transform;
|
|
||||||
|
|
||||||
// TODO(kegluneq): Remove this and use the actual Directive def'n.
|
|
||||||
// Simple mock of Directive.
|
|
||||||
class Directive {
|
|
||||||
final context;
|
|
||||||
const Directive({this.context});
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
library bar;
|
|
||||||
|
|
||||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
|
||||||
|
|
||||||
@Directive(context: 'soup')
|
|
||||||
class Component {
|
|
||||||
final dynamic c;
|
|
||||||
Component([this.c = 'sandwich']);
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
import 'package:angular2/src/reflection/reflection.dart' show reflector;
|
|
||||||
import 'bar.dart' as i0;
|
|
||||||
import 'package:angular2/src/core/annotations/annotations.dart' as i1;
|
|
||||||
import 'index.dart' as i2;
|
|
||||||
|
|
||||||
main() {
|
|
||||||
reflector
|
|
||||||
..registerType(i0.Component, {
|
|
||||||
"factory": (dynamic c) => new i0.Component(c),
|
|
||||||
"parameters": const [const [dynamic]],
|
|
||||||
"annotations": const [const i1.Directive(context: 'soup')]
|
|
||||||
});
|
|
||||||
i2.main();
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
library web_foo;
|
|
||||||
|
|
||||||
import 'bar.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
new Component('Things');
|
|
||||||
}
|
|
|
@ -3,8 +3,8 @@ library bar;
|
||||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||||
import 'foo.dart';
|
import 'foo.dart';
|
||||||
|
|
||||||
@Directive(context: const [MyContext])
|
@Component(componentServices: const [MyContext])
|
||||||
class Component {
|
class MyComponent {
|
||||||
final MyContext c;
|
final MyContext c;
|
||||||
Component(this.c);
|
MyComponent(this.c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,12 @@ import 'index.dart' as i3;
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
reflector
|
reflector
|
||||||
..registerType(i0.Component, {
|
..registerType(i0.MyComponent, {
|
||||||
"factory": (i1.MyContext c) => new i0.Component(c),
|
"factory": (i1.MyContext c) => new i0.MyComponent(c),
|
||||||
"parameters": const [const [i1.MyContext]],
|
"parameters": const [const [i1.MyContext]],
|
||||||
"annotations": const [const i2.Directive(context: const [i1.MyContext])]
|
"annotations": const [
|
||||||
|
const i2.Component(componentServices: const [i1.MyContext])
|
||||||
|
]
|
||||||
});
|
});
|
||||||
i3.main();
|
i3.main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ library bar;
|
||||||
|
|
||||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||||
|
|
||||||
@Directive(context: 'soup')
|
@Component(selector: '[soup]')
|
||||||
class Component {
|
class MyComponent {
|
||||||
Component();
|
MyComponent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@ import 'index.dart' as i2;
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
reflector
|
reflector
|
||||||
..registerType(i0.Component, {
|
..registerType(i0.MyComponent, {
|
||||||
"factory": () => new i0.Component(),
|
"factory": () => new i0.MyComponent(),
|
||||||
"parameters": const [const []],
|
"parameters": const [const []],
|
||||||
"annotations": const [const i1.Directive(context: 'soup')]
|
"annotations": const [const i1.Component(selector: '[soup]')]
|
||||||
});
|
});
|
||||||
i2.main();
|
i2.main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,5 @@ library web_foo;
|
||||||
import 'bar.dart';
|
import 'bar.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
new Component('Things');
|
new MyComponent('Things');
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,5 @@ library bar;
|
||||||
|
|
||||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||||
|
|
||||||
@Directive(context: 'soup')
|
@Component(selector: '[soup]')
|
||||||
class Component {}
|
class MyComponent {}
|
||||||
|
|
|
@ -5,10 +5,10 @@ import 'index.dart' as i2;
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
reflector
|
reflector
|
||||||
..registerType(i0.Component, {
|
..registerType(i0.MyComponent, {
|
||||||
"factory": () => new i0.Component(),
|
"factory": () => new i0.MyComponent(),
|
||||||
"parameters": const [const []],
|
"parameters": const [const []],
|
||||||
"annotations": const [const i1.Directive(context: 'soup')]
|
"annotations": const [const i1.Component(selector: '[soup]')]
|
||||||
});
|
});
|
||||||
i2.main();
|
i2.main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,5 @@ library web_foo;
|
||||||
import 'bar.dart';
|
import 'bar.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
new Component();
|
new MyComponent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
library angular2.test.transform;
|
library angular2.test;
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:barback/barback.dart';
|
import 'package:barback/barback.dart';
|
||||||
|
@ -8,8 +8,6 @@ import 'package:dart_style/dart_style.dart';
|
||||||
import 'package:unittest/unittest.dart';
|
import 'package:unittest/unittest.dart';
|
||||||
import 'package:unittest/vm_config.dart';
|
import 'package:unittest/vm_config.dart';
|
||||||
|
|
||||||
import 'common.dart';
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
useVMConfiguration();
|
useVMConfiguration();
|
||||||
|
|
||||||
|
@ -41,7 +39,8 @@ void _runTests() {
|
||||||
inputs: {
|
inputs: {
|
||||||
'a|web/index.html': 'common.html',
|
'a|web/index.html': 'common.html',
|
||||||
'a|web/index.dart': 'html_entry_point_files/index.dart',
|
'a|web/index.dart': 'html_entry_point_files/index.dart',
|
||||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
'angular2|lib/src/core/annotations/annotations.dart':
|
||||||
|
'../../lib/src/core/annotations/annotations.dart'
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
'a|web/index.html': 'html_entry_point_files/expected/index.html'
|
'a|web/index.html': 'html_entry_point_files/expected/index.html'
|
||||||
|
@ -51,7 +50,8 @@ void _runTests() {
|
||||||
'a|web/index.html': 'common.html',
|
'a|web/index.html': 'common.html',
|
||||||
'a|web/index.dart': 'simple_annotation_files/index.dart',
|
'a|web/index.dart': 'simple_annotation_files/index.dart',
|
||||||
'a|web/bar.dart': 'simple_annotation_files/bar.dart',
|
'a|web/bar.dart': 'simple_annotation_files/bar.dart',
|
||||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
'angular2|lib/src/core/annotations/annotations.dart':
|
||||||
|
'../../lib/src/core/annotations/annotations.dart'
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
'a|web/index.bootstrap.dart':
|
'a|web/index.bootstrap.dart':
|
||||||
|
@ -63,7 +63,8 @@ void _runTests() {
|
||||||
'a|web/index.dart': 'two_deps_files/index.dart',
|
'a|web/index.dart': 'two_deps_files/index.dart',
|
||||||
'a|web/foo.dart': 'two_deps_files/foo.dart',
|
'a|web/foo.dart': 'two_deps_files/foo.dart',
|
||||||
'a|web/bar.dart': 'two_deps_files/bar.dart',
|
'a|web/bar.dart': 'two_deps_files/bar.dart',
|
||||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
'angular2|lib/src/core/annotations/annotations.dart':
|
||||||
|
'../../lib/src/core/annotations/annotations.dart'
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
'a|web/index.bootstrap.dart':
|
'a|web/index.bootstrap.dart':
|
||||||
|
@ -75,29 +76,20 @@ void _runTests() {
|
||||||
'a|web/index.dart': 'list_of_types_files/index.dart',
|
'a|web/index.dart': 'list_of_types_files/index.dart',
|
||||||
'a|web/foo.dart': 'list_of_types_files/foo.dart',
|
'a|web/foo.dart': 'list_of_types_files/foo.dart',
|
||||||
'a|web/bar.dart': 'list_of_types_files/bar.dart',
|
'a|web/bar.dart': 'list_of_types_files/bar.dart',
|
||||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
'angular2|lib/src/core/annotations/annotations.dart':
|
||||||
|
'../../lib/src/core/annotations/annotations.dart'
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
'a|web/index.bootstrap.dart':
|
'a|web/index.bootstrap.dart':
|
||||||
'list_of_types_files/expected/index.bootstrap.dart'
|
'list_of_types_files/expected/index.bootstrap.dart'
|
||||||
}),
|
}),
|
||||||
new TestConfig('Component ctor with default value',
|
|
||||||
inputs: {
|
|
||||||
'a|web/index.html': 'common.html',
|
|
||||||
'a|web/index.dart': 'ctor_with_default_value_files/index.dart',
|
|
||||||
'a|web/bar.dart': 'ctor_with_default_value_files/bar.dart',
|
|
||||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
|
||||||
},
|
|
||||||
outputs: {
|
|
||||||
'a|web/index.bootstrap.dart':
|
|
||||||
'ctor_with_default_value_files/expected/index.bootstrap.dart'
|
|
||||||
}),
|
|
||||||
new TestConfig('Component with synthetic Constructor',
|
new TestConfig('Component with synthetic Constructor',
|
||||||
inputs: {
|
inputs: {
|
||||||
'a|web/index.html': 'common.html',
|
'a|web/index.html': 'common.html',
|
||||||
'a|web/index.dart': 'synthetic_ctor_files/index.dart',
|
'a|web/index.dart': 'synthetic_ctor_files/index.dart',
|
||||||
'a|web/bar.dart': 'synthetic_ctor_files/bar.dart',
|
'a|web/bar.dart': 'synthetic_ctor_files/bar.dart',
|
||||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
'angular2|lib/src/core/annotations/annotations.dart':
|
||||||
|
'../../lib/src/core/annotations/annotations.dart'
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
'a|web/index.bootstrap.dart':
|
'a|web/index.bootstrap.dart':
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
library bar;
|
library bar;
|
||||||
|
|
||||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||||
import 'foo.dart';
|
import 'foo.dart' as prefix;
|
||||||
|
|
||||||
@Directive(context: const MyContext(contextString))
|
@Component(selector: prefix.preDefinedSelector)
|
||||||
class Component2 {
|
class MyComponent {
|
||||||
final MyContext c;
|
final prefix.MyContext c;
|
||||||
final String generatedValue;
|
final String generatedValue;
|
||||||
Component2(this.c, String inValue) {
|
MyComponent(this.c, String inValue) {
|
||||||
generatedValue = 'generated ' + inValue;
|
generatedValue = 'generated ' + inValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@ import 'index.dart' as i3;
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
reflector
|
reflector
|
||||||
..registerType(i0.Component2, {
|
..registerType(i0.MyComponent, {
|
||||||
"factory":
|
"factory":
|
||||||
(i1.MyContext c, String inValue) => new i0.Component2(c, inValue),
|
(i1.MyContext c, String inValue) => new i0.MyComponent(c, inValue),
|
||||||
"parameters": const [const [i1.MyContext, String]],
|
"parameters": const [const [i1.MyContext, String]],
|
||||||
"annotations": const [
|
"annotations": const [
|
||||||
const i2.Directive(context: const i1.MyContext(i1.contextString))
|
const i2.Component(selector: i1.preDefinedSelector)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
i3.main();
|
i3.main();
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
library foo;
|
library foo;
|
||||||
|
|
||||||
const contextString = 'soup';
|
const preDefinedSelector = 'soup';
|
||||||
|
|
||||||
class MyContext {
|
class MyContext {
|
||||||
final String s;
|
final String selector;
|
||||||
const MyContext(this.s);
|
const MyContext(this.selector);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,5 @@ library web_foo;
|
||||||
import 'bar.dart';
|
import 'bar.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
new Component('Things');
|
new MyComponent('Things');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue