| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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)', () { |
| 187 expectStmtFormatsTo( |
| 188 'switch (fruit) {\n' |
| 189 'case "apple":\n' |
| 190 'print("delish");\n' |
| 191 'break;\n' |
| 192 'case "fig":\n' |
| 193 'print("bleh");\n' |
| 194 'break;\n' |
| 195 '}\n', |
| 196 'switch (fruit) {\n' |
| 197 ' case "apple":\n' |
| 198 ' print("delish");\n' |
| 199 ' break;\n' |
| 200 ' case "fig":\n' |
| 201 ' print("bleh");\n' |
| 202 ' break;\n' |
| 203 '}\n' |
| 204 ); |
| 205 }); |
| 206 |
| 207 test('stmt (generics)', () { |
| 208 expectStmtFormatsTo( |
| 209 'var numbers = <int>[1, 2, (3 + 4)];', |
| 210 'var numbers = <int>[1, 2, (3 + 4)];' |
| 211 ); |
| 212 }); |
| 213 |
| 214 test('stmt (try/catch)', () { |
| 215 expectStmtFormatsTo( |
| 216 'try {\n' |
| 217 'doSomething();\n' |
| 218 '} catch (e) {\n' |
| 219 'print(e);\n' |
| 220 '}\n', |
| 221 'try {\n' |
| 222 ' doSomething();\n' |
| 223 '} catch (e) {\n' |
| 224 ' print(e);\n' |
| 225 '}\n' |
| 226 ); |
| 227 }); |
| 228 |
| 229 |
| 230 test('stmt (binary/ternary ops)', () { |
| 231 expectStmtFormatsTo( |
| 232 'var a = 1 + 2 / (3 * -b);', |
| 233 'var a = 1 + 2 / (3 * -b);' |
| 234 ); |
| 235 expectStmtFormatsTo( |
| 236 'var c = !condition == a > b;', |
| 237 'var c = !condition == a > b;' |
| 238 ); |
| 239 expectStmtFormatsTo( |
| 240 'var d = condition ? b : object.method(a, b, c);', |
| 241 'var d = condition ? b : object.method(a, b, c);' |
| 242 ); |
| 243 expectStmtFormatsTo( |
| 244 'var d = obj is! SomeType;', |
| 245 'var d = obj is! SomeType;' |
| 246 ); |
| 247 }); |
| 248 |
| 186 test('initialIndent', () { | 249 test('initialIndent', () { |
| 187 var formatter = new CodeFormatter( | 250 var formatter = new CodeFormatter( |
| 188 new FormatterOptions(initialIndentationLevel: 2)); | 251 new FormatterOptions(initialIndentationLevel: 2)); |
| 189 var formattedSource = formatter.format(CodeKind.STATEMENT, 'var x;'); | 252 var formattedSource = formatter.format(CodeKind.STATEMENT, 'var x;'); |
| 190 expect(formattedSource, startsWith(' ')); | 253 expect(formattedSource, startsWith(' ')); |
| 191 }); | 254 }); |
| 192 | 255 |
| 193 }); | 256 }); |
| 194 | 257 |
| 195 | 258 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 String formatCU(src, {options: const FormatterOptions()}) => | 381 String formatCU(src, {options: const FormatterOptions()}) => |
| 319 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); | 382 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); |
| 320 | 383 |
| 321 String formatStatement(src, {options: const FormatterOptions()}) => | 384 String formatStatement(src, {options: const FormatterOptions()}) => |
| 322 new CodeFormatter(options).format(CodeKind.STATEMENT, src); | 385 new CodeFormatter(options).format(CodeKind.STATEMENT, src); |
| 323 | 386 |
| 324 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); | 387 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); |
| 325 | 388 |
| 326 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), | 389 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), |
| 327 equals(expected)); | 390 equals(expected)); |
| OLD | NEW |