| 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_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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 'class B {\n\n\n' | 146 'class B {\n\n\n' |
| 147 ' int b() => 42;\n\n' | 147 ' int b() => 42;\n\n' |
| 148 ' int c() => b();\n\n' | 148 ' int c() => b();\n\n' |
| 149 '}\n', | 149 '}\n', |
| 150 'class A {\n' | 150 'class A {\n' |
| 151 '}\n\n' | 151 '}\n\n' |
| 152 'class B {\n\n\n' | 152 'class B {\n\n\n' |
| 153 ' int b() => 42;\n\n' | 153 ' int b() => 42;\n\n' |
| 154 ' int c() => b();\n\n' | 154 ' int c() => b();\n\n' |
| 155 '}\n' | 155 '}\n' |
| 156 ); | 156 ); |
| 157 }); | 157 }); |
| 158 | 158 |
| 159 test('stmt', () { | 159 test('stmt', () { |
| 160 expectStmtFormatsTo( | 160 expectStmtFormatsTo( |
| 161 'if (true){\n' | 161 'if (true){\n' |
| 162 'if (true){\n' | 162 'if (true){\n' |
| 163 'if (true){\n' | 163 'if (true){\n' |
| 164 'return true;\n' | 164 'return true;\n' |
| 165 '} else{\n' | 165 '} else{\n' |
| 166 'return false;\n' | 166 'return false;\n' |
| 167 '}\n' | 167 '}\n' |
| 168 '}\n' | 168 '}\n' |
| 169 '}else{\n' | 169 '}else{\n' |
| 170 'return false;\n' | 170 'return false;\n' |
| 171 '}', | 171 '}', |
| 172 'if (true) {\n' | 172 'if (true) {\n' |
| 173 ' if (true) {\n' | 173 ' if (true) {\n' |
| 174 ' if (true) {\n' | 174 ' if (true) {\n' |
| 175 ' return true;\n' | 175 ' return true;\n' |
| 176 ' } else {\n' | 176 ' } else {\n' |
| 177 ' return false;\n' | 177 ' return false;\n' |
| 178 ' }\n' | 178 ' }\n' |
| 179 ' }\n' | 179 ' }\n' |
| 180 '} else {\n' | 180 '} else {\n' |
| 181 ' return false;\n' | 181 ' return false;\n' |
| 182 '}' | 182 '}' |
| 183 ); | 183 ); |
| 184 }); | 184 }); |
| 185 | 185 |
| 186 test('stmt (switch)', () { | 186 test('stmt (switch)', () { |
| 187 expectStmtFormatsTo( | 187 expectStmtFormatsTo( |
| 188 'switch (fruit) {\n' | 188 'switch (fruit) {\n' |
| 189 'case "apple":\n' | 189 'case "apple":\n' |
| 190 'print("delish");\n' | 190 'print("delish");\n' |
| 191 'break;\n' | 191 'break;\n' |
| 192 'case "fig":\n' | 192 'case "fig":\n' |
| 193 'print("bleh");\n' | 193 'print("bleh");\n' |
| (...skipping 25 matching lines...) Expand all Loading... |
| 219 'print(e);\n' | 219 'print(e);\n' |
| 220 '}\n', | 220 '}\n', |
| 221 'try {\n' | 221 'try {\n' |
| 222 ' doSomething();\n' | 222 ' doSomething();\n' |
| 223 '} catch (e) {\n' | 223 '} catch (e) {\n' |
| 224 ' print(e);\n' | 224 ' print(e);\n' |
| 225 '}\n' | 225 '}\n' |
| 226 ); | 226 ); |
| 227 }); | 227 }); |
| 228 | 228 |
| 229 | |
| 230 test('stmt (binary/ternary ops)', () { | 229 test('stmt (binary/ternary ops)', () { |
| 231 expectStmtFormatsTo( | 230 expectStmtFormatsTo( |
| 232 'var a = 1 + 2 / (3 * -b);', | 231 'var a = 1 + 2 / (3 * -b);', |
| 233 'var a = 1 + 2 / (3 * -b);' | 232 'var a = 1 + 2 / (3 * -b);' |
| 234 ); | 233 ); |
| 235 expectStmtFormatsTo( | 234 expectStmtFormatsTo( |
| 236 'var c = !condition == a > b;', | 235 'var c = !condition == a > b;', |
| 237 'var c = !condition == a > b;' | 236 'var c = !condition == a > b;' |
| 238 ); | 237 ); |
| 239 expectStmtFormatsTo( | 238 expectStmtFormatsTo( |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 String formatCU(src, {options: const FormatterOptions()}) => | 380 String formatCU(src, {options: const FormatterOptions()}) => |
| 382 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); | 381 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); |
| 383 | 382 |
| 384 String formatStatement(src, {options: const FormatterOptions()}) => | 383 String formatStatement(src, {options: const FormatterOptions()}) => |
| 385 new CodeFormatter(options).format(CodeKind.STATEMENT, src); | 384 new CodeFormatter(options).format(CodeKind.STATEMENT, src); |
| 386 | 385 |
| 387 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); | 386 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); |
| 388 | 387 |
| 389 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), | 388 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), |
| 390 equals(expected)); | 389 equals(expected)); |
| OLD | NEW |