OLD | NEW |
(Empty) | |
| 1 library single_library_test; |
| 2 |
| 3 import 'dart:io'; |
| 4 |
| 5 import 'package:path/path.dart' as path; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 |
| 8 import '../lib/docgen.dart'; |
| 9 |
| 10 const String DART_LIBRARY_1 = ''' |
| 11 library testLib; |
| 12 import 'temp2.dart'; |
| 13 import 'temp3.dart'; |
| 14 export 'temp2.dart'; |
| 15 export 'temp3.dart'; |
| 16 |
| 17 /** |
| 18 * Doc comment for class [A]. |
| 19 * |
| 20 * Multiline Test |
| 21 */ |
| 22 /* |
| 23 * Normal comment for class A. |
| 24 */ |
| 25 class A { |
| 26 |
| 27 int _someNumber; |
| 28 |
| 29 A() { |
| 30 _someNumber = 12; |
| 31 } |
| 32 |
| 33 A.customConstructor(); |
| 34 |
| 35 /** |
| 36 * Test for linking to parameter [A] |
| 37 */ |
| 38 void doThis(int A) { |
| 39 print(A); |
| 40 } |
| 41 } |
| 42 '''; |
| 43 |
| 44 const String DART_LIBRARY_2 = ''' |
| 45 library testLib2.foo; |
| 46 import 'temp.dart'; |
| 47 |
| 48 /** |
| 49 * Doc comment for class [B]. |
| 50 * |
| 51 * Multiline Test |
| 52 */ |
| 53 |
| 54 /* |
| 55 * Normal comment for class B. |
| 56 */ |
| 57 class B extends A { |
| 58 |
| 59 B(); |
| 60 B.fooBar(); |
| 61 |
| 62 /** |
| 63 * Test for linking to super |
| 64 */ |
| 65 int doElse(int b) { |
| 66 print(b); |
| 67 } |
| 68 |
| 69 /** |
| 70 * Test for linking to parameter [c] |
| 71 */ |
| 72 void doThis(int c) { |
| 73 print(a); |
| 74 } |
| 75 } |
| 76 |
| 77 int testFunc(int a) { |
| 78 } |
| 79 '''; |
| 80 |
| 81 const String DART_LIBRARY_3 = ''' |
| 82 library testLib.bar; |
| 83 import 'temp.dart'; |
| 84 |
| 85 /* |
| 86 * Normal comment for class C. |
| 87 */ |
| 88 class C { |
| 89 } |
| 90 '''; |
| 91 |
| 92 Directory TEMP_DIRNAME; |
| 93 |
| 94 List writeLibFiles() { |
| 95 TEMP_DIRNAME = Directory.systemTemp.createTempSync('single_library_'); |
| 96 var fileName = path.join(TEMP_DIRNAME.path, 'temp.dart'); |
| 97 var file = new File(fileName); |
| 98 file.writeAsStringSync(DART_LIBRARY_1); |
| 99 |
| 100 var fileName2 = path.join(TEMP_DIRNAME.path, 'temp2.dart'); |
| 101 file = new File(fileName2); |
| 102 file.writeAsStringSync(DART_LIBRARY_2); |
| 103 |
| 104 var fileName3 = path.join(TEMP_DIRNAME.path, 'temp3.dart'); |
| 105 file = new File(fileName3); |
| 106 file.writeAsStringSync(DART_LIBRARY_3); |
| 107 return [new Uri.file(fileName), new Uri.file(fileName3), |
| 108 new Uri.file(fileName3)]; |
| 109 } |
| 110 |
| 111 main() { |
| 112 group('Generate docs for', () { |
| 113 test('multiple libraries.', () { |
| 114 var files = writeLibFiles(); |
| 115 getMirrorSystem(files) |
| 116 .then(expectAsync1((mirrorSystem) { |
| 117 var testLibraryUri = files[0]; |
| 118 var library = new Library(mirrorSystem.libraries[testLibraryUri]); |
| 119 |
| 120 /// Testing fixReference |
| 121 // Testing Doc comment for class [B]. |
| 122 var libraryMirror = mirrorSystem.libraries[testLibraryUri]; |
| 123 var classDocComment = library.fixReference('B').children.first.text; |
| 124 expect(classDocComment, 'testLib.B'); |
| 125 |
| 126 // Test for linking to parameter [c] |
| 127 var importedLib = libraryMirror.libraryDependencies.firstWhere( |
| 128 (dep) => dep.isImport).targetLibrary; |
| 129 var aClassMirror = importedLib.classes.values.first; |
| 130 expect(aClassMirror.qualifiedName, 'testLib2.foo.B'); |
| 131 var exportedClass = getDocgenObject(aClassMirror, library); |
| 132 expect(exportedClass is Class, isTrue); |
| 133 |
| 134 |
| 135 var method = exportedClass.methods['doThis']; |
| 136 expect(method is Method, isTrue); |
| 137 var methodParameterDocComment = method.fixReference( |
| 138 'c').children.first.text; |
| 139 expect(methodParameterDocComment, 'testLib.B.doThis.c'); |
| 140 |
| 141 |
| 142 expect(method.fixReference('A').children.first.text, 'testLib.A'); |
| 143 // Testing trying to refer to doThis function |
| 144 expect(method.fixReference('doThis').children.first.text, |
| 145 'testLib.B.doThis'); |
| 146 |
| 147 // Testing trying to refer to doThis function |
| 148 expect(method.fixReference('doElse').children.first.text, |
| 149 'testLib.B.doElse'); |
| 150 |
| 151 |
| 152 // Test a third library referencing another exported library in a |
| 153 // separate file. |
| 154 importedLib = libraryMirror.libraryDependencies.firstWhere( |
| 155 (dep) => dep.isImport && dep.targetLibrary.qualifiedName == |
| 156 'testLib.bar').targetLibrary; |
| 157 aClassMirror = importedLib.classes.values.first; |
| 158 expect(aClassMirror.qualifiedName, 'testLib.bar.C'); |
| 159 exportedClass = getDocgenObject(aClassMirror, library); |
| 160 expect(exportedClass is Class, isTrue); |
| 161 expect(exportedClass.docName, 'testLib.C'); |
| 162 |
| 163 methodParameterDocComment = exportedClass.fixReference( |
| 164 'B').children.first.text; |
| 165 expect(methodParameterDocComment, 'testLib.B'); |
| 166 |
| 167 methodParameterDocComment = exportedClass.fixReference( |
| 168 'testFunc').children.first.text; |
| 169 expect(methodParameterDocComment, 'testLib.testFunc'); |
| 170 |
| 171 })).whenComplete(() => TEMP_DIRNAME.deleteSync(recursive: true)); |
| 172 }); |
| 173 }); |
| 174 } |
OLD | NEW |