| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 test.edit.format; | 5 library test.edit.format; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/edit/edit_domain.dart'; | 9 import 'package:analysis_server/src/edit/edit_domain.dart'; |
| 10 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 10 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 int x = 3; | 39 int x = 3; |
| 40 } | 40 } |
| 41 '''); | 41 '''); |
| 42 return waitForTasksFinished().then((_) { | 42 return waitForTasksFinished().then((_) { |
| 43 EditFormatResult formatResult = _formatAt(0, 3); | 43 EditFormatResult formatResult = _formatAt(0, 3); |
| 44 expect(formatResult.edits, isNotNull); | 44 expect(formatResult.edits, isNotNull); |
| 45 expect(formatResult.edits, hasLength(0)); | 45 expect(formatResult.edits, hasLength(0)); |
| 46 }); | 46 }); |
| 47 } | 47 } |
| 48 | 48 |
| 49 Future test_formatNoSelection() async { |
| 50 addTestFile(''' |
| 51 main() { int x = 3; } |
| 52 '''); |
| 53 await waitForTasksFinished(); |
| 54 EditFormatResult formatResult = _formatAt(0, 0); |
| 55 |
| 56 expect(formatResult.edits, isNotNull); |
| 57 expect(formatResult.edits, hasLength(1)); |
| 58 |
| 59 SourceEdit edit = formatResult.edits[0]; |
| 60 expect(edit.replacement, equals(''' |
| 61 main() { |
| 62 int x = 3; |
| 63 } |
| 64 ''')); |
| 65 expect(formatResult.selectionOffset, equals(0)); |
| 66 expect(formatResult.selectionLength, equals(0)); |
| 67 } |
| 68 |
| 49 Future test_formatSimple() { | 69 Future test_formatSimple() { |
| 50 addTestFile(''' | 70 addTestFile(''' |
| 51 main() { int x = 3; } | 71 main() { int x = 3; } |
| 52 '''); | 72 '''); |
| 53 return waitForTasksFinished().then((_) { | 73 return waitForTasksFinished().then((_) { |
| 54 EditFormatResult formatResult = _formatAt(0, 3); | 74 EditFormatResult formatResult = _formatAt(0, 3); |
| 55 | 75 |
| 56 expect(formatResult.edits, isNotNull); | 76 expect(formatResult.edits, isNotNull); |
| 57 expect(formatResult.edits, hasLength(1)); | 77 expect(formatResult.edits, hasLength(1)); |
| 58 | 78 |
| 59 SourceEdit edit = formatResult.edits[0]; | 79 SourceEdit edit = formatResult.edits[0]; |
| 60 expect(edit.replacement, equals(''' | 80 expect(edit.replacement, equals(''' |
| 61 main() { | 81 main() { |
| 62 int x = 3; | 82 int x = 3; |
| 63 } | 83 } |
| 64 ''')); | 84 ''')); |
| 65 expect(formatResult.selectionOffset, equals(0)); | 85 expect(formatResult.selectionOffset, equals(0)); |
| 66 expect(formatResult.selectionLength, equals(3)); | 86 expect(formatResult.selectionLength, equals(3)); |
| 67 }); | 87 }); |
| 68 } | 88 } |
| 69 | 89 |
| 70 EditFormatResult _formatAt(int selectionOffset, int selectionLength) { | 90 EditFormatResult _formatAt(int selectionOffset, int selectionLength) { |
| 71 Request request = new EditFormatParams( | 91 Request request = new EditFormatParams( |
| 72 testFile, selectionOffset, selectionLength).toRequest('0'); | 92 testFile, selectionOffset, selectionLength).toRequest('0'); |
| 73 Response response = handleSuccessfulRequest(request); | 93 Response response = handleSuccessfulRequest(request); |
| 74 return new EditFormatResult.fromResponse(response); | 94 return new EditFormatResult.fromResponse(response); |
| 75 } | 95 } |
| 76 } | 96 } |
| OLD | NEW |