| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart_style.test.formatter_test; | 5 library dart_style.test.formatter_test; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 10 import 'package:unittest/compact_vm_config.dart'; | 10 import 'package:unittest/compact_vm_config.dart'; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 var formatter = new DartFormatter(indent: 2); | 110 var formatter = new DartFormatter(indent: 2); |
| 111 expect(formatter.formatStatement('if (foo) {bar;}'), equals( | 111 expect(formatter.formatStatement('if (foo) {bar;}'), equals( |
| 112 ' if (foo) {\n' | 112 ' if (foo) {\n' |
| 113 ' bar;\n' | 113 ' bar;\n' |
| 114 ' }')); | 114 ' }')); |
| 115 }); | 115 }); |
| 116 | 116 |
| 117 group('line endings', () { | 117 group('line endings', () { |
| 118 test('uses given line ending', () { | 118 test('uses given line ending', () { |
| 119 expect(new DartFormatter(lineEnding: "%").format("var i = 1;"), | 119 expect(new DartFormatter(lineEnding: "%").format("var i = 1;"), |
| 120 equals("var i = 1;%")); | 120 equals("var i = 1;%")); |
| 121 }); | 121 }); |
| 122 | 122 |
| 123 test('infers \\r\\n if the first newline uses that', () { | 123 test('infers \\r\\n if the first newline uses that', () { |
| 124 expect(new DartFormatter().format("var\r\ni\n=\n1;\n"), | 124 expect(new DartFormatter().format("var\r\ni\n=\n1;\n"), |
| 125 equals("var i = 1;\r\n")); | 125 equals("var i = 1;\r\n")); |
| 126 }); | 126 }); |
| 127 | 127 |
| 128 test('infers \\n if the first newline uses that', () { | 128 test('infers \\n if the first newline uses that', () { |
| 129 expect(new DartFormatter().format("var\ni\r\n=\r\n1;\r\n"), | 129 expect(new DartFormatter().format("var\ni\r\n=\r\n1;\r\n"), |
| 130 equals("var i = 1;\n")); | 130 equals("var i = 1;\n")); |
| 131 }); | 131 }); |
| 132 | 132 |
| 133 test('defaults to \\n if there are no newlines', () { | 133 test('defaults to \\n if there are no newlines', () { |
| 134 expect(new DartFormatter().format("var i =1;"), | 134 expect(new DartFormatter().format("var i =1;"), |
| 135 equals("var i = 1;\n")); | 135 equals("var i = 1;\n")); |
| 136 }); |
| 137 |
| 138 test('handles Windows line endings in multiline strings', () { |
| 139 expect(new DartFormatter(lineEnding: "\r\n").formatStatement( |
| 140 ' """first\r\n' |
| 141 'second\r\n' |
| 142 'third""" ;'), equals( |
| 143 '"""first\r\n' |
| 144 'second\r\n' |
| 145 'third""";')); |
| 136 }); | 146 }); |
| 137 }); | 147 }); |
| 138 } | 148 } |
| 139 | 149 |
| 140 /// Run tests defined in "*.unit" and "*.stmt" files inside directory [name]. | 150 /// Run tests defined in "*.unit" and "*.stmt" files inside directory [name]. |
| 141 void testDirectory(String name) { | 151 void testDirectory(String name) { |
| 142 var indentPattern = new RegExp(r"^\(indent (\d+)\)\s*"); | 152 var indentPattern = new RegExp(r"^\(indent (\d+)\)\s*"); |
| 143 | 153 |
| 144 var dir = p.join(p.dirname(p.fromUri(Platform.script)), name); | 154 var dir = p.join(p.dirname(p.fromUri(Platform.script)), name); |
| 145 for (var entry in new Directory(dir).listSync()) { | 155 for (var entry in new Directory(dir).listSync()) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // newline *after* the "›", so remove it. | 240 // newline *after* the "›", so remove it. |
| 231 if (end != -1 && source.endsWith("\n\n")) { | 241 if (end != -1 && source.endsWith("\n\n")) { |
| 232 source = source.substring(0, source.length - 1); | 242 source = source.substring(0, source.length - 1); |
| 233 } | 243 } |
| 234 | 244 |
| 235 return new SourceCode(source, | 245 return new SourceCode(source, |
| 236 isCompilationUnit: isCompilationUnit, | 246 isCompilationUnit: isCompilationUnit, |
| 237 selectionStart: start == -1 ? null : start, | 247 selectionStart: start == -1 ? null : start, |
| 238 selectionLength: end == -1 ? null : end - start); | 248 selectionLength: end == -1 ? null : end - start); |
| 239 } | 249 } |
| OLD | NEW |