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.command_line; | 5 library dart_style.test.command_line; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
10 import 'package:scheduled_test/descriptor.dart' as d; | 10 import 'package:scheduled_test/descriptor.dart' as d; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 var process = runFormatterOnDir(["--machine"]); | 141 var process = runFormatterOnDir(["--machine"]); |
142 | 142 |
143 // The order isn't specified. | 143 // The order isn't specified. |
144 process.stdout.expect(either(jsonA, jsonB)); | 144 process.stdout.expect(either(jsonA, jsonB)); |
145 process.stdout.expect(either(jsonA, jsonB)); | 145 process.stdout.expect(either(jsonA, jsonB)); |
146 process.shouldExit(); | 146 process.shouldExit(); |
147 }); | 147 }); |
148 }); | 148 }); |
149 | 149 |
| 150 group("--preserve", () { |
| 151 test("errors if given paths.", () { |
| 152 var process = runFormatter(["--preserve", "path", "another"]); |
| 153 process.shouldExit(64); |
| 154 }); |
| 155 |
| 156 test("errors on wrong number of components.", () { |
| 157 var process = runFormatter(["--preserve", "1"]); |
| 158 process.shouldExit(64); |
| 159 |
| 160 process = runFormatter(["--preserve", "1:2:3"]); |
| 161 process.shouldExit(64); |
| 162 }); |
| 163 |
| 164 test("errors on non-integer component.", () { |
| 165 var process = runFormatter(["--preserve", "1:2.3"]); |
| 166 process.shouldExit(64); |
| 167 }); |
| 168 |
| 169 test("updates selection.", () { |
| 170 var process = runFormatter(["--preserve", "6:10", "-m"]); |
| 171 process.writeLine(unformattedSource); |
| 172 process.closeStdin(); |
| 173 |
| 174 var json = JSON.encode({ |
| 175 "path": "<stdin>", |
| 176 "source": formattedSource, |
| 177 "selection": {"offset": 5, "length": 9} |
| 178 }); |
| 179 |
| 180 process.stdout.expect(json); |
| 181 process.shouldExit(); |
| 182 }); |
| 183 }); |
| 184 |
150 group("with no paths", () { | 185 group("with no paths", () { |
151 test("errors on --overwrite.", () { | 186 test("errors on --overwrite.", () { |
152 var process = runFormatter(["--overwrite"]); | 187 var process = runFormatter(["--overwrite"]); |
153 process.shouldExit(64); | 188 process.shouldExit(64); |
154 }); | 189 }); |
155 | 190 |
156 test("reads from stdin.", () { | 191 test("reads from stdin.", () { |
157 var process = runFormatter(); | 192 var process = runFormatter(); |
158 process.writeLine(unformattedSource); | 193 process.writeLine(unformattedSource); |
159 process.closeStdin(); | 194 process.closeStdin(); |
160 | 195 |
161 // No trailing newline at the end. | 196 // No trailing newline at the end. |
162 process.stdout.expect(formattedSource.trimRight()); | 197 process.stdout.expect(formattedSource.trimRight()); |
163 process.shouldExit(); | 198 process.shouldExit(); |
164 }); | 199 }); |
165 }); | 200 }); |
166 } | 201 } |
OLD | NEW |