|
4 | 4 |
|
5 | 5 | library dartdoc.html_generator_test;
|
6 | 6 |
|
7 |
| -import 'package:test/test.dart'; |
| 7 | +import 'dart:io' show File, Directory, FileSystemEntity, FileSystemEntityType; |
8 | 8 |
|
| 9 | +import 'package:path/path.dart' as p; |
| 10 | +import 'package:test/test.dart'; |
9 | 11 | import 'package:dartdoc/src/html_generator.dart';
|
10 | 12 |
|
11 | 13 | void main() {
|
@@ -66,6 +68,54 @@ void main() {
|
66 | 68 |
|
67 | 69 | group('HtmlGenerator', () {
|
68 | 70 | // TODO: Run the HtmlGenerator and validate important constraints.
|
69 |
| - |
| 71 | + group('for a null package', () { |
| 72 | + HtmlGenerator generator; |
| 73 | + Directory tempOutput; |
| 74 | + |
| 75 | + setUp(() async { |
| 76 | + generator = new HtmlGenerator(null); |
| 77 | + tempOutput = Directory.systemTemp.createTempSync('doc_test_temp'); |
| 78 | + return generator.generate(null, tempOutput); |
| 79 | + }); |
| 80 | + |
| 81 | + tearDown(() { |
| 82 | + if (tempOutput != null) { |
| 83 | + tempOutput.deleteSync(recursive: true); |
| 84 | + } |
| 85 | + }); |
| 86 | + |
| 87 | + test('resources are put into the right place', () { |
| 88 | + Directory output = |
| 89 | + new Directory(p.join(tempOutput.path, 'static-assets')); |
| 90 | + expect(output, doesExist); |
| 91 | + new Directory(p.join('lib', 'resources')) |
| 92 | + .listSync(recursive: true) |
| 93 | + .forEach((FileSystemEntity f) { |
| 94 | + if (f.statSync().type == FileSystemEntityType.FILE) { |
| 95 | + String subPath = |
| 96 | + f.path.substring(p.join('lib', 'resources').length + 1); |
| 97 | + expect(new File(p.join(output.path, subPath)), doesExist); |
| 98 | + } |
| 99 | + }); |
| 100 | + }); |
| 101 | + }); |
70 | 102 | });
|
71 | 103 | }
|
| 104 | + |
| 105 | +const Matcher doesExist = const _DoesExist(); |
| 106 | + |
| 107 | +class _DoesExist extends Matcher { |
| 108 | + const _DoesExist(); |
| 109 | + bool matches(item, Map matchState) => item.existsSync(); |
| 110 | + Description describe(Description description) => description.add('exists'); |
| 111 | + Description describeMismatch( |
| 112 | + item, Description mismatchDescription, Map matchState, bool verbose) { |
| 113 | + if (item is! File && item is! Directory) { |
| 114 | + return mismatchDescription |
| 115 | + .addDescriptionOf(item) |
| 116 | + .add('is not a file or directory'); |
| 117 | + } else { |
| 118 | + return mismatchDescription.add(' does not exist'); |
| 119 | + } |
| 120 | + } |
| 121 | +} |
0 commit comments