OLD | NEW |
1 import 'dart:io'; | 1 import 'dart:io'; |
2 import 'package:analyzer/analyzer.dart'; | 2 import 'package:analyzer/analyzer.dart'; |
3 import 'package:di/generator.dart' as generator; | 3 import 'package:di/generator.dart' as generator; |
4 import 'package:unittest/unittest.dart'; | 4 import 'package:unittest/unittest.dart'; |
5 | 5 |
6 main(args) => group('generator', () { | 6 main(args) => group('generator', () { |
7 | 7 |
8 test('should codesplit deferred libraries', () { | 8 test('should codesplit deferred libraries', () { |
9 Map<generator.Chunk, String> code = generator.generateCode( | 9 Map<generator.Chunk, String> code = generator.generateCode( |
10 'test/assets/gen_test1/main.dart', ['annotations.Injectable'], | 10 'test_assets/gen_test1/main.dart', ['annotations.InjectableTest'], |
11 Platform.environment['DART_SDK'], [Platform.packageRoot]); | 11 Platform.environment['DART_SDK'], [Platform.packageRoot], 'main.dart'); |
12 | 12 |
13 expect(code.keys.map((chunk) => chunk.library == null ? null : chunk.library
.name), | 13 expect(code.keys.map((chunk) => chunk.library == null ? null : chunk.library
.name), |
14 unorderedEquals([null, 'lib_a', 'lib_b'])); | 14 unorderedEquals([null, 'lib_a', 'lib_b', 'lib_c'])); |
15 | 15 |
16 code.forEach((chunk, code) { | 16 code.forEach((chunk, code) { |
17 var cu = parseCompilationUnit(code); | 17 var cu = parseCompilationUnit(code); |
18 if (chunk.library == null) { | 18 if (chunk.library == null) { |
19 expectHasImports(cu, ['main.dart', 'common1.dart']); | 19 expectHasImports(cu, ['main.dart', 'common1.dart']); |
20 } else if (chunk.library.name.endsWith('lib_a')) { | 20 } else if (chunk.library.name.endsWith('lib_a')) { |
21 expectHasImports(cu, ['a.dart', 'a2.dart', 'common2.dart']); | 21 expectHasImports(cu, ['a.dart', 'a2.dart', 'common2.dart']); |
22 } else if (chunk.library.name.endsWith('lib_b')) { | 22 } else if (chunk.library.name.endsWith('lib_b')) { |
23 expectHasImports(cu, ['b.dart', 'b2.dart', 'common2.dart']); | 23 expectHasImports(cu, ['b.dart', 'b2.dart', 'common2.dart']); |
| 24 } else if (chunk.library.name.endsWith('lib_c')) { |
| 25 expectHasImports(cu, []); |
24 } | 26 } |
25 }); | 27 }); |
26 }); | 28 }); |
27 }); | 29 }); |
28 | 30 |
29 expectHasImports(CompilationUnit cu, List<String> expectedImports) { | 31 expectHasImports(CompilationUnit cu, List<String> expectedImports) { |
30 var imports = <String>[]; | 32 var imports = <String>[]; |
31 cu.directives.forEach((Directive directive) { | 33 cu.directives.forEach((Directive directive) { |
32 if (directive is NamespaceDirective) { | 34 if (directive is NamespaceDirective) { |
33 if (directive is! ImportDirective) { | 35 if (directive is! ImportDirective) { |
34 fail('Only expecting import, no exports.'); | 36 fail('Only expecting import, no exports.'); |
35 } | 37 } |
36 ImportDirective import = directive; | 38 ImportDirective import = directive; |
37 imports.add(import.uri.stringValue); | 39 imports.add(import.uri.stringValue); |
38 } | 40 } |
39 }); | 41 }); |
40 expect(imports.length, equals(expectedImports.length)); | 42 expect(imports.length, equals(expectedImports.length)); |
41 for (int i = 0; i < imports.length; i++) { | 43 for (int i = 0; i < imports.length; i++) { |
42 expect(imports[i], endsWith(expectedImports[i])); | 44 expect(imports[i], endsWith(expectedImports[i])); |
43 } | 45 } |
44 } | 46 } |
OLD | NEW |