Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Side by Side Diff: pkg/docgen/test/async_await_test.dart

Issue 687723007: Add test for docgen of source with async/await. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library single_library_test; 5 library async_await_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:path/path.dart' as path; 9 import 'package:path/path.dart' as path;
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
11 11
12 import '../lib/src/exports/mirrors_util.dart' as dart2js_util; 12 import '../lib/src/exports/mirrors_util.dart' as dart2js_util;
13 import '../lib/docgen.dart'; 13 import '../lib/docgen.dart';
14 14
15 const String DART_LIBRARY = ''' 15 const String DART_LIBRARY = '''
16 library test; 16 library test;
17 /** 17 /**
18 * Doc comment for class [A]. 18 * Doc comment for class [A].
19 * 19 *
20 * Multiline Test 20 * Multiline Test
21 */ 21 */
22 /* 22 /*
23 * Normal comment for class A. 23 * Normal comment for class A.
24 */ 24 */
25 class A { 25 class A {
26 26 m1() sync* {
27 int _someNumber; 27 yield 0;
28
29 A() {
30 _someNumber = 12;
31 } 28 }
32 29
33 /** 30 m2() async {
34 * Test for linking to parameter [A] 31 await 0;
35 */ 32 await for (var e in m1()) {}
36 void doThis(int A) { 33 }
37 print(A); 34
35 m3() async* {
36 yield* m1();
38 } 37 }
39 } 38 }
40 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
41 main() { 53 main() {
54 m1();
55 m2();
56 m3();
42 A a = new A(); 57 A a = new A();
43 a.doThis(5); 58 a.m1();
59 a.m2();
60 a.m3();
44 } 61 }
45 '''; 62 ''';
46 63
47 main() { 64 main() {
48 group('Generate docs for', () { 65 group('Generate docs for', () {
49 test('one simple file.', () { 66 test('file with async/await.', () {
50 var temporaryDir = Directory.systemTemp.createTempSync('single_library_'); 67 var temporaryDir = Directory.systemTemp.createTempSync('single_library_');
51 var fileName = path.join(temporaryDir.path, 'temp.dart'); 68 var fileName = path.join(temporaryDir.path, 'temp.dart');
52 var file = new File(fileName); 69 var file = new File(fileName);
53 file.writeAsStringSync(DART_LIBRARY); 70 file.writeAsStringSync(DART_LIBRARY);
54 71
55 return getMirrorSystem([new Uri.file(fileName)], false) 72 return getMirrorSystem([new Uri.file(fileName)], false)
56 .then((mirrorSystem) { 73 .then((mirrorSystem) {
57 var testLibraryUri = new Uri.file(path.absolute(fileName), 74 var testLibraryUri = new Uri.file(path.absolute(fileName),
58 windows: Platform.isWindows); 75 windows: Platform.isWindows);
59 var library = new Library(mirrorSystem.libraries[testLibraryUri]); 76 var library = new Library(mirrorSystem.libraries[testLibraryUri]);
60 expect(library is Library, isTrue); 77 expect(library is Library, isTrue);
61 78
62 var classTypes = library.classes; 79 var classTypes = library.classes;
63 var classes = []; 80 var classes = [];
64 classes.addAll(classTypes.values); 81 classes.addAll(classTypes.values);
65 classes.addAll(library.errors.values); 82 classes.addAll(library.errors.values);
66 expect(classes.every((e) => e is Class), isTrue); 83 expect(classes.every((e) => e is Class), isTrue);
67 84
68 expect(library.typedefs.values.every((e) => e is Typedef), isTrue); 85 expect(library.typedefs.values.every((e) => e is Typedef), isTrue);
69 86
70 var classMethodTypes = []; 87 var classMethodTypes = [];
71 classes.forEach((e) { 88 classes.forEach((e) {
72 classMethodTypes.add(e.methods); 89 classMethodTypes.add(e.methods);
73 classMethodTypes.add(e.inheritedMethods); 90 classMethodTypes.add(e.inheritedMethods);
74 }); 91 });
75 expect(classMethodTypes.every((e) => e is Map<String, Method>), isTrue ); 92 expect(classMethodTypes.every((e) => e is Map<String, Method>),
93 isTrue);
76 94
77 var classMethods = []; 95 var classMethods = [];
78 classMethodTypes.forEach((e) { 96 classMethodTypes.forEach((e) {
79 classMethods.addAll(e.values); 97 classMethods.addAll(e.values);
80 }); 98 });
81 expect(classMethods.every((e) => e is Method), isTrue); 99 expect(classMethods.every((e) => e is Method), isTrue);
82 100
83 var methodParameters = []; 101 var methodParameters = [];
84 classMethods.forEach((e) { 102 classMethods.forEach((e) {
85 methodParameters.addAll(e.parameters.values); 103 methodParameters.addAll(e.parameters.values);
(...skipping 19 matching lines...) Expand all
105 /// Testing fixReference 123 /// Testing fixReference
106 // Testing Doc comment for class [A]. 124 // Testing Doc comment for class [A].
107 var libraryMirror = mirrorSystem.libraries[testLibraryUri]; 125 var libraryMirror = mirrorSystem.libraries[testLibraryUri];
108 var classMirror = 126 var classMirror =
109 dart2js_util.classesOf(libraryMirror.declarations).first; 127 dart2js_util.classesOf(libraryMirror.declarations).first;
110 var classDocComment = library.fixReference('A').children.first.text; 128 var classDocComment = library.fixReference('A').children.first.text;
111 expect(classDocComment, 'test.A'); 129 expect(classDocComment, 'test.A');
112 130
113 // Test for linking to parameter [A] 131 // Test for linking to parameter [A]
114 var method = getDocgenObject( 132 var method = getDocgenObject(
115 classMirror.declarations[dart2js_util.symbolOf('doThis')]); 133 classMirror.declarations[dart2js_util.symbolOf('m1')]);
116 var methodParameterDocComment = method.fixReference(
117 'A').children.first.text;
118 expect(methodParameterDocComment, 'test.A.doThis.A');
119 134
120 // Testing trying to refer to doThis function 135 // Testing trying to refer to m1 method
121 var methodDocComment = method.fixReference( 136 var methodDocComment = method.fixReference(
122 'doThis').children.first.text; 137 'm1').children.first.text;
123 expect(methodDocComment, 'test.A.doThis'); 138 expect(methodDocComment, 'test.A.m1');
124 139
125 // Testing something with no reference 140 // Testing something with no reference
126 var libraryDocComment = method.fixReference('foobar').text; 141 var libraryDocComment = method.fixReference('foobar').text;
127 expect(libraryDocComment, 'foobar'); 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');
128 }).whenComplete(() => temporaryDir.deleteSync(recursive: true)); 147 }).whenComplete(() => temporaryDir.deleteSync(recursive: true));
129 }); 148 });
130 }); 149 });
131 } 150 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698