|
| 1 | +library angular2.test.transform.common.code.ng_deps_code_tests; |
| 2 | + |
| 3 | +import 'package:analyzer/analyzer.dart'; |
| 4 | +import 'package:angular2/src/transform/common/code/ng_deps_code.dart'; |
| 5 | +import 'package:angular2/src/transform/common/model/import_export_model.pb.dart'; |
| 6 | +import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart'; |
| 7 | +import 'package:guinness/guinness.dart'; |
| 8 | + |
| 9 | +main() => allTests(); |
| 10 | + |
| 11 | +void allTests() { |
| 12 | + describe('writeNgDepsModel', () { |
| 13 | + it('should output parsable code', () async { |
| 14 | + final ngDeps = new NgDepsModel() |
| 15 | + ..libraryUri = 'test.foo' |
| 16 | + ..imports.add(new ImportModel() |
| 17 | + ..uri = 'bar.dart' |
| 18 | + ..prefix = 'dep'); |
| 19 | + |
| 20 | + final buf = new StringBuffer(); |
| 21 | + final writer = new NgDepsWriter(buf); |
| 22 | + writer.writeNgDepsModel(ngDeps); |
| 23 | + |
| 24 | + var compilationUnit = parseCompilationUnit(buf.toString()); |
| 25 | + |
| 26 | + expect(compilationUnit).toBeNotNull(); |
| 27 | + expect(compilationUnit.declarations).toBeNotNull(); |
| 28 | + expect(compilationUnit.declarations.length > 0).toBeTrue(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should output parsable code with deferred imports', () async { |
| 32 | + // Regression test for i/4587. |
| 33 | + final ngDeps = new NgDepsModel() |
| 34 | + ..libraryUri = 'test.foo' |
| 35 | + ..imports.add(new ImportModel() |
| 36 | + ..uri = 'bar.dart' |
| 37 | + ..isDeferred = true |
| 38 | + ..prefix = 'dep'); |
| 39 | + |
| 40 | + final buf = new StringBuffer(); |
| 41 | + final writer = new NgDepsWriter(buf); |
| 42 | + writer.writeNgDepsModel(ngDeps); |
| 43 | + |
| 44 | + var compilationUnit = parseCompilationUnit(buf.toString()); |
| 45 | + |
| 46 | + expect(compilationUnit).toBeNotNull(); |
| 47 | + expect(compilationUnit.declarations).toBeNotNull(); |
| 48 | + expect(compilationUnit.declarations.length > 0).toBeTrue(); |
| 49 | + }); |
| 50 | + }); |
| 51 | +} |
0 commit comments