OLD | NEW |
---|---|
(Empty) | |
1 library angular2.test; | |
2 | |
3 import 'dart:io'; | |
4 import 'package:barback/barback.dart'; | |
5 import 'package:angular2/transformer.dart'; | |
6 import 'package:code_transformers/tests.dart'; | |
7 import 'package:dart_style/dart_style.dart'; | |
8 import 'package:unittest/unittest.dart'; | |
9 import 'package:unittest/vm_config.dart'; | |
10 | |
11 import 'common.dart'; | |
12 | |
13 main() { | |
14 useVMConfiguration(); | |
15 | |
16 // TODO(kegluneq): Add a test for generating multiple annotations. | |
17 | |
18 group('Annotation tests:', _runTests); | |
19 } | |
20 | |
21 var formatter = new DartFormatter(); | |
22 var transform = new AngularTransformer(new TransformerOptions( | |
23 'web/index.dart', 'web/index.bootstrap.dart', 'web/index.html')); | |
24 | |
25 class TestConfig { | |
jakemac
2015/02/18 16:18:50
Personally I kind of like just inlining these file
tjblasi
2015/02/18 21:18:25
I'm pretty ambivalent, but Misko strongly preferre
| |
26 final String name; | |
27 final Map<String, String> assetPathToInputPath; | |
28 final Map<String, String> assetPathToExpectedOutputPath; | |
29 | |
30 TestConfig(this.name, | |
31 {Map<String, String> inputs, Map<String, String> outputs}) | |
32 : this.assetPathToInputPath = inputs, | |
33 this.assetPathToExpectedOutputPath = outputs; | |
34 } | |
35 | |
36 void _runTests() { | |
37 // Each test has its own directory for inputs & an `expected` directory for | |
38 // expected outputs. | |
39 var tests = [ | |
40 new TestConfig('Html entry point', | |
41 inputs: { | |
42 'a|web/index.html': 'common.html', | |
43 'a|web/index.dart': 'html_entry_point_files/index.dart', | |
44 'angular2|lib/src/core/annotations/annotations.dart': 'common.dart' | |
45 }, | |
46 outputs: { | |
47 'a|web/index.html': 'html_entry_point_files/expected/index.html' | |
48 }), | |
49 new TestConfig('Simple', | |
50 inputs: { | |
51 'a|web/index.html': 'common.html', | |
52 'a|web/index.dart': 'simple_annotation_files/index.dart', | |
53 'a|web/bar.dart': 'simple_annotation_files/bar.dart', | |
54 'angular2|lib/src/core/annotations/annotations.dart': 'common.dart' | |
55 }, | |
56 outputs: { | |
57 'a|web/index.bootstrap.dart': | |
58 'simple_annotation_files/expected/index.bootstrap.dart' | |
59 }), | |
60 new TestConfig('Two injected dependencies', | |
61 inputs: { | |
62 'a|web/index.html': 'common.html', | |
63 'a|web/index.dart': 'two_deps_files/index.dart', | |
64 'a|web/foo.dart': 'two_deps_files/foo.dart', | |
65 'a|web/bar.dart': 'two_deps_files/bar.dart', | |
66 'angular2|lib/src/core/annotations/annotations.dart': 'common.dart' | |
67 }, | |
68 outputs: { | |
69 'a|web/index.bootstrap.dart': | |
70 'two_deps_files/expected/index.bootstrap.dart' | |
71 }), | |
72 new TestConfig('List of types', | |
73 inputs: { | |
74 'a|web/index.html': 'common.html', | |
75 'a|web/index.dart': 'list_of_types_files/index.dart', | |
76 'a|web/foo.dart': 'list_of_types_files/foo.dart', | |
77 'a|web/bar.dart': 'list_of_types_files/bar.dart', | |
78 'angular2|lib/src/core/annotations/annotations.dart': 'common.dart' | |
79 }, | |
80 outputs: { | |
81 'a|web/index.bootstrap.dart': | |
82 'list_of_types_files/expected/index.bootstrap.dart' | |
83 }), | |
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 }), | |
95 new TestConfig('Component with synthetic Constructor', | |
96 inputs: { | |
97 'a|web/index.html': 'common.html', | |
98 'a|web/index.dart': 'synthetic_ctor_files/index.dart', | |
99 'a|web/bar.dart': 'synthetic_ctor_files/bar.dart', | |
100 'angular2|lib/src/core/annotations/annotations.dart': 'common.dart' | |
101 }, | |
102 outputs: { | |
103 'a|web/index.bootstrap.dart': | |
104 'synthetic_ctor_files/expected/index.bootstrap.dart' | |
105 }) | |
106 ]; | |
107 | |
108 var cache = {}; | |
109 | |
110 for (var config in tests) { | |
111 // Read in input & output files. | |
112 config.assetPathToInputPath.forEach((key, value) { | |
113 config.assetPathToInputPath[key] = | |
114 cache.putIfAbsent(value, () => new File(value).readAsStringSync()); | |
115 }); | |
116 config.assetPathToExpectedOutputPath.forEach((key, value) { | |
117 config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () { | |
118 var code = new File(value).readAsStringSync(); | |
119 return value.endsWith('dart') ? formatter.format(code) : code; | |
120 }); | |
121 }); | |
122 testPhases(config.name, [ | |
123 [transform] | |
124 ], config.assetPathToInputPath, config.assetPathToExpectedOutputPath, []); | |
125 } | |
126 } | |
OLD | NEW |