Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(816)

Side by Side Diff: pkg/analysis_server/test/edit/assists_test.dart

Issue 480223002: Test for 'edit.getAssists'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.edit.assists;
6
7 import 'dart:async';
8
9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_server/src/edit/edit_domain.dart';
11 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_server/src/services/constants.dart';
13 import 'package:analysis_server/src/services/correction/change.dart';
14 import 'package:analysis_testing/reflective_tests.dart';
15 import 'package:unittest/unittest.dart' hide ERROR;
16
17 import '../analysis_abstract.dart';
18
19
20 main() {
21 groupSep = ' | ';
22 runReflectiveTests(AssistsTest);
23 }
24
25
26 @ReflectiveTestCase()
27 class AssistsTest extends AbstractAnalysisTest {
28 List<Change> changes;
29
30 void prepareAssists(String search, [int length = 0]) {
31 int offset = findOffset(search);
32 prepareAssistsAt(offset, length);
33 }
34
35 void prepareAssistsAt(int offset, int length) {
36 Request request = new Request('0', EDIT_GET_ASSISTS);
37 request.setParameter(FILE, testFile);
38 request.setParameter(OFFSET, offset);
39 request.setParameter(LENGTH, length);
40 Response response = handleSuccessfulRequest(request);
41 List<Map<String, dynamic>> changeJsonList = response.getResult(ASSISTS);
42 // TODO(scheglov) consider using generated classes and decoders
43 changes = changeJsonList.map((Map<String, dynamic> changeJson) {
44 Change change = new Change(changeJson[MESSAGE]);
45 changeJson[EDITS].forEach((Map<String, dynamic> fileEditJson) {
46 FileEdit fileEdit = new FileEdit(fileEditJson[FILE]);
47 change.fileEdits.add(fileEdit);
48 fileEditJson[EDITS].forEach((Map<String, dynamic> json) {
49 Edit edit = new Edit(json[OFFSET], json[LENGTH], json[REPLACEMENT]);
50 fileEdit.edits.add(edit);
51 });
52 });
53 return change;
54 }).toList();
55 }
56
57 @override
58 void setUp() {
59 super.setUp();
60 createProject();
61 handler = new EditDomainHandler(server);
62 }
63
64 Future test_removeTypeAnnotation() {
65 addTestFile('''
66 main() {
67 int v = 1;
68 }
69 ''');
70 return waitForTasksFinished().then((_) {
71 prepareAssists('v =');
72 _assertHasChange('Remove type annotation', '''
73 main() {
74 var v = 1;
75 }
76 ''');
77 });
78 }
79
80 Future test_splitVariableDeclaration() {
81 addTestFile('''
82 main() {
83 int v = 1;
84 }
85 ''');
86 return waitForTasksFinished().then((_) {
87 prepareAssists('v =');
88 _assertHasChange('Split variable declaration', '''
89 main() {
90 int v;
91 v = 1;
92 }
93 ''');
94 });
95 }
96
97 Future test_surroundWithIf() {
98 addTestFile('''
99 main() {
100 print(1);
101 print(2);
102 }
103 ''');
104 return waitForTasksFinished().then((_) {
105 int offset = findOffset(' print(1)');
106 int length = findOffset('}') - offset;
107 prepareAssistsAt(offset, length);
108 _assertHasChange("Surround with 'if'", '''
109 main() {
110 if (condition) {
111 print(1);
112 print(2);
113 }
114 }
115 ''');
116 });
117 }
118
119 void _assertHasChange(String message, String expectedCode) {
120 for (Change change in changes) {
121 if (change.message == message) {
122 String resultCode =
123 Edit.applySequence(testCode, change.fileEdits[0].edits);
124 expect(resultCode, expectedCode);
125 return;
126 }
127 }
128 fail("Expected to find |$message| in\n" + changes.join('\n'));
129 }
130 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/constants.dart ('k') | pkg/analysis_server/test/edit/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698