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 test.edit.sort_members; | 5 library test.edit.sort_members; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:analysis_server/src/edit/edit_domain.dart'; | 10 import 'package:analysis_server/src/edit/edit_domain.dart'; |
(...skipping 19 matching lines...) Expand all Loading... |
30 super.setUp(); | 30 super.setUp(); |
31 createProject(); | 31 createProject(); |
32 ExtensionManager manager = new ExtensionManager(); | 32 ExtensionManager manager = new ExtensionManager(); |
33 manager.processPlugins([server.serverPlugin]); | 33 manager.processPlugins([server.serverPlugin]); |
34 handler = new EditDomainHandler(server); | 34 handler = new EditDomainHandler(server); |
35 } | 35 } |
36 | 36 |
37 test_BAD_doesNotExist() async { | 37 test_BAD_doesNotExist() async { |
38 Request request = | 38 Request request = |
39 new EditSortMembersParams('/no/such/file.dart').toRequest('0'); | 39 new EditSortMembersParams('/no/such/file.dart').toRequest('0'); |
40 Response response = handler.handleRequest(request); | 40 Response response = await waitResponse(request); |
41 expect(response, | 41 expect(response, |
42 isResponseFailure('0', RequestErrorCode.SORT_MEMBERS_INVALID_FILE)); | 42 isResponseFailure('0', RequestErrorCode.SORT_MEMBERS_INVALID_FILE)); |
43 } | 43 } |
44 | 44 |
45 test_BAD_hasParseError() async { | 45 test_BAD_hasParseError() async { |
46 addTestFile(''' | 46 addTestFile(''' |
47 main() { | 47 main() { |
48 print() | 48 print() |
49 } | 49 } |
50 '''); | 50 '''); |
51 Request request = new EditSortMembersParams(testFile).toRequest('0'); | 51 Request request = new EditSortMembersParams(testFile).toRequest('0'); |
52 Response response = handler.handleRequest(request); | 52 Response response = await waitResponse(request); |
53 expect(response, | 53 expect(response, |
54 isResponseFailure('0', RequestErrorCode.SORT_MEMBERS_PARSE_ERRORS)); | 54 isResponseFailure('0', RequestErrorCode.SORT_MEMBERS_PARSE_ERRORS)); |
55 } | 55 } |
56 | 56 |
57 test_BAD_notDartFile() async { | 57 test_BAD_notDartFile() async { |
58 Request request = | 58 Request request = |
59 new EditSortMembersParams('/not-a-Dart-file.txt').toRequest('0'); | 59 new EditSortMembersParams('/not-a-Dart-file.txt').toRequest('0'); |
60 Response response = handler.handleRequest(request); | 60 Response response = await waitResponse(request); |
61 expect(response, | 61 expect(response, |
62 isResponseFailure('0', RequestErrorCode.SORT_MEMBERS_INVALID_FILE)); | 62 isResponseFailure('0', RequestErrorCode.SORT_MEMBERS_INVALID_FILE)); |
63 } | 63 } |
64 | 64 |
65 test_OK_afterWaitForAnalysis() async { | 65 test_OK_afterWaitForAnalysis() async { |
66 addTestFile(''' | 66 addTestFile(''' |
67 class C {} | 67 class C {} |
68 class A {} | 68 class A {} |
69 class B {} | 69 class B {} |
70 '''); | 70 '''); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 class B {} | 185 class B {} |
186 '''); | 186 '''); |
187 return _assertSorted(r''' | 187 return _assertSorted(r''' |
188 class A {} | 188 class A {} |
189 class B {} | 189 class B {} |
190 class C {} | 190 class C {} |
191 '''); | 191 '''); |
192 } | 192 } |
193 | 193 |
194 Future _assertSorted(String expectedCode) async { | 194 Future _assertSorted(String expectedCode) async { |
195 _requestSort(); | 195 await _requestSort(); |
196 String resultCode = SourceEdit.applySequence(testCode, fileEdit.edits); | 196 String resultCode = SourceEdit.applySequence(testCode, fileEdit.edits); |
197 expect(resultCode, expectedCode); | 197 expect(resultCode, expectedCode); |
198 } | 198 } |
199 | 199 |
200 void _requestSort() { | 200 Future _requestSort() async { |
201 Request request = new EditSortMembersParams(testFile).toRequest('0'); | 201 Request request = new EditSortMembersParams(testFile).toRequest('0'); |
202 Response response = handleSuccessfulRequest(request); | 202 Response response = await waitResponse(request); |
203 var result = new EditSortMembersResult.fromResponse(response); | 203 var result = new EditSortMembersResult.fromResponse(response); |
204 fileEdit = result.edit; | 204 fileEdit = result.edit; |
205 } | 205 } |
206 } | 206 } |
OLD | NEW |