test(dart/transform): Move BindGenerator tests to their own dir.
Move existing BindGenerator test to its own directory and to test that phase specificially, rather than the whole pipeline. Add another BindGenerator test.
This commit is contained in:
parent
4b12c19560
commit
5c1c534894
|
@ -27,7 +27,7 @@ List<String> _generateSetters(Map<String, String> bindMap) {
|
|||
var setters = [];
|
||||
// TODO(kegluneq): Include types for receivers. See #886.
|
||||
bindMap.forEach((prop, type) {
|
||||
setters.add('\'$prop\': (o, String v) => o.$prop = v');
|
||||
setters.add(''''$prop': (o, String v) => o.$prop = v''');
|
||||
});
|
||||
return setters;
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ class RegisteredType {
|
|||
/// The actual call to `Reflector#registerType`.
|
||||
final MethodInvocation registerMethod;
|
||||
/// The factory method registered.
|
||||
final Expression factory;
|
||||
final Expression factoryFn;
|
||||
/// The parameters registered.
|
||||
final Expression parameters;
|
||||
/// The annotations registered.
|
||||
final Expression annotations;
|
||||
|
||||
RegisteredType._(this.typeName, this.registerMethod, this.factory,
|
||||
RegisteredType._(this.typeName, this.registerMethod, this.factoryFn,
|
||||
this.parameters, this.annotations);
|
||||
|
||||
/// Creates a [RegisteredType] given a [MethodInvocation] node representing
|
||||
|
@ -25,14 +25,14 @@ class RegisteredType {
|
|||
var visitor = new _ParseRegisterTypeVisitor();
|
||||
registerMethod.accept(visitor);
|
||||
return new RegisteredType._(visitor.typeName, registerMethod,
|
||||
visitor.factory, visitor.parameters, visitor.annotations);
|
||||
visitor.factoryFn, visitor.parameters, visitor.annotations);
|
||||
}
|
||||
}
|
||||
|
||||
class _ParseRegisterTypeVisitor extends Object
|
||||
with RecursiveAstVisitor<Object> {
|
||||
Identifier typeName;
|
||||
Expression factory;
|
||||
Expression factoryFn;
|
||||
Expression parameters;
|
||||
Expression annotations;
|
||||
|
||||
|
@ -56,7 +56,7 @@ class _ParseRegisterTypeVisitor extends Object
|
|||
annotations = node.value;
|
||||
break;
|
||||
case 'factory':
|
||||
factory = node.value;
|
||||
factoryFn = node.value;
|
||||
break;
|
||||
case 'parameters':
|
||||
parameters = node.value;
|
||||
|
|
|
@ -64,7 +64,7 @@ class CreateNgDepsVisitor extends Object
|
|||
}
|
||||
|
||||
void _writeImport() {
|
||||
writer.print('import \'${path.basename(importPath)}\';');
|
||||
writer.print('''import '${path.basename(importPath)}';''');
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -150,19 +150,19 @@ class CreateNgDepsVisitor extends Object
|
|||
}
|
||||
writer.print('..registerType(');
|
||||
visitNode(node.name);
|
||||
writer.print(', {\'factory\': ');
|
||||
writer.print(''', {'factory': ''');
|
||||
if (ctor == null) {
|
||||
_generateEmptyFactory(node.name.toString());
|
||||
} else {
|
||||
ctor.accept(_factoryVisitor);
|
||||
}
|
||||
writer.print(', \'parameters\': ');
|
||||
writer.print(''', 'parameters': ''');
|
||||
if (ctor == null) {
|
||||
_generateEmptyParams();
|
||||
} else {
|
||||
ctor.accept(_paramsVisitor);
|
||||
}
|
||||
writer.print(', \'annotations\': ');
|
||||
writer.print(''', 'annotations': ''');
|
||||
node.accept(_metaVisitor);
|
||||
writer.print('})');
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
library angular2.test.transform.bind_generator.all_tests;
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:barback/barback.dart';
|
||||
import 'package:angular2/src/transform/bind_generator/generator.dart';
|
||||
import 'package:angular2/src/transform/common/formatter.dart';
|
||||
import 'package:code_transformers/tests.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:unittest/unittest.dart';
|
||||
import 'package:unittest/vm_config.dart';
|
||||
|
||||
import '../common/read_file.dart';
|
||||
|
||||
var formatter = new DartFormatter();
|
||||
|
||||
void allTests() {
|
||||
var reader = new TestAssetReader();
|
||||
|
||||
test('should generate a setter for a `bind` property in an annotation.',
|
||||
() async {
|
||||
var inputPath = 'bind_generator/basic_bind_files/bar.ngDeps.dart';
|
||||
var expected = formatter.format(
|
||||
readFile('bind_generator/basic_bind_files/expected/bar.ngDeps.dart'));
|
||||
|
||||
var output = formatter
|
||||
.format(await createNgSetters(reader, new AssetId('a', inputPath)));
|
||||
expect(output, equals(expected));
|
||||
});
|
||||
|
||||
test('should generate a single setter when multiple annotations bind to the '
|
||||
'same property.', () async {
|
||||
var inputPath = 'bind_generator/duplicate_bind_name_files/soup.ngDeps.dart';
|
||||
var expected = formatter.format(readFile(
|
||||
'bind_generator/duplicate_bind_name_files/expected/soup.ngDeps.dart'));
|
||||
|
||||
var output = formatter
|
||||
.format(await createNgSetters(reader, new AssetId('a', inputPath)));
|
||||
expect(output, equals(expected));
|
||||
});
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
library bar;
|
||||
|
||||
import 'bar.dart';
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
bool _visited = false;
|
||||
void setupReflection(reflector) {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
reflector
|
||||
..registerType(ToolTip, {
|
||||
'factory': () => new ToolTip(),
|
||||
'parameters': const [],
|
||||
'annotations': const [
|
||||
const Decorator(
|
||||
selector: '[tool-tip]', bind: const {'text': 'tool-tip'})
|
||||
]
|
||||
});
|
||||
}
|
|
@ -8,13 +8,6 @@ void setupReflection(reflector) {
|
|||
if (_visited) return;
|
||||
_visited = true;
|
||||
reflector
|
||||
..registerType(MyComponent, {
|
||||
'factory': () => new MyComponent(),
|
||||
'parameters': const [],
|
||||
'annotations': const [
|
||||
const Component(selector: 'soup', services: const [ToolTip])
|
||||
]
|
||||
})
|
||||
..registerType(ToolTip, {
|
||||
'factory': () => new ToolTip(),
|
||||
'parameters': const [],
|
|
@ -0,0 +1,26 @@
|
|||
library dinner.soup;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
import 'soup.dart';
|
||||
|
||||
bool _visited = false;
|
||||
void setupReflection(reflector) {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
reflector
|
||||
..registerType(SoupComponent, {
|
||||
'factory': () => new SoupComponent(),
|
||||
'parameters': const [],
|
||||
'annotations': const [
|
||||
const Component(
|
||||
componentServices: const [SaladComponent],
|
||||
bind: const {'menu': 'menu'})
|
||||
]
|
||||
})
|
||||
..registerType(SaladComponent, {
|
||||
'factory': () => new SaladComponent(),
|
||||
'parameters': const [],
|
||||
'annotations': const [const Component(bind: const {'menu': 'menu'})]
|
||||
})
|
||||
..registerSetters({'menu': (o, String v) => o.menu = v});
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
library dinner.soup;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
import 'soup.dart';
|
||||
|
||||
bool _visited = false;
|
||||
void setupReflection(reflector) {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
reflector
|
||||
..registerType(SoupComponent, {
|
||||
'factory': () => new SoupComponent(),
|
||||
'parameters': const [],
|
||||
'annotations': const [
|
||||
const Component(
|
||||
componentServices: const [SaladComponent],
|
||||
bind: const {'menu': 'menu'})
|
||||
]
|
||||
})
|
||||
..registerType(SaladComponent, {
|
||||
'factory': () => new SaladComponent(),
|
||||
'parameters': const [],
|
||||
'annotations': const [const Component(bind: const {'menu': 'menu'})]
|
||||
});
|
||||
}
|
|
@ -93,14 +93,6 @@ void allTests() {
|
|||
outputs: {
|
||||
'a|web/bar.ngDeps.dart': 'two_annotations_files/expected/bar.ngDeps.dart'
|
||||
}),
|
||||
new IntegrationTestConfig('should generate setters for `bind` values.',
|
||||
inputs: {
|
||||
'a|web/index.dart': 'basic_bind_files/index.dart',
|
||||
'a|web/bar.dart': 'basic_bind_files/bar.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/bar.ngDeps.dart': 'basic_bind_files/expected/bar.ngDeps.dart'
|
||||
}),
|
||||
new IntegrationTestConfig(
|
||||
'should ensure that dependencies are property chained.',
|
||||
inputs: {
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
@Component(selector: 'soup', services: const [ToolTip])
|
||||
class MyComponent {}
|
||||
|
||||
@Decorator(selector: '[tool-tip]', bind: const {'text': 'tool-tip'})
|
||||
class ToolTip {
|
||||
String text;
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
library web_foo;
|
||||
|
||||
import 'package:angular2/src/core/application.dart';
|
||||
import 'package:angular2/src/reflection/reflection_capabilities.dart';
|
||||
import 'bar.dart';
|
||||
|
||||
void main() {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrap(MyComponent);
|
||||
}
|
|
@ -3,12 +3,14 @@ library angular2.test.transform;
|
|||
import 'package:unittest/unittest.dart';
|
||||
import 'package:unittest/vm_config.dart';
|
||||
|
||||
import 'bind_generator/all_tests.dart' as bindGenerator;
|
||||
import 'directive_processor/all_tests.dart' as directiveProcessor;
|
||||
import 'integration/all_tests.dart' as integration;
|
||||
import 'reflection_remover/all_tests.dart' as reflectionRemover;
|
||||
|
||||
main() {
|
||||
useVMConfiguration();
|
||||
group('Bind Generator', bindGenerator.allTests);
|
||||
group('Directive Processor', directiveProcessor.allTests);
|
||||
group('Reflection Remover', reflectionRemover.allTests);
|
||||
group('Transformer Pipeline', integration.allTests);
|
||||
|
|
Loading…
Reference in New Issue