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

Side by Side Diff: pkg/analysis_server/test/services/completion/completion_target_test.dart

Issue 985183003: fix completion target handling of comments (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/completion_target.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.services.completion.target; 5 library test.services.completion.target;
6 6
7 import 'package:analysis_server/src/services/completion/completion_target.dart'; 7 import 'package:analysis_server/src/services/completion/completion_target.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 assertCommon(); 52 assertCommon();
53 expect(target.isFunctionalArgument(), isFunctionalArgument); 53 expect(target.isFunctionalArgument(), isFunctionalArgument);
54 } 54 }
55 55
56 test_ArgumentList_InstanceCreationExpression() { 56 test_ArgumentList_InstanceCreationExpression() {
57 // ArgumentList InstanceCreationExpression Block 57 // ArgumentList InstanceCreationExpression Block
58 addTestSource('main() {new Foo(^)}'); 58 addTestSource('main() {new Foo(^)}');
59 assertTarget(')', '()', argIndex: 0); 59 assertTarget(')', '()', argIndex: 0);
60 } 60 }
61 61
62 test_ArgumentList_InstanceCreationExpression_functionArg2() {
63 // ArgumentList InstanceCreationExpression Block
64 addTestSource('main() {new B(^)} class B{B(f()){}}');
65 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
66 }
67
62 test_ArgumentList_MethodInvocation() { 68 test_ArgumentList_MethodInvocation() {
63 // ArgumentList MethodInvocation Block 69 // ArgumentList MethodInvocation Block
64 addTestSource('main() {foo(^)}'); 70 addTestSource('main() {foo(^)}');
65 assertTarget(')', '()', argIndex: 0); 71 assertTarget(')', '()', argIndex: 0);
66 } 72 }
67 73
68 test_ArgumentList_MethodInvocation2() { 74 test_ArgumentList_MethodInvocation2() {
69 // ArgumentList MethodInvocation Block 75 // ArgumentList MethodInvocation Block
70 addTestSource('main() {foo(^n)}'); 76 addTestSource('main() {foo(^n)}');
71 assertTarget('n', '(n)', argIndex: 0); 77 assertTarget('n', '(n)', argIndex: 0);
(...skipping 16 matching lines...) Expand all
88 addTestSource('main() {foo(^)} foo(f()) {}'); 94 addTestSource('main() {foo(^)} foo(f()) {}');
89 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true); 95 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
90 } 96 }
91 97
92 test_ArgumentList_MethodInvocation_functionArg2() { 98 test_ArgumentList_MethodInvocation_functionArg2() {
93 // ArgumentList MethodInvocation Block 99 // ArgumentList MethodInvocation Block
94 addTestSource('main() {new B().boo(^)} class B{boo(f()){}}'); 100 addTestSource('main() {new B().boo(^)} class B{boo(f()){}}');
95 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true); 101 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
96 } 102 }
97 103
98 test_ArgumentList_InstanceCreationExpression_functionArg2() {
99 // ArgumentList InstanceCreationExpression Block
100 addTestSource('main() {new B(^)} class B{B(f()){}}');
101 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
102 }
103
104 test_AsExpression_identifier() { 104 test_AsExpression_identifier() {
105 // SimpleIdentifier TypeName AsExpression 105 // SimpleIdentifier TypeName AsExpression
106 addTestSource('class A {var b; X _c; foo() {var a; (a^ as String).foo();}'); 106 addTestSource('class A {var b; X _c; foo() {var a; (a^ as String).foo();}');
107 assertTarget('a as String', '(a as String)'); 107 assertTarget('a as String', '(a as String)');
108 } 108 }
109 109
110 test_AsExpression_keyword() { 110 test_AsExpression_keyword() {
111 // SimpleIdentifier TypeName AsExpression 111 // SimpleIdentifier TypeName AsExpression
112 addTestSource('class A {var b; X _c; foo() {var a; (a ^as String).foo();}'); 112 addTestSource('class A {var b; X _c; foo() {var a; (a ^as String).foo();}');
113 assertTarget('as', 'a as String'); 113 assertTarget('as', 'a as String');
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 addTestSource('class C {foo(){var f; {var x;} new^ }}'); 148 addTestSource('class C {foo(){var f; {var x;} new^ }}');
149 assertTarget('new ();', '{var f; {var x;} new ();}'); 149 assertTarget('new ();', '{var f; {var x;} new ();}');
150 } 150 }
151 151
152 test_InstanceCreationExpression_keyword2() { 152 test_InstanceCreationExpression_keyword2() {
153 // InstanceCreationExpression ExpressionStatement Block 153 // InstanceCreationExpression ExpressionStatement Block
154 addTestSource('class C {foo(){var f; {var x;} new^ C();}}'); 154 addTestSource('class C {foo(){var f; {var x;} new^ C();}}');
155 assertTarget('new C();', '{var f; {var x;} new C();}'); 155 assertTarget('new C();', '{var f; {var x;} new C();}');
156 } 156 }
157 157
158 test_MethodDeclaration_inComment() {
159 // Comment ClassDeclaration CompilationUnit
160 addTestSource('class C2 {/* ^ */ zoo(z) {} String name;}');
161 assertTarget('/* */', 'class C2 {zoo(z) {} String name;}');
162 }
163
164 test_MethodDeclaration_inComment2() {
165 // Comment ClassDeclaration CompilationUnit
166 addTestSource('''
167 class C2 {
168 // normal comment ^
169 zoo(z) { } String name; }''');
170 assertTarget('// normal comment ', 'class C2 {zoo(z) {} String name;}');
171 }
172
173 test_MethodDeclaration_inComment3() {
174 // Comment ClassDeclaration CompilationUnit
175 addTestSource('''
176 class C2 {
177 // normal ^comment
178 zoo(z) { } String name; }''');
179 assertTarget('// normal comment', 'class C2 {zoo(z) {} String name;}');
180 }
181
182 test_MethodDeclaration_inComment4() {
183 // Comment ClassDeclaration CompilationUnit
184 addTestSource('''
185 class C2 {
186 // normal comment ^
187 // normal comment 2
188 zoo(z) { } String name; }''');
189 assertTarget('// normal comment ', 'class C2 {zoo(z) {} String name;}');
190 }
191
192 test_MethodDeclaration_inComment5() {
193 // Comment ClassDeclaration CompilationUnit
194 addTestSource('''
195 class C2 {
196 // normal comment
197 // normal comment 2^
198 zoo(z) { } String name; }''');
199 assertTarget('// normal comment 2', 'class C2 {zoo(z) {} String name;}');
200 }
201
202 test_MethodDeclaration_inDocComment() {
203 // Comment MethodDeclaration ClassDeclaration CompilationUnit
204 addTestSource('class C2 {/** ^ */ zoo(z) { } String name; }');
205 assertTarget('/** */', '');
206 expect(target.containingNode is Comment, isTrue);
207 expect(target.containingNode.parent.toSource(), 'zoo(z) {}');
208 }
209
210 test_MethodDeclaration_inDocComment2() {
211 // Comment MethodDeclaration ClassDeclaration CompilationUnit
212 addTestSource('''
213 class C2 {
214 /// some dartdoc ^
215 zoo(z) { } String name; }''');
216 assertTarget('/// some dartdoc ', '');
217 expect(target.containingNode is Comment, isTrue);
218 expect(target.containingNode.parent.toSource(), 'zoo(z) {}');
219 }
220
221 test_MethodDeclaration_inDocComment3() {
222 // Comment MethodDeclaration ClassDeclaration CompilationUnit
223 addTestSource('''
224 class C2 {
225 /// some ^dartdoc
226 zoo(z) { } String name; }''');
227 assertTarget('/// some dartdoc', '');
228 expect(target.containingNode is Comment, isTrue);
229 expect(target.containingNode.parent.toSource(), 'zoo(z) {}');
230 }
231
232 test_MethodDeclaration_returnType() {
233 // ClassDeclaration CompilationUnit
234 addTestSource('class C2 {^ zoo(z) { } String name; }');
235 assertTarget('zoo(z) {}', 'class C2 {zoo(z) {} String name;}');
236 }
237
238 test_MethodDeclaration_returnType_afterComment() {
239 // ClassDeclaration CompilationUnit
240 addTestSource('class C2 {/* */ ^ zoo(z) { } String name; }');
241 assertTarget('zoo(z) {}', 'class C2 {zoo(z) {} String name;}');
242 }
243
244 test_MethodDeclaration_returnType_afterComment2() {
245 // MethodDeclaration ClassDeclaration CompilationUnit
246 addTestSource('''
247 class C2 {
248 // normal comment
249 ^ zoo(z) {} String name;}''');
250 assertTarget('zoo(z) {}', 'class C2 {zoo(z) {} String name;}');
251 }
252
253 test_MethodDeclaration_returnType_afterDocComment() {
254 // MethodDeclaration ClassDeclaration CompilationUnit
255 addTestSource('class C2 {/** */ ^ zoo(z) { } String name; }');
256 assertTarget('zoo', 'zoo(z) {}');
257 }
258
259 test_MethodDeclaration_returnType_afterDocComment2() {
260 // SimpleIdentifier MethodDeclaration ClassDeclaration CompilationUnit
261 addTestSource('''
262 class C2 {
263 /// some dartdoc
264 ^ zoo(z) { } String name; }''');
265 assertTarget('zoo', 'zoo(z) {}');
266 }
267
Paul Berry 2015/03/09 22:32:51 I'd suggest adding some corner cases to test that
danrubel 2015/03/11 15:01:56 Great suggestion. Done.
158 test_VariableDeclaration_lhs_identifier_after() { 268 test_VariableDeclaration_lhs_identifier_after() {
159 // VariableDeclaration VariableDeclarationList 269 // VariableDeclaration VariableDeclarationList
160 addTestSource('main() {int b^ = 1;}'); 270 addTestSource('main() {int b^ = 1;}');
161 assertTarget('b = 1', 'int b = 1'); 271 assertTarget('b = 1', 'int b = 1');
162 } 272 }
163 273
164 test_VariableDeclaration_lhs_identifier_before() { 274 test_VariableDeclaration_lhs_identifier_before() {
165 // VariableDeclaration VariableDeclarationList 275 // VariableDeclaration VariableDeclarationList
166 addTestSource('main() {int ^b = 1;}'); 276 addTestSource('main() {int ^b = 1;}');
167 assertTarget('b = 1', 'int b = 1'); 277 assertTarget('b = 1', 'int b = 1');
168 } 278 }
169 } 279 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/completion_target.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698