OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library single_library_test; | |
6 | |
7 import 'dart:io'; | |
8 | |
9 import 'package:path/path.dart' as path; | |
10 import 'package:unittest/unittest.dart'; | |
11 | |
12 import '../lib/src/exports/mirrors_util.dart' as dart2js_util; | |
13 import '../lib/docgen.dart'; | |
14 | |
15 const String DART_LIBRARY = ''' | |
16 library test; | |
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 /** | |
34 * Test for linking to parameter [A] | |
35 */ | |
36 void doThis(int A) { | |
37 print(A); | |
38 } | |
39 } | |
40 | |
41 main() { | |
42 A a = new A(); | |
43 a.doThis(5); | |
44 } | |
45 '''; | |
46 | |
47 main() { | |
48 group('Generate docs for', () { | |
49 test('one simple file.', () { | |
50 var temporaryDir = Directory.systemTemp.createTempSync('single_library_'); | |
51 var fileName = path.join(temporaryDir.path, 'temp.dart'); | |
52 var file = new File(fileName); | |
53 file.writeAsStringSync(DART_LIBRARY); | |
54 | |
55 return getMirrorSystem([new Uri.file(fileName)], false) | |
56 .then((mirrorSystem) { | |
57 var testLibraryUri = new Uri.file(path.absolute(fileName), | |
58 windows: Platform.isWindows); | |
59 var library = new Library(mirrorSystem.libraries[testLibraryUri]); | |
60 expect(library is Library, isTrue); | |
61 | |
62 var classTypes = library.classes; | |
63 var classes = []; | |
64 classes.addAll(classTypes.values); | |
65 classes.addAll(library.errors.values); | |
66 expect(classes.every((e) => e is Class), isTrue); | |
67 | |
68 expect(library.typedefs.values.every((e) => e is Typedef), isTrue); | |
69 | |
70 var classMethodTypes = []; | |
71 classes.forEach((e) { | |
72 classMethodTypes.add(e.methods); | |
73 classMethodTypes.add(e.inheritedMethods); | |
74 }); | |
75 expect(classMethodTypes.every((e) => e is Map<String, Method>), isTrue
); | |
76 | |
77 var classMethods = []; | |
78 classMethodTypes.forEach((e) { | |
79 classMethods.addAll(e.values); | |
80 }); | |
81 expect(classMethods.every((e) => e is Method), isTrue); | |
82 | |
83 var methodParameters = []; | |
84 classMethods.forEach((e) { | |
85 methodParameters.addAll(e.parameters.values); | |
86 }); | |
87 expect(methodParameters.every((e) => e is Parameter), isTrue); | |
88 | |
89 var functionTypes = library.functions; | |
90 expect(functionTypes is Map<String, Method>, isTrue); | |
91 | |
92 var functions = []; | |
93 functions.addAll(functionTypes.values); | |
94 expect(functions.every((e) => e is Method), isTrue); | |
95 | |
96 var functionParameters = []; | |
97 functions.forEach((e) { | |
98 functionParameters.addAll(e.parameters.values); | |
99 }); | |
100 expect(functionParameters.every((e) => e is Parameter), isTrue); | |
101 | |
102 var variables = library.variables.values; | |
103 expect(variables.every((e) => e is Variable), isTrue); | |
104 | |
105 /// Testing fixReference | |
106 // Testing Doc comment for class [A]. | |
107 var libraryMirror = mirrorSystem.libraries[testLibraryUri]; | |
108 var classMirror = | |
109 dart2js_util.classesOf(libraryMirror.declarations).first; | |
110 var classDocComment = library.fixReference('A').children.first.text; | |
111 expect(classDocComment, 'test.A'); | |
112 | |
113 // Test for linking to parameter [A] | |
114 var method = getDocgenObject( | |
115 classMirror.declarations[dart2js_util.symbolOf('doThis')]); | |
116 var methodParameterDocComment = method.fixReference( | |
117 'A').children.first.text; | |
118 expect(methodParameterDocComment, 'test.A.doThis.A'); | |
119 | |
120 // Testing trying to refer to doThis function | |
121 var methodDocComment = method.fixReference( | |
122 'doThis').children.first.text; | |
123 expect(methodDocComment, 'test.A.doThis'); | |
124 | |
125 // Testing something with no reference | |
126 var libraryDocComment = method.fixReference('foobar').text; | |
127 expect(libraryDocComment, 'foobar'); | |
128 }).whenComplete(() => temporaryDir.deleteSync(recursive: true)); | |
129 }); | |
130 }); | |
131 } | |
OLD | NEW |