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

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

Issue 109423004: Formatter line continuation awareness hooks. (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
« no previous file with comments | « pkg/analyzer/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/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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 'if (true) {\n' 907 'if (true) {\n'
908 ' print("true!");\n' 908 ' print("true!");\n'
909 '} else {\n' 909 '} else {\n'
910 ' print("false!");\n' 910 ' print("false!");\n'
911 '}'); 911 '}');
912 expectStmtFormatsTo('if (true) print("true!"); else print("false!");', 912 expectStmtFormatsTo('if (true) print("true!"); else print("false!");',
913 'if (true) print("true!"); else print("false!");', 913 'if (true) print("true!"); else print("false!");',
914 transforms: false); 914 transforms: false);
915 }); 915 });
916 916
917 // test('line continuations - 1', () {
918 // expectStmtFormatsTo(
919 // 'if (x &&\n'
920 // ' y) {\n'
921 // ' print("yes!");\n'
922 // '}',
923 // 'if (x &&\n'
924 // ' y) {\n'
925 // ' print("yes!");\n'
926 // '}'
927 // );
928 // expectStmtFormatsTo(
929 // 'var x =\n'
930 // ' 1234567890;',
931 // 'var x =\n'
932 // ' 1234567890;'
933 // );
934 // expectStmtFormatsTo(
935 // 'foo() {\n'
936 // ' var x = 0;\n'
937 // ' x =\n'
938 // ' 1234567890;\n'
939 // '}',
940 // 'foo() {\n'
941 // ' var x = 0;\n'
942 // ' x =\n'
943 // ' 1234567890;\n'
944 // '}'
945 // );
946 // expectStmtFormatsTo(
947 // 'foo() {\n'
948 // ' while (true &&\n'
949 // ' true) {\n'
950 // ' print("!");\n'
951 // ' }\n'
952 // '}',
953 // 'foo() {\n'
954 // ' while (true &&\n'
955 // ' true) {\n'
956 // ' print("!");\n'
957 // ' }\n'
958 // '}'
959 // );
960 // expectStmtFormatsTo(
961 // 'foo() {\n'
962 // ' do {\n'
963 // ' print("!");\n'
964 // ' } while (true &&\n'
965 // ' true);\n'
966 // '}',
967 // 'foo() {\n'
968 // ' do {\n'
969 // ' print("!");\n'
970 // ' } while (true &&\n'
971 // ' true);\n'
972 // '}'
973 // );
974 // expectStmtFormatsTo(
975 // 'int foo() {\n'
976 // ' return\n'
977 // ' foo();\n'
978 // '}',
979 // 'int foo() {\n'
980 // ' return\n'
981 // ' foo();\n'
982 // '}'
983 // );
984 // expectStmtFormatsTo(
985 // 'int foo() {\n'
986 // ' return\n'
987 // ' 13;\n'
988 // '}',
989 // 'int foo() {\n'
990 // ' return\n'
991 // ' 13;\n'
992 // '}'
993 // );
994 // expectStmtFormatsTo(
995 // 'foo(fn()) {\n'
996 // ' return foo(() {\n'
997 // ' return 1;\n'
998 // '});\n'
999 // '}',
1000 // 'foo(fn()) {\n'
1001 // ' return foo(() {\n'
1002 // ' return 1;\n'
1003 // '});\n'
1004 // '}'
1005 // );
1006 // expectStmtFormatsTo(
1007 // 'true ? foo() :\n'
1008 // ' bar();',
1009 // 'true ? foo() :\n'
1010 // ' bar();'
1011 // );
1012 // expectCUFormatsTo(
1013 // 'import "dart:core" as\n'
1014 // ' core;\n',
1015 // 'import "dart:core" as\n'
1016 // ' core;\n'
1017 // );
1018 // expectCUFormatsTo(
1019 // 'export "package:foo/foo.dart" show\n'
1020 // ' Foo;\n',
1021 // 'export "package:foo/foo.dart" show\n'
1022 // ' Foo;\n'
1023 // );
1024 // expectCUFormatsTo(
1025 // 'class Foo extends Bar implements\n'
1026 // ' Baz {\n'
1027 // '}\n',
1028 // 'class Foo extends Bar implements\n'
1029 // ' Baz {\n'
1030 // '}\n'
1031 // );
1032 // });
1033
917 test('initialIndent', () { 1034 test('initialIndent', () {
918 var formatter = new CodeFormatter( 1035 var formatter = new CodeFormatter(
919 new FormatterOptions(initialIndentationLevel: 2)); 1036 new FormatterOptions(initialIndentationLevel: 2));
920 var formattedSource = 1037 var formattedSource =
921 formatter.format(CodeKind.STATEMENT, 'var x;').source; 1038 formatter.format(CodeKind.STATEMENT, 'var x;').source;
922 expect(formattedSource, startsWith(' ')); 1039 expect(formattedSource, startsWith(' '));
923 }); 1040 });
924 1041
925 test('selections', () { 1042 test('selections', () {
926 expectSelectedPostFormat('class X {}', '}'); 1043 expectSelectedPostFormat('class X {}', '}');
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), 1265 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(),
1149 throwsA(new isInstanceOf<FormatterException>())); 1266 throwsA(new isInstanceOf<FormatterException>()));
1150 1267
1151 expectCUFormatsTo(src, expected, {transforms: true}) => 1268 expectCUFormatsTo(src, expected, {transforms: true}) =>
1152 expect(formatCU(src, options: new FormatterOptions( 1269 expect(formatCU(src, options: new FormatterOptions(
1153 codeTransforms: transforms)).source, equals(expected)); 1270 codeTransforms: transforms)).source, equals(expected));
1154 1271
1155 expectStmtFormatsTo(src, expected, {transforms: true}) => 1272 expectStmtFormatsTo(src, expected, {transforms: true}) =>
1156 expect(formatStatement(src, options: 1273 expect(formatStatement(src, options:
1157 new FormatterOptions(codeTransforms: transforms)), equals(expected)); 1274 new FormatterOptions(codeTransforms: transforms)), equals(expected));
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/services/formatter_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698