| 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/ast.dart'; | 7 import 'package:analyzer_experimental/src/generated/ast.dart'; |
| 8 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 8 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| 9 import 'package:analyzer_experimental/src/services/formatter.dart'; | 9 import 'package:analyzer_experimental/src/services/formatter.dart'; |
| 10 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; | 10 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; |
| 11 import 'package:analyzer_experimental/src/services/writer.dart'; | 11 import 'package:analyzer_experimental/src/services/writer.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 | 14 |
| 15 /// Formatter tests | 15 /// Formatter tests |
| 16 group('formatter', () { | 16 group('formatter', () { |
| 17 | 17 |
| 18 test('failed parse', () { | 18 test('failed parse', () { |
| 19 var formatter = new CodeFormatter(); | 19 var formatter = new CodeFormatter(); |
| 20 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'), | 20 expect(() => formatter.format(CodeKind.COMPILATION_UNIT, '~'), |
| 21 throwsA(new isInstanceOf<FormatterException>())); | 21 throwsA(new isInstanceOf<FormatterException>())); |
| 22 }); | 22 }); |
| 23 | 23 |
| 24 test('CU (1)', () { | 24 test('CU (1)', () { |
| 25 expectCUFormatsTo( | 25 expectCUFormatsTo( |
| 26 'class A {\n' | 26 'class A {\n' |
| 27 '}', | 27 '}', |
| 28 'class A {\n' | 28 'class A {\n' |
| 29 '}' | 29 '}\n' |
| 30 ); | 30 ); |
| 31 }); | 31 }); |
| 32 | 32 |
| 33 test('CU (2)', () { | 33 test('CU (2)', () { |
| 34 expectCUFormatsTo( | 34 expectCUFormatsTo( |
| 35 'class A { \n' | 35 'class A { \n' |
| 36 '}', | 36 '}', |
| 37 'class A {\n' | 37 'class A {\n' |
| 38 '}' | 38 '}\n' |
| 39 ); | 39 ); |
| 40 }); | 40 }); |
| 41 | 41 |
| 42 test('CU (3)', () { | 42 test('CU (3)', () { |
| 43 expectCUFormatsTo( | 43 expectCUFormatsTo( |
| 44 'class A {\n' | 44 'class A {\n' |
| 45 ' }', | 45 ' }', |
| 46 'class A {\n' | 46 'class A {\n' |
| 47 '}' | 47 '}\n' |
| 48 ); | 48 ); |
| 49 }); | 49 }); |
| 50 | 50 |
| 51 test('CU (4)', () { | 51 test('CU (4)', () { |
| 52 expectCUFormatsTo( | 52 expectCUFormatsTo( |
| 53 ' class A {\n' | 53 ' class A {\n' |
| 54 '}', | 54 '}', |
| 55 'class A {\n' | 55 'class A {\n' |
| 56 '}' | 56 '}\n' |
| 57 ); | 57 ); |
| 58 }); | 58 }); |
| 59 | 59 |
| 60 test('CU (method indent)', () { | 60 test('CU (method indent)', () { |
| 61 expectCUFormatsTo( | 61 expectCUFormatsTo( |
| 62 'class A {\n' | 62 'class A {\n' |
| 63 'void x(){\n' | 63 'void x(){\n' |
| 64 '}\n' | 64 '}\n' |
| 65 '}', | 65 '}', |
| 66 'class A {\n' | 66 'class A {\n' |
| 67 ' void x() {\n' | 67 ' void x() {\n' |
| 68 ' }\n' | 68 ' }\n' |
| 69 '}' | 69 '}\n' |
| 70 ); | 70 ); |
| 71 }); | 71 }); |
| 72 | 72 |
| 73 test('CU (method indent - 2)', () { | 73 test('CU (method indent - 2)', () { |
| 74 expectCUFormatsTo( | 74 expectCUFormatsTo( |
| 75 'class A {\n' | 75 'class A {\n' |
| 76 ' static bool x(){ return true; }\n' | 76 ' static bool x(){ return true; }\n' |
| 77 ' }', | 77 ' }', |
| 78 'class A {\n' | 78 'class A {\n' |
| 79 ' static bool x() {\n' | 79 ' static bool x() {\n' |
| 80 ' return true;\n' | 80 ' return true;\n' |
| 81 ' }\n' | 81 ' }\n' |
| 82 '}' | 82 '}\n' |
| 83 ); | 83 ); |
| 84 }); | 84 }); |
| 85 | 85 |
| 86 test('CU (method indent - 3)', () { | 86 test('CU (method indent - 3)', () { |
| 87 expectCUFormatsTo( | 87 expectCUFormatsTo( |
| 88 'class A {\n' | 88 'class A {\n' |
| 89 ' int x() => 42 + 3 ; \n' | 89 ' int x() => 42 + 3 ; \n' |
| 90 ' }', | 90 ' }', |
| 91 'class A {\n' | 91 'class A {\n' |
| 92 ' int x() => 42 + 3;\n' | 92 ' int x() => 42 + 3;\n' |
| 93 '}' | 93 '}\n' |
| 94 ); | 94 ); |
| 95 }); | 95 }); |
| 96 | 96 |
| 97 test('CU (method indent - 4)', () { | 97 test('CU (method indent - 4)', () { |
| 98 expectCUFormatsTo( | 98 expectCUFormatsTo( |
| 99 'class A {\n' | 99 'class A {\n' |
| 100 ' int x() { \n' | 100 ' int x() { \n' |
| 101 'if (true) {return 42;\n' | 101 'if (true) {return 42;\n' |
| 102 '} else { return false; }\n' | 102 '} else { return false; }\n' |
| 103 ' }' | 103 ' }' |
| 104 '}', | 104 '}', |
| 105 'class A {\n' | 105 'class A {\n' |
| 106 ' int x() {\n' | 106 ' int x() {\n' |
| 107 ' if (true) {\n' | 107 ' if (true) {\n' |
| 108 ' return 42;\n' | 108 ' return 42;\n' |
| 109 ' } else {\n' | 109 ' } else {\n' |
| 110 ' return false;\n' | 110 ' return false;\n' |
| 111 ' }\n' | 111 ' }\n' |
| 112 ' }\n' | 112 ' }\n' |
| 113 '}' | 113 '}\n' |
| 114 ); | 114 ); |
| 115 }); | 115 }); |
| 116 | 116 |
| 117 test('CU (multiple members)', () { |
| 118 expectCUFormatsTo( |
| 119 'class A {\n' |
| 120 '}\n' |
| 121 'class B {\n' |
| 122 '}\n', |
| 123 'class A {\n' |
| 124 '}\n' |
| 125 'class B {\n' |
| 126 '}\n' |
| 127 ); |
| 128 }); |
| 129 |
| 130 test('CU (multiple members w/blanks)', () { |
| 131 expectCUFormatsTo( |
| 132 'class A {\n' |
| 133 '}\n\n' |
| 134 'class B {\n' |
| 135 '}\n', |
| 136 'class A {\n' |
| 137 '}\n\n' |
| 138 'class B {\n' |
| 139 '}\n' |
| 140 ); |
| 141 }); |
| 142 |
| 143 |
| 117 test('stmt', () { | 144 test('stmt', () { |
| 118 expectStmtFormatsTo( | 145 expectStmtFormatsTo( |
| 119 'if (true){\n' | 146 'if (true){\n' |
| 120 'if (true){\n' | 147 'if (true){\n' |
| 121 'if (true){\n' | 148 'if (true){\n' |
| 122 'return true;\n' | 149 'return true;\n' |
| 123 '} else{\n' | 150 '} else{\n' |
| 124 'return false;\n' | 151 'return false;\n' |
| 125 '}\n' | 152 '}\n' |
| 126 '}\n' | 153 '}\n' |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 String formatCU(src, {options: const FormatterOptions()}) => | 293 String formatCU(src, {options: const FormatterOptions()}) => |
| 267 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); | 294 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); |
| 268 | 295 |
| 269 String formatStatement(src, {options: const FormatterOptions()}) => | 296 String formatStatement(src, {options: const FormatterOptions()}) => |
| 270 new CodeFormatter(options).format(CodeKind.STATEMENT, src); | 297 new CodeFormatter(options).format(CodeKind.STATEMENT, src); |
| 271 | 298 |
| 272 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); | 299 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); |
| 273 | 300 |
| 274 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), | 301 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), |
| 275 equals(expected)); | 302 equals(expected)); |
| OLD | NEW |