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

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

Issue 104993003: Formatter improvements (comments and empty bodies). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | Annotate | Revision Log
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/src/generated/java_core.dart' show CharSequence; 7 import 'package:analyzer/src/generated/java_core.dart' show CharSequence;
8 import 'package:analyzer/src/generated/scanner.dart'; 8 import 'package:analyzer/src/generated/scanner.dart';
9 import 'package:analyzer/src/services/formatter_impl.dart'; 9 import 'package:analyzer/src/services/formatter_impl.dart';
10 import 'package:analyzer/src/services/writer.dart'; 10 import 'package:analyzer/src/services/writer.dart';
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 'class A {\n' 529 'class A {\n'
530 '}\n' 530 '}\n'
531 '\n' 531 '\n'
532 '/// ... and\n' 532 '/// ... and\n'
533 '\n' 533 '\n'
534 '/// Dangling ones too\n' 534 '/// Dangling ones too\n'
535 'int x;\n' 535 'int x;\n'
536 ); 536 );
537 }); 537 });
538 538
539 test('CU - comments (8)', () {
540 expectCUFormatsTo(
541 'var x /* X */, y;\n',
542 'var x /* X */, y;\n'
543 );
544 });
545
546 test('CU - comments (9)', () {
547 expectCUFormatsTo(
548 'main() {\n'
549 ' foo(1 /* bang */, 2);\n'
550 '}\n'
551 'foo(x, y) => null;\n',
552 'main() {\n'
553 ' foo(1 /* bang */, 2);\n'
554 '}\n'
555 'foo(x, y) => null;\n'
556 );
557 });
558
559 test('CU - comments (10)', () {
Brian Wilkerson 2013/12/04 19:52:50 If there isn't already, it might be good to add a
pquitslund 2013/12/04 21:09:10 Good call. I've got one of those in my list tests
560 expectCUFormatsTo(
561 'var l = [1 /* bang */, 2];\n',
562 'var l = [1 /* bang */, 2];\n'
563 );
564 });
565
566 test('CU - comments (11)', () {
567 expectCUFormatsTo(
568 'var m = {1: 2 /* bang */, 3: 4};\n',
569 'var m = {1: 2 /* bang */, 3: 4};\n'
570 );
571 });
572
539 test('CU - EOF nl', () { 573 test('CU - EOF nl', () {
540 expectCUFormatsTo( 574 expectCUFormatsTo(
541 'var x = 1;', 575 'var x = 1;',
542 'var x = 1;\n' 576 'var x = 1;\n'
543 ); 577 );
544 }); 578 });
545 579
546 test('CU - constructor', () { 580 test('CU - constructor', () {
547 expectCUFormatsTo( 581 expectCUFormatsTo(
548 'class A {\n' 582 'class A {\n'
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 ' case "apple":\n' 738 ' case "apple":\n'
705 ' print("delish");\n' 739 ' print("delish");\n'
706 ' break;\n' 740 ' break;\n'
707 ' case "fig":\n' 741 ' case "fig":\n'
708 ' print("bleh");\n' 742 ' print("bleh");\n'
709 ' break;\n' 743 ' break;\n'
710 '}' 744 '}'
711 ); 745 );
712 }); 746 });
713 747
748 test('stmt (empty while body)', () {
749 expectStmtFormatsTo(
750 'while (true);',
751 'while (true);'
752 );
753 });
754
755 test('stmt (empty for body)', () {
756 expectStmtFormatsTo(
757 'for ( ; ; );',
758 'for ( ; ; );'
759 );
760 });
761
714 test('stmt (cascades)', () { 762 test('stmt (cascades)', () {
715 expectStmtFormatsTo( 763 expectStmtFormatsTo(
716 '"foo"\n' 764 '"foo"\n'
717 '..toString()\n' 765 '..toString()\n'
718 '..toString();', 766 '..toString();',
719 '"foo"\n' 767 '"foo"\n'
720 ' ..toString()\n' 768 ' ..toString()\n'
721 ' ..toString();' 769 ' ..toString();'
722 ); 770 );
723 }); 771 });
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), 1115 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(),
1068 throwsA(new isInstanceOf<FormatterException>())); 1116 throwsA(new isInstanceOf<FormatterException>()));
1069 1117
1070 expectCUFormatsTo(src, expected, {transforms: true}) => 1118 expectCUFormatsTo(src, expected, {transforms: true}) =>
1071 expect(formatCU(src, options: new FormatterOptions( 1119 expect(formatCU(src, options: new FormatterOptions(
1072 codeTransforms: transforms)).source, equals(expected)); 1120 codeTransforms: transforms)).source, equals(expected));
1073 1121
1074 expectStmtFormatsTo(src, expected, {transforms: true}) => 1122 expectStmtFormatsTo(src, expected, {transforms: true}) =>
1075 expect(formatStatement(src, options: 1123 expect(formatStatement(src, options:
1076 new FormatterOptions(codeTransforms: transforms)), equals(expected)); 1124 new FormatterOptions(codeTransforms: transforms)), equals(expected));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698