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

Side by Side Diff: packages/dart_style/test/formatter_test.dart

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « packages/dart_style/test/command_line_test.dart ('k') | packages/dart_style/test/io_test.dart » ('j') | 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 @TestOn("vm") 5 @TestOn("vm")
6 library dart_style.test.formatter_test; 6 library dart_style.test.formatter_test;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:mirrors'; 9 import 'dart:mirrors';
10 10
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 .path); 142 .path);
143 143
144 var entries = new Directory(p.join(testDir, name)) 144 var entries = new Directory(p.join(testDir, name))
145 .listSync(recursive: true, followLinks: false); 145 .listSync(recursive: true, followLinks: false);
146 for (var entry in entries) { 146 for (var entry in entries) {
147 if (!entry.path.endsWith(".stmt") && !entry.path.endsWith(".unit")) { 147 if (!entry.path.endsWith(".stmt") && !entry.path.endsWith(".unit")) {
148 continue; 148 continue;
149 } 149 }
150 150
151 group("$name ${p.basename(entry.path)}", () { 151 group("$name ${p.basename(entry.path)}", () {
152 var lines = (entry as File).readAsLinesSync(); 152 // Explicitly create a File, in case the entry is a Link.
153 var lines = new File(entry.path).readAsLinesSync();
153 154
154 // The first line may have a "|" to indicate the page width. 155 // The first line may have a "|" to indicate the page width.
155 var pageWidth; 156 var pageWidth;
156 if (lines[0].endsWith("|")) { 157 if (lines[0].endsWith("|")) {
157 pageWidth = lines[0].indexOf("|"); 158 pageWidth = lines[0].indexOf("|");
158 lines = lines.skip(1).toList(); 159 lines = lines.skip(1).toList();
159 } 160 }
160 161
161 var i = 0; 162 var i = 0;
162 while (i < lines.length) { 163 while (i < lines.length) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 new DartFormatter(pageWidth: pageWidth, indent: leadingIndent); 201 new DartFormatter(pageWidth: pageWidth, indent: leadingIndent);
201 202
202 var actual = formatter.formatSource(inputCode); 203 var actual = formatter.formatSource(inputCode);
203 204
204 // The test files always put a newline at the end of the expectation. 205 // The test files always put a newline at the end of the expectation.
205 // Statements from the formatter (correctly) don't have that, so add 206 // Statements from the formatter (correctly) don't have that, so add
206 // one to line up with the expected result. 207 // one to line up with the expected result.
207 var actualText = actual.text; 208 var actualText = actual.text;
208 if (!isCompilationUnit) actualText += "\n"; 209 if (!isCompilationUnit) actualText += "\n";
209 210
210 expect(actualText, equals(expected.text)); 211 // Fail with an explicit message because it's easier to read than
212 // the matcher output.
213 if (actualText != expected.text) {
214 fail("Formatting did not match expectation. Expected:\n"
215 "${expected.text}\nActual:\n$actualText");
216 }
217
211 expect(actual.selectionStart, equals(expected.selectionStart)); 218 expect(actual.selectionStart, equals(expected.selectionStart));
212 expect(actual.selectionLength, equals(expected.selectionLength)); 219 expect(actual.selectionLength, equals(expected.selectionLength));
213 }); 220 });
214 } 221 }
215 }); 222 });
216 } 223 }
217 } 224 }
218 225
219 /// Given a source string that contains ‹ and › to indicate a selection, returns 226 /// Given a source string that contains ‹ and › to indicate a selection, returns
220 /// a [SourceCode] with the text (with the selection markers removed) and the 227 /// a [SourceCode] with the text (with the selection markers removed) and the
221 /// correct selection range. 228 /// correct selection range.
222 SourceCode _extractSelection(String source, {bool isCompilationUnit: false}) { 229 SourceCode _extractSelection(String source, {bool isCompilationUnit: false}) {
223 var start = source.indexOf("‹"); 230 var start = source.indexOf("‹");
224 source = source.replaceAll("‹", ""); 231 source = source.replaceAll("‹", "");
225 232
226 var end = source.indexOf("›"); 233 var end = source.indexOf("›");
227 source = source.replaceAll("›", ""); 234 source = source.replaceAll("›", "");
228 235
229 return new SourceCode(source, 236 return new SourceCode(source,
230 isCompilationUnit: isCompilationUnit, 237 isCompilationUnit: isCompilationUnit,
231 selectionStart: start == -1 ? null : start, 238 selectionStart: start == -1 ? null : start,
232 selectionLength: end == -1 ? null : end - start); 239 selectionLength: end == -1 ? null : end - start);
233 } 240 }
OLDNEW
« no previous file with comments | « packages/dart_style/test/command_line_test.dart ('k') | packages/dart_style/test/io_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698