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