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

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

Issue 113693003: dartfmt gets opinionated about 'gratuitous' linebreaks. (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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 test('CU - comments (10)', () { 559 test('CU - comments (10)', () {
560 expectCUFormatsTo( 560 expectCUFormatsTo(
561 'var l = [1 /* bang */, 2];\n', 561 'var l = [1 /* bang */, 2];\n',
562 'var l = [1 /* bang */, 2];\n' 562 'var l = [1 /* bang */, 2];\n'
563 ); 563 );
564 }); 564 });
565 565
566 test('CU - comments (11)', () { 566 test('CU - comments (11)', () {
567 expectCUFormatsTo( 567 expectCUFormatsTo(
568 'var m = {1: 2 /* bang */, 3: 4};\n', 568 'var m = {1: 2 /* bang */, 3: 4};\n',
569 'var m = {1: 2 /* bang */, 3: 4};\n' 569 'var m = {\n'
570 ' 1: 2 /* bang */,\n'
571 ' 3: 4\n'
572 '};\n'
570 ); 573 );
571 }); 574 });
572 575
573 test('CU - EOF nl', () { 576 test('CU - EOF nl', () {
574 expectCUFormatsTo( 577 expectCUFormatsTo(
575 'var x = 1;', 578 'var x = 1;',
576 'var x = 1;\n' 579 'var x = 1;\n'
577 ); 580 );
578 }); 581 });
579 582
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 test('stmt (lists)', () { 783 test('stmt (lists)', () {
781 expectStmtFormatsTo( 784 expectStmtFormatsTo(
782 'var l = [1,2,3,4];', 785 'var l = [1,2,3,4];',
783 'var l = [1, 2, 3, 4];' 786 'var l = [1, 2, 3, 4];'
784 ); 787 );
785 expectStmtFormatsTo( 788 expectStmtFormatsTo(
786 'var l = [\n' 789 'var l = [\n'
787 '1,\n' 790 '1,\n'
788 '2,\n' 791 '2,\n'
789 '];', 792 '];',
790 'var l = [\n' 793 'var l = [1, 2,];'
791 ' 1,\n'
792 ' 2,\n'
793 '];'
794 ); 794 );
795 //Dangling ',' 795 //Dangling ','
796 expectStmtFormatsTo( 796 expectStmtFormatsTo(
797 'var l = [1,];', 797 'var l = [1,];',
798 'var l = [1,];' 798 'var l = [1,];'
799 ); 799 );
800 }); 800 });
801 801
802 test('stmt (maps)', () { 802 test('stmt (maps)', () {
803 expectStmtFormatsTo( 803 expectStmtFormatsTo(
804 'var map = const {"foo": "bar", "fuz": null};', 804 'var map = const {"foo": "bar", "fuz": null};',
805 'var map = const {"foo": "bar", "fuz": null};' 805 'var map = const {\n'
806 ' "foo": "bar",\n'
807 ' "fuz": null\n'
808 '};'
806 ); 809 );
807 810
808 expectStmtFormatsTo( 811 expectStmtFormatsTo(
809 'var map = {\n' 812 'var map = {\n'
810 '"foo": "bar",\n' 813 '"foo": "bar",\n'
811 '"bar": "baz"' 814 '"bar": "baz"\n'
812 '};', 815 '};',
813 'var map = {\n' 816 'var map = {\n'
814 ' "foo": "bar",\n' 817 ' "foo": "bar",\n'
815 ' "bar": "baz"' 818 ' "bar": "baz"\n'
816 '};' 819 '};'
817 ); 820 );
818 821
819 //Dangling ',' 822 //Dangling ','
820 expectStmtFormatsTo( 823 expectStmtFormatsTo(
821 'var map = {"foo": "bar",};', 824 'var map = {"foo": "bar",};',
822 'var map = {"foo": "bar",};' 825 'var map = {\n'
826 ' "foo": "bar",\n'
827 '};'
823 ); 828 );
824 }); 829 });
825 830
826 test('stmt (try/catch)', () { 831 test('stmt (try/catch)', () {
827 expectStmtFormatsTo( 832 expectStmtFormatsTo(
828 'try {\n' 833 'try {\n'
829 'doSomething();\n' 834 'doSomething();\n'
830 '} catch (e) {\n' 835 '} catch (e) {\n'
831 'print(e);\n' 836 'print(e);\n'
832 '}', 837 '}',
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 'if (true) {\n' 912 'if (true) {\n'
908 ' print("true!");\n' 913 ' print("true!");\n'
909 '} else {\n' 914 '} else {\n'
910 ' print("false!");\n' 915 ' print("false!");\n'
911 '}'); 916 '}');
912 expectStmtFormatsTo('if (true) print("true!"); else print("false!");', 917 expectStmtFormatsTo('if (true) print("true!"); else print("false!");',
913 'if (true) print("true!"); else print("false!");', 918 'if (true) print("true!"); else print("false!");',
914 transforms: false); 919 transforms: false);
915 }); 920 });
916 921
922 // smoketest to ensure we're enforcing the 'no gratuitous linebreaks'
923 // opinion
924 test('CU (eat newlines)', () {
925 expectCUFormatsTo(
926 'abstract\n'
927 'class\n'
928 'A{}',
929 'abstract class A {\n'
930 '}\n'
931 );
932 });
933
917 // test('line continuations - 1', () { 934 // test('line continuations - 1', () {
918 // expectStmtFormatsTo( 935 // expectStmtFormatsTo(
919 // 'if (x &&\n' 936 // 'if (x &&\n'
920 // ' y) {\n' 937 // ' y) {\n'
921 // ' print("yes!");\n' 938 // ' print("yes!");\n'
922 // '}', 939 // '}',
923 // 'if (x &&\n' 940 // 'if (x &&\n'
924 // ' y) {\n' 941 // ' y) {\n'
925 // ' print("yes!");\n' 942 // ' print("yes!");\n'
926 // '}' 943 // '}'
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), 1282 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(),
1266 throwsA(new isInstanceOf<FormatterException>())); 1283 throwsA(new isInstanceOf<FormatterException>()));
1267 1284
1268 expectCUFormatsTo(src, expected, {transforms: true}) => 1285 expectCUFormatsTo(src, expected, {transforms: true}) =>
1269 expect(formatCU(src, options: new FormatterOptions( 1286 expect(formatCU(src, options: new FormatterOptions(
1270 codeTransforms: transforms)).source, equals(expected)); 1287 codeTransforms: transforms)).source, equals(expected));
1271 1288
1272 expectStmtFormatsTo(src, expected, {transforms: true}) => 1289 expectStmtFormatsTo(src, expected, {transforms: true}) =>
1273 expect(formatStatement(src, options: 1290 expect(formatStatement(src, options:
1274 new FormatterOptions(codeTransforms: transforms)), equals(expected)); 1291 new FormatterOptions(codeTransforms: transforms)), equals(expected));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698