feat(dart/transformer:: Initial commit of ctor stubs & annotation register
Closes #646 Closes #496 Closes #498
This commit is contained in:
11
modules/angular2/test/transform/common.dart
Normal file
11
modules/angular2/test/transform/common.dart
Normal file
@ -0,0 +1,11 @@
|
||||
// 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 initialize.test.build.common;
|
||||
|
||||
// TODO(kegluneq): Remove this and use the actual Directive def'n.
|
||||
// Simple mock of Directive.
|
||||
class Directive {
|
||||
final context;
|
||||
const Directive({this.context});
|
||||
}
|
3
modules/angular2/test/transform/common.html
Normal file
3
modules/angular2/test/transform/common.html
Normal file
@ -0,0 +1,3 @@
|
||||
<html><head></head><body>
|
||||
<script type="application/dart" src="index.dart"></script>
|
||||
</body></html>
|
@ -0,0 +1,9 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
@Directive(context: 'soup')
|
||||
class Component {
|
||||
final dynamic c;
|
||||
Component([this.c = 'sandwich']);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
library web_foo;
|
||||
|
||||
import 'bar.dart';
|
||||
|
||||
void main() {
|
||||
new Component('Things');
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
<html><head></head><body>
|
||||
<script type="application/dart" src="index.bootstrap.dart"></script>
|
||||
</body></html>
|
@ -0,0 +1,5 @@
|
||||
library web_foo;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
void main() {}
|
10
modules/angular2/test/transform/list_of_types_files/bar.dart
Normal file
10
modules/angular2/test/transform/list_of_types_files/bar.dart
Normal file
@ -0,0 +1,10 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
import 'foo.dart';
|
||||
|
||||
@Directive(context: const [MyContext])
|
||||
class Component {
|
||||
final MyContext c;
|
||||
Component(this.c);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import 'package:angular2/src/reflection/reflection.dart' show reflector;
|
||||
import 'bar.dart' as i0;
|
||||
import 'foo.dart' as i1;
|
||||
import 'package:angular2/src/core/annotations/annotations.dart' as i2;
|
||||
import 'index.dart' as i3;
|
||||
|
||||
main() {
|
||||
reflector
|
||||
..registerType(i0.Component, {
|
||||
"factory": (i1.MyContext c) => new i0.Component(c),
|
||||
"parameters": const [const [i1.MyContext]],
|
||||
"annotations": const [const i2.Directive(context: const [i1.MyContext])]
|
||||
});
|
||||
i3.main();
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
library foo;
|
||||
|
||||
class MyContext {
|
||||
final String s;
|
||||
const MyContext(this.s);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
library web_foo;
|
||||
|
||||
import 'bar.dart';
|
||||
|
||||
void main() {
|
||||
new Component('Things');
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
@Directive(context: 'soup')
|
||||
class Component {
|
||||
Component();
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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": () => new i0.Component(),
|
||||
"parameters": const [const []],
|
||||
"annotations": const [const i1.Directive(context: 'soup')]
|
||||
});
|
||||
i2.main();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
library web_foo;
|
||||
|
||||
import 'bar.dart';
|
||||
|
||||
void main() {
|
||||
new Component('Things');
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
@Directive(context: 'soup')
|
||||
class Component {}
|
@ -0,0 +1,14 @@
|
||||
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": () => new i0.Component(),
|
||||
"parameters": const [const []],
|
||||
"annotations": const [const i1.Directive(context: 'soup')]
|
||||
});
|
||||
i2.main();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
library web_foo;
|
||||
|
||||
import 'bar.dart';
|
||||
|
||||
void main() {
|
||||
new Component();
|
||||
}
|
126
modules/angular2/test/transform/transform_test.dart
Normal file
126
modules/angular2/test/transform/transform_test.dart
Normal file
@ -0,0 +1,126 @@
|
||||
library angular2.test;
|
||||
|
||||
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 'common.dart';
|
||||
|
||||
main() {
|
||||
useVMConfiguration();
|
||||
|
||||
// TODO(kegluneq): Add a test for generating multiple annotations.
|
||||
|
||||
group('Annotation tests:', _runTests);
|
||||
}
|
||||
|
||||
var formatter = new DartFormatter();
|
||||
var transform = new AngularTransformer(new TransformerOptions(
|
||||
'web/index.dart', 'web/index.bootstrap.dart', 'web/index.html'));
|
||||
|
||||
class TestConfig {
|
||||
final String name;
|
||||
final Map<String, String> assetPathToInputPath;
|
||||
final Map<String, String> assetPathToExpectedOutputPath;
|
||||
|
||||
TestConfig(this.name,
|
||||
{Map<String, String> inputs, Map<String, String> outputs})
|
||||
: this.assetPathToInputPath = inputs,
|
||||
this.assetPathToExpectedOutputPath = outputs;
|
||||
}
|
||||
|
||||
void _runTests() {
|
||||
// Each test has its own directory for inputs & an `expected` directory for
|
||||
// expected outputs.
|
||||
var tests = [
|
||||
new TestConfig('Html entry point',
|
||||
inputs: {
|
||||
'a|web/index.html': 'common.html',
|
||||
'a|web/index.dart': 'html_entry_point_files/index.dart',
|
||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/index.html': 'html_entry_point_files/expected/index.html'
|
||||
}),
|
||||
new TestConfig('Simple',
|
||||
inputs: {
|
||||
'a|web/index.html': 'common.html',
|
||||
'a|web/index.dart': 'simple_annotation_files/index.dart',
|
||||
'a|web/bar.dart': 'simple_annotation_files/bar.dart',
|
||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/index.bootstrap.dart':
|
||||
'simple_annotation_files/expected/index.bootstrap.dart'
|
||||
}),
|
||||
new TestConfig('Two injected dependencies',
|
||||
inputs: {
|
||||
'a|web/index.html': 'common.html',
|
||||
'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',
|
||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/index.bootstrap.dart':
|
||||
'two_deps_files/expected/index.bootstrap.dart'
|
||||
}),
|
||||
new TestConfig('List of types',
|
||||
inputs: {
|
||||
'a|web/index.html': 'common.html',
|
||||
'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',
|
||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/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',
|
||||
inputs: {
|
||||
'a|web/index.html': 'common.html',
|
||||
'a|web/index.dart': 'synthetic_ctor_files/index.dart',
|
||||
'a|web/bar.dart': 'synthetic_ctor_files/bar.dart',
|
||||
'angular2|lib/src/core/annotations/annotations.dart': 'common.dart'
|
||||
},
|
||||
outputs: {
|
||||
'a|web/index.bootstrap.dart':
|
||||
'synthetic_ctor_files/expected/index.bootstrap.dart'
|
||||
})
|
||||
];
|
||||
|
||||
var cache = {};
|
||||
|
||||
for (var config in tests) {
|
||||
// Read in input & output files.
|
||||
config.assetPathToInputPath.forEach((key, value) {
|
||||
config.assetPathToInputPath[key] =
|
||||
cache.putIfAbsent(value, () => new File(value).readAsStringSync());
|
||||
});
|
||||
config.assetPathToExpectedOutputPath.forEach((key, value) {
|
||||
config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () {
|
||||
var code = new File(value).readAsStringSync();
|
||||
return value.endsWith('dart') ? formatter.format(code) : code;
|
||||
});
|
||||
});
|
||||
testPhases(config.name, [
|
||||
[transform]
|
||||
], config.assetPathToInputPath, config.assetPathToExpectedOutputPath, []);
|
||||
}
|
||||
}
|
13
modules/angular2/test/transform/two_deps_files/bar.dart
Normal file
13
modules/angular2/test/transform/two_deps_files/bar.dart
Normal file
@ -0,0 +1,13 @@
|
||||
library bar;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
import 'foo.dart';
|
||||
|
||||
@Directive(context: const MyContext(contextString))
|
||||
class Component2 {
|
||||
final MyContext c;
|
||||
final String generatedValue;
|
||||
Component2(this.c, String inValue) {
|
||||
generatedValue = 'generated ' + inValue;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
import 'package:angular2/src/reflection/reflection.dart' show reflector;
|
||||
import 'bar.dart' as i0;
|
||||
import 'foo.dart' as i1;
|
||||
import 'package:angular2/src/core/annotations/annotations.dart' as i2;
|
||||
import 'index.dart' as i3;
|
||||
|
||||
main() {
|
||||
reflector
|
||||
..registerType(i0.Component2, {
|
||||
"factory":
|
||||
(i1.MyContext c, String inValue) => new i0.Component2(c, inValue),
|
||||
"parameters": const [const [i1.MyContext, String]],
|
||||
"annotations": const [
|
||||
const i2.Directive(context: const i1.MyContext(i1.contextString))
|
||||
]
|
||||
});
|
||||
i3.main();
|
||||
}
|
8
modules/angular2/test/transform/two_deps_files/foo.dart
Normal file
8
modules/angular2/test/transform/two_deps_files/foo.dart
Normal file
@ -0,0 +1,8 @@
|
||||
library foo;
|
||||
|
||||
const contextString = 'soup';
|
||||
|
||||
class MyContext {
|
||||
final String s;
|
||||
const MyContext(this.s);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
library web_foo;
|
||||
|
||||
import 'bar.dart';
|
||||
|
||||
void main() {
|
||||
new Component('Things');
|
||||
}
|
Reference in New Issue
Block a user