diff --git a/modules/angular2/src/transform/bind_generator/generator.dart b/modules/angular2/src/transform/bind_generator/generator.dart index e96b32701d..3081d33ab6 100644 --- a/modules/angular2/src/transform/bind_generator/generator.dart +++ b/modules/angular2/src/transform/bind_generator/generator.dart @@ -27,7 +27,8 @@ class CreateNgSettersVisitor extends ToSourceVisitor with VisitorMixin { @override Object visitMethodInvocation(MethodInvocation node) { - var isRegisterType = node.methodName.toString() == REGISTER_TYPE_METHOD_NAME; + var isRegisterType = + node.methodName.toString() == REGISTER_TYPE_METHOD_NAME; // The first argument to a `registerType` call is the type. extractVisitor.currentName = node.argumentList.arguments[0] is Identifier ? node.argumentList.arguments[0] diff --git a/modules/angular2/src/transform/common/formatter.dart b/modules/angular2/src/transform/common/formatter.dart index 152474e2c2..c9d71bb8c3 100644 --- a/modules/angular2/src/transform/common/formatter.dart +++ b/modules/angular2/src/transform/common/formatter.dart @@ -4,7 +4,7 @@ import 'package:dart_style/dart_style.dart'; import 'logging.dart'; -DartFormatter _formatter; +DartFormatter _formatter = null; void init(DartFormatter formatter) { if (_formatter != null) { diff --git a/modules/angular2/src/transform/directive_processor/visitors.dart b/modules/angular2/src/transform/directive_processor/visitors.dart index 720e0a3218..c682477cb0 100644 --- a/modules/angular2/src/transform/directive_processor/visitors.dart +++ b/modules/angular2/src/transform/directive_processor/visitors.dart @@ -7,6 +7,7 @@ import 'package:angular2/src/transform/common/visitor_mixin.dart'; /// SourceVisitor designed to accept [ConstructorDeclaration] nodes. class _CtorTransformVisitor extends ToSourceVisitor with VisitorMixin { + bool _withParameterAnnotations = true; bool _withParameterTypes = true; bool _withParameterNames = true; final PrintWriter writer; @@ -21,7 +22,13 @@ class _CtorTransformVisitor extends ToSourceVisitor with VisitorMixin { /// If [_withParameterTypes] is true, this method outputs [node]'s type. If /// [_withParameterNames] is true, this method outputs [node]'s identifier. - Object _visitNormalFormalParameter(TypeName type, SimpleIdentifier name) { + Object _visitNormalFormalParameter( + NodeList metadata, TypeName type, SimpleIdentifier name) { + if (_withParameterAnnotations && metadata != null) { + assert(_withParameterTypes); + var suffix = type != null ? ', ' : ''; + visitNodeListWithSeparatorAndSuffix(metadata, ', ', suffix); + } if (_withParameterTypes) { visitNodeWithSuffix(type, ' '); } @@ -48,7 +55,8 @@ class _CtorTransformVisitor extends ToSourceVisitor with VisitorMixin { @override Object visitSimpleFormalParameter(SimpleFormalParameter node) { - return _visitNormalFormalParameter(node.type, node.identifier); + return _visitNormalFormalParameter( + node.metadata, node.type, node.identifier); } @override @@ -61,14 +69,14 @@ class _CtorTransformVisitor extends ToSourceVisitor with VisitorMixin { if (type == null) { type = _fieldNameToType[node.identifier.toString()]; } - return _visitNormalFormalParameter(type, node.identifier); + return _visitNormalFormalParameter(node.metadata, type, node.identifier); } @override Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { logger.error('Function typed formal parameters not supported ' '(${node.toSource()})'); - return _visitNormalFormalParameter(null, node.identifier); + return _visitNormalFormalParameter(node.metadata, null, node.identifier); } @override @@ -93,18 +101,30 @@ class _CtorTransformVisitor extends ToSourceVisitor with VisitorMixin { writer.print(')'); return null; } + + @override + Object visitAnnotation(Annotation node) { + var prefix = + node.arguments != null && node.arguments.length > 0 ? 'const ' : ''; + visitNodeWithPrefix(prefix, node.name); + visitNodeWithPrefix(".", node.constructorName); + visitNode(node.arguments); + return null; + } } /// ToSourceVisitor designed to print 'parameters' values for Angular2's /// [registerType] calls. class ParameterTransformVisitor extends _CtorTransformVisitor { - ParameterTransformVisitor(PrintWriter writer) : super(writer); + ParameterTransformVisitor(PrintWriter writer) : super(writer) { + _withParameterNames = false; + _withParameterTypes = true; + _withParameterAnnotations = true; + } @override Object visitConstructorDeclaration(ConstructorDeclaration node) { _buildFieldMap(node); - _withParameterNames = false; - _withParameterTypes = true; writer.print('const ['); visitNode(node.parameters); writer.print(']'); @@ -131,7 +151,9 @@ class ParameterTransformVisitor extends _CtorTransformVisitor { /// ToSourceVisitor designed to print 'factory' values for Angular2's /// [registerType] calls. class FactoryTransformVisitor extends _CtorTransformVisitor { - FactoryTransformVisitor(PrintWriter writer) : super(writer); + FactoryTransformVisitor(PrintWriter writer) : super(writer) { + _withParameterAnnotations = false; + } @override Object visitConstructorDeclaration(ConstructorDeclaration node) { @@ -142,6 +164,7 @@ class FactoryTransformVisitor extends _CtorTransformVisitor { writer.print(' => new '); visitNode(node.returnType); visitNodeWithPrefix(".", node.name); + _withParameterTypes = false; visitNode(node.parameters); return null; diff --git a/modules/angular2/test/transform/common/read_file.dart b/modules/angular2/test/transform/common/read_file.dart new file mode 100644 index 0000000000..269866e151 --- /dev/null +++ b/modules/angular2/test/transform/common/read_file.dart @@ -0,0 +1,14 @@ +library angular2.test.transform.common.read_file; + +import 'dart:io'; + +/// Smooths over differences in CWD between IDEs and running tests in Travis. +String readFile(String path) { + for (var myPath in [path, 'test/transform/${path}']) { + var file = new File(myPath); + if (file.existsSync()) { + return file.readAsStringSync(); + } + } + return null; +} diff --git a/modules/angular2/test/transform/directive_processor/all_tests.dart b/modules/angular2/test/transform/directive_processor/all_tests.dart new file mode 100644 index 0000000000..708fe085da --- /dev/null +++ b/modules/angular2/test/transform/directive_processor/all_tests.dart @@ -0,0 +1,30 @@ +library angular2.test.transform.directive_processor.all_tests; + +import 'dart:io'; +import 'package:barback/barback.dart'; +import 'package:angular2/src/transform/directive_processor/rewriter.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() { + test('should preserve parameter annotations as const instances', () { + var inputPath = 'parameter_metadata/soup.dart'; + var expected = _readFile('parameter_metadata/expected/soup.ngDeps.dart'); + var output = + formatter.format(createNgDeps(_readFile(inputPath), inputPath)); + expect(output, equals(expected)); + }); +} + +var pathBase = 'directive_processor'; + +/// Smooths over differences in CWD between IDEs and running tests in Travis. +String _readFile(String path) => readFile('$pathBase/$path'); diff --git a/modules/angular2/test/transform/directive_processor/parameter_metadata/expected/soup.ngDeps.dart b/modules/angular2/test/transform/directive_processor/parameter_metadata/expected/soup.ngDeps.dart new file mode 100644 index 0000000000..f7efc4e80e --- /dev/null +++ b/modules/angular2/test/transform/directive_processor/parameter_metadata/expected/soup.ngDeps.dart @@ -0,0 +1,17 @@ +library dinner.soup; + +import 'soup.dart'; +import 'package:angular2/src/core/annotations/annotations.dart'; + +bool _visited = false; +void setupReflection(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(SoupComponent, { + "factory": + (String description, salt) => new SoupComponent(description, salt), + "parameters": const [const [Tasty, String], const [const Inject(Salt)]], + "annotations": const [const Component(selector: '[soup]')] + }); +} // {"version":1,"importOffset":104,"registerOffset":451,"imports":["package:angular2/src/core/annotations/annotations.dart"]} diff --git a/modules/angular2/test/transform/directive_processor/parameter_metadata/soup.dart b/modules/angular2/test/transform/directive_processor/parameter_metadata/soup.dart new file mode 100644 index 0000000000..0a2524fc86 --- /dev/null +++ b/modules/angular2/test/transform/directive_processor/parameter_metadata/soup.dart @@ -0,0 +1,8 @@ +library dinner.soup; + +import 'package:angular2/src/core/annotations/annotations.dart'; + +@Component(selector: '[soup]') +class SoupComponent { + SoupComponent(@Tasty String description, @Inject(Salt) salt); +} diff --git a/modules/angular2/test/transform/integration/all_tests.dart b/modules/angular2/test/transform/integration/all_tests.dart new file mode 100644 index 0000000000..df5bbe4ae0 --- /dev/null +++ b/modules/angular2/test/transform/integration/all_tests.dart @@ -0,0 +1,141 @@ +library angular2.test.transform.integration; + +import 'dart:io'; +import 'package:angular2/transformer.dart'; +import 'package:code_transformers/tests.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:unittest/unittest.dart'; + +import '../common/read_file.dart'; + +var formatter = new DartFormatter(); +var transform = new AngularTransformerGroup(new TransformerOptions( + 'web/index.dart', reflectionEntryPoint: 'web/index.dart')); + +class IntegrationTestConfig { + final String name; + final Map assetPathToInputPath; + final Map assetPathToExpectedOutputPath; + + IntegrationTestConfig(this.name, + {Map inputs, Map outputs}) + : this.assetPathToInputPath = inputs, + this.assetPathToExpectedOutputPath = outputs; +} + +void allTests() { + /* + * Each test has its own directory for inputs & an `expected` directory for + * expected outputs. + * + * In addition to these declared inputs, we inject a set of common inputs for + * every test. + */ + var commonInputs = { + 'angular2|lib/src/core/annotations/annotations.dart': + '../../../lib/src/core/annotations/annotations.dart', + 'angular2|lib/src/core/application.dart': '../common/application.dart', + 'angular2|lib/src/reflection/reflection_capabilities.dart': + '../common/reflection_capabilities.dart' + }; + + var tests = [ + new IntegrationTestConfig( + 'should generate proper code for a Component defining only a selector.', + inputs: { + 'a|web/index.dart': 'simple_annotation_files/index.dart', + 'a|web/bar.dart': 'simple_annotation_files/bar.dart' + }, + outputs: { + 'a|web/bar.ngDeps.dart': + 'simple_annotation_files/expected/bar.ngDeps.dart', + 'a|web/index.ngDeps.dart': + 'simple_annotation_files/expected/index.ngDeps.dart' + }), + new IntegrationTestConfig( + 'should generate proper code for a Component using a selector defined ' + 'in another file.', + inputs: { + 'a|web/index.dart': 'two_deps_files/index.dart', + 'a|web/foo.dart': 'two_deps_files/foo.dart', + 'a|web/bar.dart': 'two_deps_files/bar.dart' + }, + outputs: { + 'a|web/bar.ngDeps.dart': 'two_deps_files/expected/bar.ngDeps.dart' + }), + new IntegrationTestConfig( + 'should generate proper code for a Component declaring a ' + 'componentService defined in another file.', + inputs: { + 'a|web/index.dart': 'list_of_types_files/index.dart', + 'a|web/foo.dart': 'list_of_types_files/foo.dart', + 'a|web/bar.dart': 'list_of_types_files/bar.dart' + }, + outputs: { + 'a|web/bar.ngDeps.dart': 'list_of_types_files/expected/bar.ngDeps.dart' + }), + new IntegrationTestConfig( + 'should generate a factory for a class with no declared ctor.', + inputs: { + 'a|web/index.dart': 'synthetic_ctor_files/index.dart', + 'a|web/bar.dart': 'synthetic_ctor_files/bar.dart' + }, + outputs: { + 'a|web/bar.ngDeps.dart': 'synthetic_ctor_files/expected/bar.ngDeps.dart' + }), + new IntegrationTestConfig('should preserve multiple annotations.', + inputs: { + 'a|web/index.dart': 'two_annotations_files/index.dart', + 'a|web/bar.dart': 'two_annotations_files/bar.dart', + 'angular2|lib/src/core/annotations/template.dart': + '../../../lib/src/core/annotations/template.dart' + }, + 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: { + 'a|web/index.dart': 'chained_deps_files/index.dart', + 'a|web/foo.dart': 'chained_deps_files/foo.dart', + 'a|web/bar.dart': 'chained_deps_files/bar.dart' + }, + outputs: { + 'a|web/bar.ngDeps.dart': 'chained_deps_files/expected/bar.ngDeps.dart', + 'a|web/foo.ngDeps.dart': 'chained_deps_files/expected/foo.ngDeps.dart' + }) + ]; + + var cache = {}; + + for (var config in tests) { + + // Read in input & output files. + config.assetPathToInputPath + ..addAll(commonInputs) + ..forEach((key, value) { + config.assetPathToInputPath[key] = + cache.putIfAbsent(value, () => _readFile(value)); + }); + config.assetPathToExpectedOutputPath.forEach((key, value) { + config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () { + var code = _readFile(value); + return value.endsWith('dart') ? formatter.format(code) : code; + }); + }); + testPhases(config.name, [ + [transform] + ], config.assetPathToInputPath, config.assetPathToExpectedOutputPath, []); + } +} + +/// Smooths over differences in CWD between IDEs and running tests in Travis. +String _readFile(String path) => readFile('integration/$path'); diff --git a/modules/angular2/test/transform/basic_bind_files/bar.dart b/modules/angular2/test/transform/integration/basic_bind_files/bar.dart similarity index 100% rename from modules/angular2/test/transform/basic_bind_files/bar.dart rename to modules/angular2/test/transform/integration/basic_bind_files/bar.dart diff --git a/modules/angular2/test/transform/basic_bind_files/expected/bar.ngDeps.dart b/modules/angular2/test/transform/integration/basic_bind_files/expected/bar.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/basic_bind_files/expected/bar.ngDeps.dart rename to modules/angular2/test/transform/integration/basic_bind_files/expected/bar.ngDeps.dart diff --git a/modules/angular2/test/transform/basic_bind_files/index.dart b/modules/angular2/test/transform/integration/basic_bind_files/index.dart similarity index 100% rename from modules/angular2/test/transform/basic_bind_files/index.dart rename to modules/angular2/test/transform/integration/basic_bind_files/index.dart diff --git a/modules/angular2/test/transform/chained_deps_files/bar.dart b/modules/angular2/test/transform/integration/chained_deps_files/bar.dart similarity index 100% rename from modules/angular2/test/transform/chained_deps_files/bar.dart rename to modules/angular2/test/transform/integration/chained_deps_files/bar.dart diff --git a/modules/angular2/test/transform/chained_deps_files/expected/bar.ngDeps.dart b/modules/angular2/test/transform/integration/chained_deps_files/expected/bar.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/chained_deps_files/expected/bar.ngDeps.dart rename to modules/angular2/test/transform/integration/chained_deps_files/expected/bar.ngDeps.dart diff --git a/modules/angular2/test/transform/chained_deps_files/expected/foo.ngDeps.dart b/modules/angular2/test/transform/integration/chained_deps_files/expected/foo.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/chained_deps_files/expected/foo.ngDeps.dart rename to modules/angular2/test/transform/integration/chained_deps_files/expected/foo.ngDeps.dart diff --git a/modules/angular2/test/transform/chained_deps_files/expected/index.ngDeps.dart b/modules/angular2/test/transform/integration/chained_deps_files/expected/index.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/chained_deps_files/expected/index.ngDeps.dart rename to modules/angular2/test/transform/integration/chained_deps_files/expected/index.ngDeps.dart diff --git a/modules/angular2/test/transform/chained_deps_files/foo.dart b/modules/angular2/test/transform/integration/chained_deps_files/foo.dart similarity index 100% rename from modules/angular2/test/transform/chained_deps_files/foo.dart rename to modules/angular2/test/transform/integration/chained_deps_files/foo.dart diff --git a/modules/angular2/test/transform/chained_deps_files/index.dart b/modules/angular2/test/transform/integration/chained_deps_files/index.dart similarity index 100% rename from modules/angular2/test/transform/chained_deps_files/index.dart rename to modules/angular2/test/transform/integration/chained_deps_files/index.dart diff --git a/modules/angular2/test/transform/list_of_types_files/bar.dart b/modules/angular2/test/transform/integration/list_of_types_files/bar.dart similarity index 100% rename from modules/angular2/test/transform/list_of_types_files/bar.dart rename to modules/angular2/test/transform/integration/list_of_types_files/bar.dart diff --git a/modules/angular2/test/transform/list_of_types_files/expected/bar.ngDeps.dart b/modules/angular2/test/transform/integration/list_of_types_files/expected/bar.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/list_of_types_files/expected/bar.ngDeps.dart rename to modules/angular2/test/transform/integration/list_of_types_files/expected/bar.ngDeps.dart diff --git a/modules/angular2/test/transform/list_of_types_files/foo.dart b/modules/angular2/test/transform/integration/list_of_types_files/foo.dart similarity index 100% rename from modules/angular2/test/transform/list_of_types_files/foo.dart rename to modules/angular2/test/transform/integration/list_of_types_files/foo.dart diff --git a/modules/angular2/test/transform/list_of_types_files/index.dart b/modules/angular2/test/transform/integration/list_of_types_files/index.dart similarity index 100% rename from modules/angular2/test/transform/list_of_types_files/index.dart rename to modules/angular2/test/transform/integration/list_of_types_files/index.dart diff --git a/modules/angular2/test/transform/simple_annotation_files/bar.dart b/modules/angular2/test/transform/integration/simple_annotation_files/bar.dart similarity index 100% rename from modules/angular2/test/transform/simple_annotation_files/bar.dart rename to modules/angular2/test/transform/integration/simple_annotation_files/bar.dart diff --git a/modules/angular2/test/transform/simple_annotation_files/expected/bar.ngDeps.dart b/modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/simple_annotation_files/expected/bar.ngDeps.dart rename to modules/angular2/test/transform/integration/simple_annotation_files/expected/bar.ngDeps.dart diff --git a/modules/angular2/test/transform/simple_annotation_files/expected/index.ngDeps.dart b/modules/angular2/test/transform/integration/simple_annotation_files/expected/index.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/simple_annotation_files/expected/index.ngDeps.dart rename to modules/angular2/test/transform/integration/simple_annotation_files/expected/index.ngDeps.dart diff --git a/modules/angular2/test/transform/simple_annotation_files/index.dart b/modules/angular2/test/transform/integration/simple_annotation_files/index.dart similarity index 100% rename from modules/angular2/test/transform/simple_annotation_files/index.dart rename to modules/angular2/test/transform/integration/simple_annotation_files/index.dart diff --git a/modules/angular2/test/transform/synthetic_ctor_files/bar.dart b/modules/angular2/test/transform/integration/synthetic_ctor_files/bar.dart similarity index 100% rename from modules/angular2/test/transform/synthetic_ctor_files/bar.dart rename to modules/angular2/test/transform/integration/synthetic_ctor_files/bar.dart diff --git a/modules/angular2/test/transform/synthetic_ctor_files/expected/bar.ngDeps.dart b/modules/angular2/test/transform/integration/synthetic_ctor_files/expected/bar.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/synthetic_ctor_files/expected/bar.ngDeps.dart rename to modules/angular2/test/transform/integration/synthetic_ctor_files/expected/bar.ngDeps.dart diff --git a/modules/angular2/test/transform/synthetic_ctor_files/index.dart b/modules/angular2/test/transform/integration/synthetic_ctor_files/index.dart similarity index 100% rename from modules/angular2/test/transform/synthetic_ctor_files/index.dart rename to modules/angular2/test/transform/integration/synthetic_ctor_files/index.dart diff --git a/modules/angular2/test/transform/two_annotations_files/bar.dart b/modules/angular2/test/transform/integration/two_annotations_files/bar.dart similarity index 100% rename from modules/angular2/test/transform/two_annotations_files/bar.dart rename to modules/angular2/test/transform/integration/two_annotations_files/bar.dart diff --git a/modules/angular2/test/transform/two_annotations_files/expected/bar.ngDeps.dart b/modules/angular2/test/transform/integration/two_annotations_files/expected/bar.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/two_annotations_files/expected/bar.ngDeps.dart rename to modules/angular2/test/transform/integration/two_annotations_files/expected/bar.ngDeps.dart diff --git a/modules/angular2/test/transform/two_annotations_files/index.dart b/modules/angular2/test/transform/integration/two_annotations_files/index.dart similarity index 100% rename from modules/angular2/test/transform/two_annotations_files/index.dart rename to modules/angular2/test/transform/integration/two_annotations_files/index.dart diff --git a/modules/angular2/test/transform/two_deps_files/bar.dart b/modules/angular2/test/transform/integration/two_deps_files/bar.dart similarity index 100% rename from modules/angular2/test/transform/two_deps_files/bar.dart rename to modules/angular2/test/transform/integration/two_deps_files/bar.dart diff --git a/modules/angular2/test/transform/two_deps_files/expected/bar.ngDeps.dart b/modules/angular2/test/transform/integration/two_deps_files/expected/bar.ngDeps.dart similarity index 100% rename from modules/angular2/test/transform/two_deps_files/expected/bar.ngDeps.dart rename to modules/angular2/test/transform/integration/two_deps_files/expected/bar.ngDeps.dart diff --git a/modules/angular2/test/transform/two_deps_files/foo.dart b/modules/angular2/test/transform/integration/two_deps_files/foo.dart similarity index 100% rename from modules/angular2/test/transform/two_deps_files/foo.dart rename to modules/angular2/test/transform/integration/two_deps_files/foo.dart diff --git a/modules/angular2/test/transform/two_deps_files/index.dart b/modules/angular2/test/transform/integration/two_deps_files/index.dart similarity index 100% rename from modules/angular2/test/transform/two_deps_files/index.dart rename to modules/angular2/test/transform/integration/two_deps_files/index.dart diff --git a/modules/angular2/test/transform/reflection_remover/all_tests.dart b/modules/angular2/test/transform/reflection_remover/all_tests.dart new file mode 100644 index 0000000000..4291b5dae1 --- /dev/null +++ b/modules/angular2/test/transform/reflection_remover/all_tests.dart @@ -0,0 +1,21 @@ +library angular2.test.transform.reflection_remover; + +import 'package:analyzer/analyzer.dart'; +import 'package:angular2/src/transform/reflection_remover/codegen.dart'; +import 'package:angular2/src/transform/reflection_remover/rewriter.dart'; +import 'package:unittest/unittest.dart'; + +import 'reflection_remover_files/expected/index.dart' as expected; +import '../common/read_file.dart'; + +void allTests() { + var codegen = new Codegen('web/index.dart', 'web/index.ngDeps.dart'); + + test('should remove uses of mirrors & insert calls to generated code', () { + var code = + readFile('reflection_remover/reflection_remover_files/index.dart'); + var output = + new Rewriter(code, codegen).rewrite(parseCompilationUnit(code)); + expect(output, equals(expected.code)); + }); +} diff --git a/modules/angular2/test/transform/reflection_remover_files/README.md b/modules/angular2/test/transform/reflection_remover/reflection_remover_files/README.md similarity index 100% rename from modules/angular2/test/transform/reflection_remover_files/README.md rename to modules/angular2/test/transform/reflection_remover/reflection_remover_files/README.md diff --git a/modules/angular2/test/transform/reflection_remover_files/expected/index.dart b/modules/angular2/test/transform/reflection_remover/reflection_remover_files/expected/index.dart similarity index 100% rename from modules/angular2/test/transform/reflection_remover_files/expected/index.dart rename to modules/angular2/test/transform/reflection_remover/reflection_remover_files/expected/index.dart diff --git a/modules/angular2/test/transform/reflection_remover_files/index.dart b/modules/angular2/test/transform/reflection_remover/reflection_remover_files/index.dart similarity index 100% rename from modules/angular2/test/transform/reflection_remover_files/index.dart rename to modules/angular2/test/transform/reflection_remover/reflection_remover_files/index.dart diff --git a/modules/angular2/test/transform/simple_annotation_files/expected/index.dart b/modules/angular2/test/transform/simple_annotation_files/expected/index.dart deleted file mode 100644 index 65a6b9b1f1..0000000000 --- a/modules/angular2/test/transform/simple_annotation_files/expected/index.dart +++ /dev/null @@ -1,13 +0,0 @@ -library web_foo; - -import 'package:angular2/src/core/application.dart'; -import 'package:angular2/src/reflection/reflection.dart'; -import 'index.ngDeps.dart' as ngStaticInit; -import 'package:angular2/src/reflection/reflection_capabilities.dart'; -import 'bar.dart'; - -void main() { - ngStaticInit.setupReflection(reflector); - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules/angular2/test/transform/transform.server.spec.dart b/modules/angular2/test/transform/transform.server.spec.dart index 78d6be5e22..7ed038417a 100644 --- a/modules/angular2/test/transform/transform.server.spec.dart +++ b/modules/angular2/test/transform/transform.server.spec.dart @@ -1,153 +1,15 @@ library angular2.test.transform; -import 'dart:io'; -import 'package:barback/barback.dart'; -import 'package:angular2/transformer.dart'; -import 'package:code_transformers/tests.dart'; -import 'package:dart_style/dart_style.dart'; import 'package:unittest/unittest.dart'; import 'package:unittest/vm_config.dart'; -import 'reflection_remover_files/expected/index.dart' - as reflection_remover_output; +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('Integration tests:', _integrationTests); -} - -var formatter = new DartFormatter(); -var transform = new AngularTransformerGroup(new TransformerOptions( - 'web/index.dart', reflectionEntryPoint: 'web/index.dart')); - -class IntegrationTestConfig { - final String name; - final Map assetPathToInputPath; - final Map assetPathToExpectedOutputPath; - - IntegrationTestConfig(this.name, - {Map inputs, Map outputs}) - : this.assetPathToInputPath = inputs, - this.assetPathToExpectedOutputPath = outputs; -} - -void _integrationTests() { - /* - * Each test has its own directory for inputs & an `expected` directory for - * expected outputs. - * - * In addition to these declared inputs, we inject a set of common inputs for - * every test. - */ - var commonInputs = { - 'angular2|lib/src/core/annotations/annotations.dart': - '../../lib/src/core/annotations/annotations.dart', - 'angular2|lib/src/core/application.dart': 'common/application.dart', - 'angular2|lib/src/reflection/reflection_capabilities.dart': - 'common/reflection_capabilities.dart' - }; - - var tests = [ - new IntegrationTestConfig('Simple', - inputs: { - 'a|web/index.dart': 'simple_annotation_files/index.dart', - 'a|web/bar.dart': 'simple_annotation_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngDeps.dart': - 'simple_annotation_files/expected/bar.ngDeps.dart', - 'a|web/index.ngDeps.dart': - 'simple_annotation_files/expected/index.ngDeps.dart' - }), - new IntegrationTestConfig('Reflection Remover', - inputs: {'a|web/index.dart': 'reflection_remover_files/index.dart'}, - outputs: {'a|web/index.dart': reflection_remover_output.code}), - new IntegrationTestConfig('Two injected dependencies', - inputs: { - 'a|web/index.dart': 'two_deps_files/index.dart', - 'a|web/foo.dart': 'two_deps_files/foo.dart', - 'a|web/bar.dart': 'two_deps_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngDeps.dart': 'two_deps_files/expected/bar.ngDeps.dart' - }), - new IntegrationTestConfig('List of types', - inputs: { - 'a|web/index.dart': 'list_of_types_files/index.dart', - 'a|web/foo.dart': 'list_of_types_files/foo.dart', - 'a|web/bar.dart': 'list_of_types_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngDeps.dart': 'list_of_types_files/expected/bar.ngDeps.dart' - }), - new IntegrationTestConfig('Component with synthetic Constructor', - inputs: { - 'a|web/index.dart': 'synthetic_ctor_files/index.dart', - 'a|web/bar.dart': 'synthetic_ctor_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngDeps.dart': 'synthetic_ctor_files/expected/bar.ngDeps.dart' - }), - new IntegrationTestConfig('Component with two annotations', - inputs: { - 'a|web/index.dart': 'two_annotations_files/index.dart', - 'a|web/bar.dart': 'two_annotations_files/bar.dart', - 'angular2|lib/src/core/annotations/template.dart': - '../../lib/src/core/annotations/template.dart' - }, - outputs: { - 'a|web/bar.ngDeps.dart': 'two_annotations_files/expected/bar.ngDeps.dart' - }), - new IntegrationTestConfig('Basic `bind`', - 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('Chained dependencies', - inputs: { - 'a|web/index.dart': 'chained_deps_files/index.dart', - 'a|web/foo.dart': 'chained_deps_files/foo.dart', - 'a|web/bar.dart': 'chained_deps_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngDeps.dart': 'chained_deps_files/expected/bar.ngDeps.dart', - 'a|web/foo.ngDeps.dart': 'chained_deps_files/expected/foo.ngDeps.dart' - }) - ]; - - var cache = {}; - - for (var config in tests) { - - // Read in input & output files. - config.assetPathToInputPath - ..addAll(commonInputs) - ..forEach((key, value) { - config.assetPathToInputPath[key] = - cache.putIfAbsent(value, () => _readFile(value)); - }); - config.assetPathToExpectedOutputPath.forEach((key, value) { - config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () { - var code = _readFile(value); - return value.endsWith('dart') ? formatter.format(code) : code; - }); - }); - testPhases(config.name, [ - [transform] - ], config.assetPathToInputPath, config.assetPathToExpectedOutputPath, []); - } -} - -/// Smooths over differences in CWD between IDEs and running tests in Travis. -String _readFile(String path) { - for (var myPath in [path, 'test/transform/${path}']) { - var file = new File(myPath); - if (file.existsSync()) { - return file.readAsStringSync(); - } - } - return path; + group('Directive Processor', directiveProcessor.allTests); + group('Reflection Remover', reflectionRemover.allTests); + group('Transformer Pipeline', integration.allTests); }