| OLD | NEW |
| 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 Loading... |
| 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 'true ? foo() :\n' |
| 986 ' bar();', |
| 987 'true ? foo() :\n' |
| 988 ' bar();' |
| 989 ); |
| 990 expectCUFormatsTo( |
| 991 'import "dart:core" as\n' |
| 992 ' core;\n', |
| 993 'import "dart:core" as\n' |
| 994 ' core;\n' |
| 995 ); |
| 996 expectCUFormatsTo( |
| 997 'export "package:foo/foo.dart" show\n' |
| 998 ' Foo;\n', |
| 999 'export "package:foo/foo.dart" show\n' |
| 1000 ' Foo;\n' |
| 1001 ); |
| 1002 expectCUFormatsTo( |
| 1003 'class Foo extends Bar implements\n' |
| 1004 ' Baz {\n' |
| 1005 '}\n', |
| 1006 'class Foo extends Bar implements\n' |
| 1007 ' Baz {\n' |
| 1008 '}\n' |
| 1009 ); |
| 1010 }); |
| 1011 |
| 917 test('initialIndent', () { | 1012 test('initialIndent', () { |
| 918 var formatter = new CodeFormatter( | 1013 var formatter = new CodeFormatter( |
| 919 new FormatterOptions(initialIndentationLevel: 2)); | 1014 new FormatterOptions(initialIndentationLevel: 2)); |
| 920 var formattedSource = | 1015 var formattedSource = |
| 921 formatter.format(CodeKind.STATEMENT, 'var x;').source; | 1016 formatter.format(CodeKind.STATEMENT, 'var x;').source; |
| 922 expect(formattedSource, startsWith(' ')); | 1017 expect(formattedSource, startsWith(' ')); |
| 923 }); | 1018 }); |
| 924 | 1019 |
| 925 test('selections', () { | 1020 test('selections', () { |
| 926 expectSelectedPostFormat('class X {}', '}'); | 1021 expectSelectedPostFormat('class X {}', '}'); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), | 1243 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), |
| 1149 throwsA(new isInstanceOf<FormatterException>())); | 1244 throwsA(new isInstanceOf<FormatterException>())); |
| 1150 | 1245 |
| 1151 expectCUFormatsTo(src, expected, {transforms: true}) => | 1246 expectCUFormatsTo(src, expected, {transforms: true}) => |
| 1152 expect(formatCU(src, options: new FormatterOptions( | 1247 expect(formatCU(src, options: new FormatterOptions( |
| 1153 codeTransforms: transforms)).source, equals(expected)); | 1248 codeTransforms: transforms)).source, equals(expected)); |
| 1154 | 1249 |
| 1155 expectStmtFormatsTo(src, expected, {transforms: true}) => | 1250 expectStmtFormatsTo(src, expected, {transforms: true}) => |
| 1156 expect(formatStatement(src, options: | 1251 expect(formatStatement(src, options: |
| 1157 new FormatterOptions(codeTransforms: transforms)), equals(expected)); | 1252 new FormatterOptions(codeTransforms: transforms)), equals(expected)); |
| OLD | NEW |