| OLD | NEW |
| 1 import 'dart:convert'; | 1 import 'dart:convert'; |
| 2 import 'dart:io'; | 2 import 'dart:io'; |
| 3 |
| 3 import 'package:path/path.dart' as p; | 4 import 'package:path/path.dart' as p; |
| 4 import 'package:scheduled_test/descriptor.dart' as d; | 5 import 'package:scheduled_test/descriptor.dart' as d; |
| 5 import 'package:scheduled_test/scheduled_test.dart'; | 6 import 'package:scheduled_test/scheduled_test.dart'; |
| 6 | 7 |
| 8 import 'util.dart'; |
| 7 import '../lib/docgen.dart' as dg; | 9 import '../lib/docgen.dart' as dg; |
| 8 | 10 |
| 9 void main() { | 11 void main() { |
| 10 | 12 |
| 11 setUp(() { | 13 setUp(() { |
| 12 var tempDir; | 14 var tempDir; |
| 13 schedule(() { | 15 schedule(() { |
| 14 return Directory.systemTemp | 16 return Directory.systemTemp |
| 15 .createTemp('docgen_test-') | 17 .createTemp('docgen_test-') |
| 16 .then((dir) { | 18 .then((dir) { |
| 17 tempDir = dir; | 19 tempDir = dir; |
| 18 d.defaultRoot = tempDir.path; | 20 d.defaultRoot = tempDir.path; |
| 19 }); | 21 }); |
| 20 }); | 22 }); |
| 21 | 23 |
| 22 currentSchedule.onComplete.schedule(() { | 24 currentSchedule.onComplete.schedule(() { |
| 23 d.defaultRoot = null; | 25 d.defaultRoot = null; |
| 24 return tempDir.delete(recursive: true); | 26 return tempDir.delete(recursive: true); |
| 25 }); | 27 }); |
| 26 }); | 28 }); |
| 27 | 29 |
| 28 test('json output', () { | 30 test('json output', () { |
| 29 print(d.defaultRoot); | 31 print(d.defaultRoot); |
| 30 | 32 |
| 31 d.dir('lib', [ | |
| 32 d.file('temp.dart', DART_LIBRARY_1), | |
| 33 d.file('temp2.dart', DART_LIBRARY_2), | |
| 34 d.file('temp3.dart', DART_LIBRARY_3), | |
| 35 ]).create(); | |
| 36 | |
| 37 schedule(() { | 33 schedule(() { |
| 38 return dg.docgen([d.defaultRoot], out: p.join(d.defaultRoot, 'docs')); | 34 var codeDir = getMultiLibraryCodePath(); |
| 35 expect(FileSystemEntity.isDirectorySync(codeDir), isTrue); |
| 36 return dg.docgen(['$codeDir/'], out: p.join(d.defaultRoot, 'docs')); |
| 39 }); | 37 }); |
| 40 | 38 |
| 41 d.dir('docs', [ | 39 d.dir('docs', [ |
| 42 d.matcherFile('index.json', _isJsonMap), | 40 d.matcherFile('index.json', _isJsonMap), |
| 43 d.matcherFile('index.txt', isNotNull), | 41 d.matcherFile('index.txt', isNotNull), |
| 44 d.matcherFile('library_list.json', _isJsonMap), | 42 d.matcherFile('library_list.json', _isJsonMap), |
| 45 d.matcherFile('testLib-bar.C.json', _isJsonMap), | 43 d.matcherFile('testLib-bar.C.json', _isJsonMap), |
| 46 d.matcherFile('testLib-bar.json', _isJsonMap), | 44 d.matcherFile('testLib-bar.json', _isJsonMap), |
| 47 d.matcherFile('testLib.A.json', _isJsonMap), | 45 d.matcherFile('testLib.A.json', _isJsonMap), |
| 48 d.matcherFile('testLib.B.json', _isJsonMap), | 46 d.matcherFile('testLib.B.json', _isJsonMap), |
| 49 d.matcherFile('testLib.C.json', _isJsonMap), | 47 d.matcherFile('testLib.C.json', _isJsonMap), |
| 50 d.matcherFile('testLib.json', _isJsonMap), | 48 d.matcherFile('testLib.json', _isJsonMap), |
| 51 d.matcherFile('testLib2-foo.B.json', _isJsonMap), | 49 d.matcherFile('testLib2-foo.B.json', _isJsonMap), |
| 52 d.matcherFile('testLib2-foo.json', _isJsonMap) | 50 d.matcherFile('testLib2-foo.json', _isJsonMap) |
| 53 ]).validate(); | 51 ]).validate(); |
| 54 }); | 52 }); |
| 55 } | 53 } |
| 56 | 54 |
| 57 final Matcher _isJsonMap = predicate((input) { | 55 final Matcher _isJsonMap = predicate((input) { |
| 58 try { | 56 try { |
| 59 return JSON.decode(input) is Map; | 57 return JSON.decode(input) is Map; |
| 60 } catch (e) { | 58 } catch (e) { |
| 61 return false; | 59 return false; |
| 62 } | 60 } |
| 63 }, 'Output is JSON encoded Map'); | 61 }, 'Output is JSON encoded Map'); |
| 64 | |
| 65 const String DART_LIBRARY_1 = ''' | |
| 66 library testLib; | |
| 67 import 'temp2.dart'; | |
| 68 import 'temp3.dart'; | |
| 69 export 'temp2.dart'; | |
| 70 export 'temp3.dart'; | |
| 71 | |
| 72 /** | |
| 73 * Doc comment for class [A]. | |
| 74 * | |
| 75 * Multiline Test | |
| 76 */ | |
| 77 /* | |
| 78 * Normal comment for class A. | |
| 79 */ | |
| 80 class A { | |
| 81 | |
| 82 int _someNumber; | |
| 83 | |
| 84 A() { | |
| 85 _someNumber = 12; | |
| 86 } | |
| 87 | |
| 88 A.customConstructor(); | |
| 89 | |
| 90 /** | |
| 91 * Test for linking to parameter [A] | |
| 92 */ | |
| 93 void doThis(int A) { | |
| 94 print(A); | |
| 95 } | |
| 96 } | |
| 97 '''; | |
| 98 | |
| 99 const String DART_LIBRARY_2 = ''' | |
| 100 library testLib2.foo; | |
| 101 import 'temp.dart'; | |
| 102 | |
| 103 /** | |
| 104 * Doc comment for class [B]. | |
| 105 * | |
| 106 * Multiline Test | |
| 107 */ | |
| 108 | |
| 109 /* | |
| 110 * Normal comment for class B. | |
| 111 */ | |
| 112 class B extends A { | |
| 113 | |
| 114 B(); | |
| 115 B.fooBar(); | |
| 116 | |
| 117 /** | |
| 118 * Test for linking to super | |
| 119 */ | |
| 120 int doElse(int b) { | |
| 121 print(b); | |
| 122 } | |
| 123 | |
| 124 /** | |
| 125 * Test for linking to parameter [c] | |
| 126 */ | |
| 127 void doThis(int c) { | |
| 128 print(a); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 int testFunc(int a) { | |
| 133 } | |
| 134 '''; | |
| 135 | |
| 136 const String DART_LIBRARY_3 = ''' | |
| 137 library testLib.bar; | |
| 138 import 'temp.dart'; | |
| 139 | |
| 140 /* | |
| 141 * Normal comment for class C. | |
| 142 */ | |
| 143 class C { | |
| 144 } | |
| 145 '''; | |
| OLD | NEW |