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

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

Issue 23458038: Ensure formatted CUs end with a newline (dartbug.com/13188). (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/writer.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 28 matching lines...) Expand all
39 'class A {\n' 39 'class A {\n'
40 '}\n' 40 '}\n'
41 ); 41 );
42 }); 42 });
43 43
44 test('CU (3)', () { 44 test('CU (3)', () {
45 expectCUFormatsTo( 45 expectCUFormatsTo(
46 'class A {\n' 46 'class A {\n'
47 ' }', 47 ' }',
48 'class A {\n' 48 'class A {\n'
49 '}' 49 '}\n'
50 ); 50 );
51 }); 51 });
52 52
53 test('CU (4)', () { 53 test('CU (4)', () {
54 expectCUFormatsTo( 54 expectCUFormatsTo(
55 ' class A {\n' 55 ' class A {\n'
56 '}\n', 56 '}\n',
57 'class A {\n' 57 'class A {\n'
58 '}\n' 58 '}\n'
59 ); 59 );
60 }); 60 });
61 61
62 test('CU (5)', () { 62 test('CU (5)', () {
63 expectCUFormatsTo( 63 expectCUFormatsTo(
64 'class A { int meaningOfLife() => 42; }', 64 'class A { int meaningOfLife() => 42; }',
65 'class A {\n' 65 'class A {\n'
66 ' int meaningOfLife() => 42;\n' 66 ' int meaningOfLife() => 42;\n'
67 '}' 67 '}\n'
68 ); 68 );
69 }); 69 });
70 70
71 test('CU - EOL comments', () { 71 test('CU - EOL comments', () {
72 expectCUFormatsTo( 72 expectCUFormatsTo(
73 '//comment one\n\n' 73 '//comment one\n\n'
74 '//comment two\n\n', 74 '//comment two\n\n',
75 '//comment one\n\n' 75 '//comment one\n\n'
76 '//comment two\n\n' 76 '//comment two\n\n'
77 ); 77 );
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 '}\n', 155 '}\n',
156 'import "dart:io";\n\n' 156 'import "dart:io";\n\n'
157 'import "package:unittest/unittest.dart";\n' 157 'import "package:unittest/unittest.dart";\n'
158 'foo() {\n' 158 'foo() {\n'
159 '}\n' 159 '}\n'
160 ); 160 );
161 expectCUFormatsTo( 161 expectCUFormatsTo(
162 'library a; class B { }', 162 'library a; class B { }',
163 'library a;\n' 163 'library a;\n'
164 'class B {\n' 164 'class B {\n'
165 '}' 165 '}\n'
166 ); 166 );
167 }); 167 });
168 168
169 test('CU - method invocations', () { 169 test('CU - method invocations', () {
170 expectCUFormatsTo( 170 expectCUFormatsTo(
171 'class A {\n' 171 'class A {\n'
172 ' foo() {\n' 172 ' foo() {\n'
173 ' bar();\n' 173 ' bar();\n'
174 ' for (int i = 0; i < 42; i++) {\n' 174 ' for (int i = 0; i < 42; i++) {\n'
175 ' baz();\n' 175 ' baz();\n'
(...skipping 13 matching lines...) Expand all
189 189
190 test('CU w/class decl comment', () { 190 test('CU w/class decl comment', () {
191 expectCUFormatsTo( 191 expectCUFormatsTo(
192 'import "foo";\n\n' 192 'import "foo";\n\n'
193 '//Killer class\n' 193 '//Killer class\n'
194 'class A {\n' 194 'class A {\n'
195 '}', 195 '}',
196 'import "foo";\n\n' 196 'import "foo";\n\n'
197 '//Killer class\n' 197 '//Killer class\n'
198 'class A {\n' 198 'class A {\n'
199 '}' 199 '}\n'
200 ); 200 );
201 }); 201 });
202 202
203 test('CU (method body)', () { 203 test('CU (method body)', () {
204 expectCUFormatsTo( 204 expectCUFormatsTo(
205 'class A {\n' 205 'class A {\n'
206 ' foo(path) {\n' 206 ' foo(path) {\n'
207 ' var buffer = new StringBuffer();\n' 207 ' var buffer = new StringBuffer();\n'
208 ' var file = new File(path);\n' 208 ' var file = new File(path);\n'
209 ' return file;\n' 209 ' return file;\n'
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 '// Comment 2\n' 421 '// Comment 2\n'
422 '\n' 422 '\n'
423 '/* Comment 3 */', 423 '/* Comment 3 */',
424 'library foo;\n' 424 'library foo;\n'
425 '\n' 425 '\n'
426 '\n' 426 '\n'
427 '/* Comment 1 */\n' 427 '/* Comment 1 */\n'
428 '\n' 428 '\n'
429 '// Comment 2\n' 429 '// Comment 2\n'
430 '\n' 430 '\n'
431 '/* Comment 3 */' 431 '/* Comment 3 */\n'
432 ); 432 );
433 }); 433 });
434 434
435 test('CU - comments (EOF)', () { 435 test('CU - comments (EOF)', () {
436 expectCUFormatsTo( 436 expectCUFormatsTo(
437 'library foo; //zamm', 437 'library foo; //zamm',
438 'library foo; //zamm\n' //<-- note extra NEWLINE 438 'library foo; //zamm\n' //<-- note extra NEWLINE
439 ); 439 );
440 }); 440 });
441 441
(...skipping 30 matching lines...) Expand all
472 'var x; //x\n', 472 'var x; //x\n',
473 'var x; //x\n' 473 'var x; //x\n'
474 ); 474 );
475 }); 475 });
476 476
477 test('CU - comments (4)', () { 477 test('CU - comments (4)', () {
478 expectCUFormatsTo( 478 expectCUFormatsTo(
479 'class X { //X!\n' 479 'class X { //X!\n'
480 '}', 480 '}',
481 'class X { //X!\n' 481 'class X { //X!\n'
482 '}' 482 '}\n'
483 ); 483 );
484 }); 484 });
485 485
486 test('CU - comments (5)', () { 486 test('CU - comments (5)', () {
487 expectCUFormatsTo( 487 expectCUFormatsTo(
488 '//comment one\n\n' 488 '//comment one\n\n'
489 '//comment two\n\n', 489 '//comment two\n\n',
490 '//comment one\n\n' 490 '//comment one\n\n'
491 '//comment two\n\n' 491 '//comment two\n\n'
492 ); 492 );
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 'class A {\n' 528 'class A {\n'
529 '}\n' 529 '}\n'
530 '\n' 530 '\n'
531 '/// ... and\n' 531 '/// ... and\n'
532 '\n' 532 '\n'
533 '/// Dangling ones too\n' 533 '/// Dangling ones too\n'
534 'int x;\n' 534 'int x;\n'
535 ); 535 );
536 }); 536 });
537 537
538 538 test('CU - EOF nl', () {
539 expectCUFormatsTo(
540 'var x = 1;',
541 'var x = 1;\n'
542 );
543 });
544
539 test('CU - constructor', () { 545 test('CU - constructor', () {
540 expectCUFormatsTo( 546 expectCUFormatsTo(
541 'class A {\n' 547 'class A {\n'
542 ' const _a;\n' 548 ' const _a;\n'
543 ' A();\n' 549 ' A();\n'
544 ' int a() => _a;\n' 550 ' int a() => _a;\n'
545 '}\n', 551 '}\n',
546 'class A {\n' 552 'class A {\n'
547 ' const _a;\n' 553 ' const _a;\n'
548 ' A();\n' 554 ' A();\n'
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 new TokenStreamComparator(null, t1, t2).verifyEquals(); 974 new TokenStreamComparator(null, t1, t2).verifyEquals();
969 975
970 expectStreamsNotEqual(Token t1, Token t2) => 976 expectStreamsNotEqual(Token t1, Token t2) =>
971 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), 977 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(),
972 throwsA(new isInstanceOf<FormatterException>())); 978 throwsA(new isInstanceOf<FormatterException>()));
973 979
974 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); 980 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected));
975 981
976 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), 982 expectStmtFormatsTo(src, expected) => expect(formatStatement(src),
977 equals(expected)); 983 equals(expected));
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/services/writer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698