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

Side by Side Diff: tests/compiler/dart2js_extra/mirror_printer_test.dart

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: revert another multipart test Created 4 years, 3 months 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /// Prints all information about all mirrors. This tests that it is possible to 5 /// Prints all information about all mirrors. This tests that it is possible to
6 /// enumerate all reflective information without crashing. 6 /// enumerate all reflective information without crashing.
7 7
8 // Note: Adding imports below is fine for regression tests. For example, 8 // Note: Adding imports below is fine for regression tests. For example,
9 // 'crash_library_metadata.dart' is imported to ensure the compiler doesn't 9 // 'crash_library_metadata.dart' is imported to ensure the compiler doesn't
10 // crash. 10 // crash.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 get indent { 45 get indent {
46 for (int i = 0; i < indentationLevel; i++) { 46 for (int i = 0; i < indentationLevel; i++) {
47 w(' '); 47 w(' ');
48 } 48 }
49 } 49 }
50 50
51 String stringifyInstance(InstanceMirror mirror) { 51 String stringifyInstance(InstanceMirror mirror) {
52 var reflectee = mirror.reflectee; 52 var reflectee = mirror.reflectee;
53 if (reflectee is String) return '"${reflectee}"'; 53 if (reflectee is String) return '"${reflectee}"';
54 if (reflectee is Null || reflectee is bool || reflectee is num || 54 if (reflectee is Null ||
55 reflectee is List || reflectee is Map) { 55 reflectee is bool ||
56 reflectee is num ||
57 reflectee is List ||
58 reflectee is Map) {
56 return '$reflectee'; 59 return '$reflectee';
57 } 60 }
58 StringBuffer buffer = new StringBuffer(); 61 StringBuffer buffer = new StringBuffer();
59 Map<Symbol, DeclarationMirror> declarations = mirror.type.declarations; 62 Map<Symbol, DeclarationMirror> declarations = mirror.type.declarations;
60 buffer 63 buffer..write(n(mirror.type.simpleName))..write('(');
61 ..write(n(mirror.type.simpleName))
62 ..write('(');
63 bool first = true; 64 bool first = true;
64 declarations.forEach((Symbol name, DeclarationMirror declaration) { 65 declarations.forEach((Symbol name, DeclarationMirror declaration) {
65 if (declaration is! VariableMirror) return; 66 if (declaration is! VariableMirror) return;
66 VariableMirror variable = declaration; 67 VariableMirror variable = declaration;
67 if (variable.isStatic) return; 68 if (variable.isStatic) return;
68 // TODO(ahe): Include superclasses. 69 // TODO(ahe): Include superclasses.
69 if (first) { 70 if (first) {
70 first = false; 71 first = false;
71 } else { 72 } else {
72 buffer.write(', '); 73 buffer.write(', ');
73 } 74 }
74 buffer 75 buffer
75 ..write(n(name)) 76 ..write(n(name))
76 ..write(': ') 77 ..write(': ')
77 ..write(stringifyInstance(mirror.getField(name))); 78 ..write(stringifyInstance(mirror.getField(name)));
78 }); 79 });
79 buffer.write(')'); 80 buffer.write(')');
80 return buffer.toString(); 81 return buffer.toString();
81 } 82 }
82 83
83 String stringifyMetadata(InstanceMirror mirror) { 84 String stringifyMetadata(InstanceMirror mirror) {
84 return '@${stringifyInstance(mirror)}'; 85 return '@${stringifyInstance(mirror)}';
85 } 86 }
86 87
87 bool writeType(TypeMirror mirror) { 88 bool writeType(TypeMirror mirror) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 writeMethod(declaration); 162 writeMethod(declaration);
162 } else { 163 } else {
163 // TODO(ahe): Test other subclasses of DeclarationMirror. 164 // TODO(ahe): Test other subclasses of DeclarationMirror.
164 w('$declaration'); 165 w('$declaration');
165 } 166 }
166 } 167 }
167 168
168 writeLibrary(LibraryMirror library) { 169 writeLibrary(LibraryMirror library) {
169 w('library ${n(library.simpleName)};\n\n'); 170 w('library ${n(library.simpleName)};\n\n');
170 library.declarations.values 171 library.declarations.values
171 .where((d)=> d is! TypeMirror) 172 .where((d) => d is! TypeMirror)
172 .forEach(writeDeclaration); 173 .forEach(writeDeclaration);
173 w('\n'); 174 w('\n');
174 } 175 }
175 176
176 static StringBuffer stringify(Map<Uri, LibraryMirror> libraries) { 177 static StringBuffer stringify(Map<Uri, LibraryMirror> libraries) {
177 StringBuffer buffer = new StringBuffer(); 178 StringBuffer buffer = new StringBuffer();
178 libraries.values.forEach(new MirrorPrinter(buffer).writeLibrary); 179 libraries.values.forEach(new MirrorPrinter(buffer).writeLibrary);
179 return buffer; 180 return buffer;
180 } 181 }
181 } 182 }
182 183
183 main() { 184 main() {
184 print(MirrorPrinter.stringify(currentMirrorSystem().libraries)); 185 print(MirrorPrinter.stringify(currentMirrorSystem().libraries));
185 // Clear the nodes to avoid confusing the fine test framework (by "fine" I 186 // Clear the nodes to avoid confusing the fine test framework (by "fine" I
186 // mean something else) -- ahe. 187 // mean something else) -- ahe.
187 document.body.nodes.clear(); 188 document.body.nodes.clear();
188 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698