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

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

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « packages/dart_style/test/comments/top_level.unit ('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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 test("does not add newline to statement", () { 74 test("does not add newline to statement", () {
75 expect(new DartFormatter().formatStatement("var x = 1;"), 75 expect(new DartFormatter().formatStatement("var x = 1;"),
76 equals("var x = 1;")); 76 equals("var x = 1;"));
77 }); 77 });
78 78
79 test("fails if anything is after the statement", () { 79 test("fails if anything is after the statement", () {
80 try { 80 try {
81 new DartFormatter().formatStatement("var x = 1;;"); 81 new DartFormatter().formatStatement("var x = 1;;");
82 82
83 fail("Should throw."); 83 fail("Should throw.");
84 } catch (err) { 84 } on FormatterException catch (ex) {
85 expect(err, new isInstanceOf<FormatterException>()); 85 expect(ex.errors.length, equals(1));
86 var message = err.message(); 86 expect(ex.errors.first.offset, equals(10));
87 expect(message, contains("Unexpected token"));
88 expect(message, contains("column 11"));
89 } 87 }
90 }); 88 });
91 89
92 test('preserves initial indent', () { 90 test('preserves initial indent', () {
93 var formatter = new DartFormatter(indent: 3); 91 var formatter = new DartFormatter(indent: 3);
94 expect( 92 expect(
95 formatter.formatStatement('if (foo) {bar;}'), 93 formatter.formatStatement('if (foo) {bar;}'),
96 equals(' if (foo) {\n' 94 equals(' if (foo) {\n'
97 ' bar;\n' 95 ' bar;\n'
98 ' }')); 96 ' }'));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 130
133 /// Run tests defined in "*.unit" and "*.stmt" files inside directory [name]. 131 /// Run tests defined in "*.unit" and "*.stmt" files inside directory [name].
134 void testDirectory(String name) { 132 void testDirectory(String name) {
135 var indentPattern = new RegExp(r"^\(indent (\d+)\)\s*"); 133 var indentPattern = new RegExp(r"^\(indent (\d+)\)\s*");
136 134
137 // Locate the "test" directory. Use mirrors so that this works with the test 135 // Locate the "test" directory. Use mirrors so that this works with the test
138 // package, which loads this suite into an isolate. 136 // package, which loads this suite into an isolate.
139 var testDir = p.dirname(currentMirrorSystem() 137 var testDir = p.dirname(currentMirrorSystem()
140 .findLibrary(#dart_style.test.formatter_test) 138 .findLibrary(#dart_style.test.formatter_test)
141 .uri 139 .uri
142 .path); 140 .toFilePath());
143 141
144 var entries = new Directory(p.join(testDir, name)) 142 var entries = new Directory(p.join(testDir, name))
145 .listSync(recursive: true, followLinks: false); 143 .listSync(recursive: true, followLinks: false);
146 for (var entry in entries) { 144 for (var entry in entries) {
147 if (!entry.path.endsWith(".stmt") && !entry.path.endsWith(".unit")) { 145 if (!entry.path.endsWith(".stmt") && !entry.path.endsWith(".unit")) {
148 continue; 146 continue;
149 } 147 }
150 148
151 group("$name ${p.basename(entry.path)}", () { 149 group("$name ${p.basename(entry.path)}", () {
152 // Explicitly create a File, in case the entry is a Link. 150 // Explicitly create a File, in case the entry is a Link.
(...skipping 28 matching lines...) Expand all
181 var input = ""; 179 var input = "";
182 while (!lines[i].startsWith("<<<")) { 180 while (!lines[i].startsWith("<<<")) {
183 input += lines[i++] + "\n"; 181 input += lines[i++] + "\n";
184 } 182 }
185 183
186 var expectedOutput = ""; 184 var expectedOutput = "";
187 while (++i < lines.length && !lines[i].startsWith(">>>")) { 185 while (++i < lines.length && !lines[i].startsWith(">>>")) {
188 expectedOutput += lines[i] + "\n"; 186 expectedOutput += lines[i] + "\n";
189 } 187 }
190 188
189 // TODO(rnystrom): Stop skipping these tests when possible.
190 if (description.contains("(skip:")) {
191 print("skipping $description");
192 continue;
193 }
194
191 test(description, () { 195 test(description, () {
192 var isCompilationUnit = p.extension(entry.path) == ".unit"; 196 var isCompilationUnit = p.extension(entry.path) == ".unit";
193 197
194 var inputCode = 198 var inputCode =
195 _extractSelection(input, isCompilationUnit: isCompilationUnit); 199 _extractSelection(input, isCompilationUnit: isCompilationUnit);
196 200
197 var expected = _extractSelection(expectedOutput, 201 var expected = _extractSelection(expectedOutput,
198 isCompilationUnit: isCompilationUnit); 202 isCompilationUnit: isCompilationUnit);
199 203
200 var formatter = 204 var formatter =
(...skipping 30 matching lines...) Expand all
231 source = source.replaceAll("‹", ""); 235 source = source.replaceAll("‹", "");
232 236
233 var end = source.indexOf("›"); 237 var end = source.indexOf("›");
234 source = source.replaceAll("›", ""); 238 source = source.replaceAll("›", "");
235 239
236 return new SourceCode(source, 240 return new SourceCode(source,
237 isCompilationUnit: isCompilationUnit, 241 isCompilationUnit: isCompilationUnit,
238 selectionStart: start == -1 ? null : start, 242 selectionStart: start == -1 ? null : start,
239 selectionLength: end == -1 ? null : end - start); 243 selectionLength: end == -1 ? null : end - start);
240 } 244 }
OLDNEW
« no previous file with comments | « packages/dart_style/test/comments/top_level.unit ('k') | packages/dart_style/test/io_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698