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 async_await_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 m1() sync* { | |
27 yield 0; | |
28 } | |
29 | |
30 m2() async { | |
31 await 0; | |
32 await for (var e in m1()) {} | |
33 } | |
34 | |
35 m3() async* { | |
36 yield* m1(); | |
37 } | |
38 } | |
39 | |
40 m1() sync* { | |
41 yield 0; | |
42 } | |
43 | |
44 m2() async { | |
45 await 0; | |
46 await for (var e in m1()) {} | |
47 } | |
48 | |
49 m3() async* { | |
50 yield* m1(); | |
51 } | |
52 | |
53 main() { | |
54 m1(); | |
55 m2(); | |
56 m3(); | |
57 A a = new A(); | |
58 a.m1(); | |
59 a.m2(); | |
60 a.m3(); | |
61 } | |
62 '''; | |
63 | |
64 main() { | |
65 group('Generate docs for', () { | |
66 test('file with async/await.', () { | |
67 var temporaryDir = Directory.systemTemp.createTempSync('single_library_'); | |
68 var fileName = path.join(temporaryDir.path, 'temp.dart'); | |
69 var file = new File(fileName); | |
70 file.writeAsStringSync(DART_LIBRARY); | |
71 | |
72 return getMirrorSystem([new Uri.file(fileName)], false) | |
73 .then((mirrorSystem) { | |
74 var testLibraryUri = new Uri.file(path.absolute(fileName), | |
75 windows: Platform.isWindows); | |
76 var library = new Library(mirrorSystem.libraries[testLibraryUri]); | |
77 expect(library is Library, isTrue); | |
78 | |
79 var classTypes = library.classes; | |
80 var classes = []; | |
81 classes.addAll(classTypes.values); | |
82 classes.addAll(library.errors.values); | |
83 expect(classes.every((e) => e is Class), isTrue); | |
84 | |
85 expect(library.typedefs.values.every((e) => e is Typedef), isTrue); | |
86 | |
87 var classMethodTypes = []; | |
88 classes.forEach((e) { | |
89 classMethodTypes.add(e.methods); | |
90 classMethodTypes.add(e.inheritedMethods); | |
91 }); | |
92 expect(classMethodTypes.every((e) => e is Map<String, Method>), | |
93 isTrue); | |
94 | |
95 var classMethods = []; | |
96 classMethodTypes.forEach((e) { | |
97 classMethods.addAll(e.values); | |
98 }); | |
99 expect(classMethods.every((e) => e is Method), isTrue); | |
100 | |
101 var methodParameters = []; | |
102 classMethods.forEach((e) { | |
103 methodParameters.addAll(e.parameters.values); | |
104 }); | |
105 expect(methodParameters.every((e) => e is Parameter), isTrue); | |
106 | |
107 var functionTypes = library.functions; | |
108 expect(functionTypes is Map<String, Method>, isTrue); | |
109 | |
110 var functions = []; | |
111 functions.addAll(functionTypes.values); | |
112 expect(functions.every((e) => e is Method), isTrue); | |
113 | |
114 var functionParameters = []; | |
115 functions.forEach((e) { | |
116 functionParameters.addAll(e.parameters.values); | |
117 }); | |
118 expect(functionParameters.every((e) => e is Parameter), isTrue); | |
119 | |
120 var variables = library.variables.values; | |
121 expect(variables.every((e) => e is Variable), isTrue); | |
122 | |
123 /// Testing fixReference | |
124 // Testing Doc comment for class [A]. | |
125 var libraryMirror = mirrorSystem.libraries[testLibraryUri]; | |
126 var classMirror = | |
127 dart2js_util.classesOf(libraryMirror.declarations).first; | |
128 var classDocComment = library.fixReference('A').children.first.text; | |
129 expect(classDocComment, 'test.A'); | |
130 | |
131 // Test for linking to parameter [A] | |
132 var method = getDocgenObject( | |
133 classMirror.declarations[dart2js_util.symbolOf('m1')]); | |
134 | |
135 // Testing trying to refer to m1 method | |
136 var methodDocComment = method.fixReference( | |
137 'm1').children.first.text; | |
138 expect(methodDocComment, 'test.A.m1'); | |
139 | |
140 // Testing something with no reference | |
141 var libraryDocComment = method.fixReference('foobar').text; | |
142 expect(libraryDocComment, 'foobar'); | |
143 | |
144 // Testing trying to refer to m1 function | |
145 libraryDocComment = library.fixReference('m1').children.first.text; | |
146 expect(libraryDocComment, 'test.m1'); | |
147 }).whenComplete(() => temporaryDir.deleteSync(recursive: true)); | |
148 }); | |
149 }); | |
150 } | |
OLD | NEW |