| 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/protocol.dart'; | 11 import 'package:analysis_server/src/protocol.dart'; |
| 12 import 'package:analyzer/src/plugin/plugin_impl.dart'; |
| 11 import 'package:unittest/unittest.dart' hide ERROR; | 13 import 'package:unittest/unittest.dart' hide ERROR; |
| 12 | 14 |
| 13 import '../analysis_abstract.dart'; | 15 import '../analysis_abstract.dart'; |
| 14 import '../reflective_tests.dart'; | 16 import '../reflective_tests.dart'; |
| 15 | 17 |
| 16 main() { | 18 main() { |
| 17 groupSep = ' | '; | 19 groupSep = ' | '; |
| 18 runReflectiveTests(FormatTest); | 20 runReflectiveTests(FormatTest); |
| 19 } | 21 } |
| 20 | 22 |
| 21 @reflectiveTest | 23 @reflectiveTest |
| 22 class FormatTest extends AbstractAnalysisTest { | 24 class FormatTest extends AbstractAnalysisTest { |
| 23 @override | 25 @override |
| 24 void setUp() { | 26 void setUp() { |
| 25 super.setUp(); | 27 super.setUp(); |
| 26 createProject(); | 28 createProject(); |
| 27 handler = new EditDomainHandler(server); | 29 ExtensionManager manager = new ExtensionManager(); |
| 30 ServerPlugin plugin = new ServerPlugin(); |
| 31 manager.processPlugins([plugin]); |
| 32 handler = new EditDomainHandler(server, plugin); |
| 33 } |
| 34 |
| 35 Future test_formatNoOp() { |
| 36 // Already formatted source |
| 37 addTestFile(''' |
| 38 main() { |
| 39 int x = 3; |
| 40 } |
| 41 '''); |
| 42 return waitForTasksFinished().then((_) { |
| 43 EditFormatResult formatResult = _formatAt(0, 3); |
| 44 expect(formatResult.edits, isNotNull); |
| 45 expect(formatResult.edits, hasLength(0)); |
| 46 }); |
| 28 } | 47 } |
| 29 | 48 |
| 30 Future test_formatSimple() { | 49 Future test_formatSimple() { |
| 31 addTestFile(''' | 50 addTestFile(''' |
| 32 main() { int x = 3; } | 51 main() { int x = 3; } |
| 33 '''); | 52 '''); |
| 34 return waitForTasksFinished().then((_) { | 53 return waitForTasksFinished().then((_) { |
| 35 EditFormatResult formatResult = _formatAt(0, 3); | 54 EditFormatResult formatResult = _formatAt(0, 3); |
| 36 | 55 |
| 37 expect(formatResult.edits, isNotNull); | 56 expect(formatResult.edits, isNotNull); |
| 38 expect(formatResult.edits, hasLength(1)); | 57 expect(formatResult.edits, hasLength(1)); |
| 39 | 58 |
| 40 SourceEdit edit = formatResult.edits[0]; | 59 SourceEdit edit = formatResult.edits[0]; |
| 41 expect(edit.replacement, equals(''' | 60 expect(edit.replacement, equals(''' |
| 42 main() { | 61 main() { |
| 43 int x = 3; | 62 int x = 3; |
| 44 } | 63 } |
| 45 ''')); | 64 ''')); |
| 46 expect(formatResult.selectionOffset, equals(0)); | 65 expect(formatResult.selectionOffset, equals(0)); |
| 47 expect(formatResult.selectionLength, equals(3)); | 66 expect(formatResult.selectionLength, equals(3)); |
| 48 }); | 67 }); |
| 49 } | 68 } |
| 50 | 69 |
| 51 Future test_formatNoOp() { | |
| 52 // Already formatted source | |
| 53 addTestFile(''' | |
| 54 main() { | |
| 55 int x = 3; | |
| 56 } | |
| 57 '''); | |
| 58 return waitForTasksFinished().then((_) { | |
| 59 EditFormatResult formatResult = _formatAt(0, 3); | |
| 60 expect(formatResult.edits, isNotNull); | |
| 61 expect(formatResult.edits, hasLength(0)); | |
| 62 }); | |
| 63 } | |
| 64 | |
| 65 EditFormatResult _formatAt(int selectionOffset, int selectionLength) { | 70 EditFormatResult _formatAt(int selectionOffset, int selectionLength) { |
| 66 Request request = new EditFormatParams( | 71 Request request = new EditFormatParams( |
| 67 testFile, selectionOffset, selectionLength).toRequest('0'); | 72 testFile, selectionOffset, selectionLength).toRequest('0'); |
| 68 Response response = handleSuccessfulRequest(request); | 73 Response response = handleSuccessfulRequest(request); |
| 69 return new EditFormatResult.fromResponse(response); | 74 return new EditFormatResult.fromResponse(response); |
| 70 } | 75 } |
| 71 } | 76 } |
| OLD | NEW |