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

Side by Side Diff: pkg/analyzer_experimental/test/services/formatter_test.dart

Issue 23301021: Formatter checkpoint (String literal elimination). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer_experimental/lib/src/services/formatter_impl.dart ('k') | 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) 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 import 'package:unittest/unittest.dart'; 5 import 'package:unittest/unittest.dart';
6 6
7 import 'package:analyzer_experimental/src/generated/scanner.dart'; 7 import 'package:analyzer_experimental/src/generated/scanner.dart';
8 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; 8 import 'package:analyzer_experimental/src/services/formatter_impl.dart';
9 import 'package:analyzer_experimental/src/services/writer.dart'; 9 import 'package:analyzer_experimental/src/services/writer.dart';
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 'import "dart:io";\n\n' 110 'import "dart:io";\n\n'
111 'import "package:unittest/unittest.dart";\n' 111 'import "package:unittest/unittest.dart";\n'
112 'foo() {\n' 112 'foo() {\n'
113 '}\n', 113 '}\n',
114 'import "dart:io";\n\n' 114 'import "dart:io";\n\n'
115 'import "package:unittest/unittest.dart";\n' 115 'import "package:unittest/unittest.dart";\n'
116 'foo() {\n' 116 'foo() {\n'
117 '}\n' 117 '}\n'
118 ); 118 );
119 }); 119 });
120
121 test('CU - method invocations', () {
122 expectCUFormatsTo(
123 'class A {\n'
124 ' foo() {\n'
125 ' bar();\n'
126 ' for (int i = 0; i < 42; i++) {\n'
127 ' baz();\n'
128 ' }\n'
129 ' }\n'
130 '}\n',
131 'class A {\n'
132 ' foo() {\n'
133 ' bar();\n'
134 ' for (int i = 0; i < 42; i++) {\n'
135 ' baz();\n'
136 ' }\n'
137 ' }\n'
138 '}\n'
139 );
140 });
120 141
121 test('CU w/class decl comment', () { 142 test('CU w/class decl comment', () {
122 expectCUFormatsTo( 143 expectCUFormatsTo(
123 'import "foo";\n\n' 144 'import "foo";\n\n'
124 '//Killer class\n' 145 '//Killer class\n'
125 'class A {\n' 146 'class A {\n'
126 '}', 147 '}',
127 'import "foo";\n\n' 148 'import "foo";\n\n'
128 '//Killer class\n' 149 '//Killer class\n'
129 'class A {\n' 150 'class A {\n'
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 ' int c() => b();\n\n' 269 ' int c() => b();\n\n'
249 '}\n', 270 '}\n',
250 'class A {\n' 271 'class A {\n'
251 '}\n\n' 272 '}\n\n'
252 'class B {\n\n\n' 273 'class B {\n\n\n'
253 ' int b() => 42;\n\n' 274 ' int b() => 42;\n\n'
254 ' int c() => b();\n\n' 275 ' int c() => b();\n\n'
255 '}\n' 276 '}\n'
256 ); 277 );
257 }); 278 });
279
280 test('CU - constructor', () {
281 expectCUFormatsTo(
282 'class A {\n'
283 ' const _a;\n'
284 ' A();\n'
285 ' int a() => _a;\n'
286 '}\n',
287 'class A {\n'
288 ' const _a;\n'
289 ' A();\n'
290 ' int a() => _a;\n'
291 '}\n'
292 );
293 });
258 294
295 test('CU - method decl w/ named params', () {
296 expectCUFormatsTo(
297 'class A {\n'
298 ' int a(var x, {optional: null}) => null;\n'
299 '}\n',
300 'class A {\n'
301 ' int a(var x, {optional: null}) => null;\n'
302 '}\n'
303 );
304 });
305
306 test('CU - method decl w/ optional params', () {
307 expectCUFormatsTo(
308 'class A {\n'
309 ' int a(var x, [optional = null]) => null;\n'
310 '}\n',
311 'class A {\n'
312 ' int a(var x, [optional = null]) => null;\n'
313 '}\n'
314 );
315 });
316
317 test('CU - factory constructor redirects', () {
318 expectCUFormatsTo(
319 'class A {\n'
320 ' const factory A() = B;\n'
321 '}\n',
322 'class A {\n'
323 ' const factory A() = B;\n'
324 '}\n'
325 );
326 });
327
328 test('CU - constructor initializers', () {
329 expectCUFormatsTo(
330 'class A {\n'
331 ' int _a;\n'
332 ' A(a) : _a = a;\n'
333 '}\n',
334 'class A {\n'
335 ' int _a;\n'
336 ' A(a) : _a = a;\n'
337 '}\n'
338 );
339 });
340
259 test('stmt', () { 341 test('stmt', () {
260 expectStmtFormatsTo( 342 expectStmtFormatsTo(
261 'if (true){\n' 343 'if (true){\n'
262 'if (true){\n' 344 'if (true){\n'
263 'if (true){\n' 345 'if (true){\n'
264 'return true;\n' 346 'return true;\n'
265 '} else{\n' 347 '} else{\n'
266 'return false;\n' 348 'return false;\n'
267 '}\n' 349 '}\n'
268 '}\n' 350 '}\n'
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 String formatCU(src, {options: const FormatterOptions()}) => 562 String formatCU(src, {options: const FormatterOptions()}) =>
481 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); 563 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src);
482 564
483 String formatStatement(src, {options: const FormatterOptions()}) => 565 String formatStatement(src, {options: const FormatterOptions()}) =>
484 new CodeFormatter(options).format(CodeKind.STATEMENT, src); 566 new CodeFormatter(options).format(CodeKind.STATEMENT, src);
485 567
486 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); 568 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected));
487 569
488 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), 570 expectStmtFormatsTo(src, expected) => expect(formatStatement(src),
489 equals(expected)); 571 equals(expected));
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/services/formatter_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698