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

Side by Side Diff: pkg/analysis_server/test/completion_test.dart

Issue 785013002: Ported completion tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | « no previous file | pkg/analysis_server/test/completion_test_support.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.completion.support;
6
7 import 'dart:collection';
8
9 import 'package:unittest/unittest.dart';
10
11 import 'completion_test_support.dart';
12
13 main() {
14 // CompletionTestBuilder builder = new CompletionTestBuilder();
15 // builder.buildAll();
16 test("dummy", () => null);
17 }
18
19 /**
20 * A builder that builds the completion tests.
21 */
22 class CompletionTestBuilder {
23 void buildAll() {
24 buildNumberedTests();
25 buildCommentSnippetTests();
26 buildCompletionTests();
27 buildOtherTests();
28 buildLibraryTests();
29 }
30
31 void buildCommentSnippetTests() {
32 CompletionTestCase.buildTests('testCommentSnippets001', '''
33 class X {static final num MAX = 0;num yc,xc;mth() {xc = yc = MA!1X;x!2c.abs();nu m f = M!3AX;}}''',
34 <String>["1+MAX", "2+xc", "3+MAX"]);
35
36 CompletionTestCase.buildTests('testCommentSnippets002', '''
37 class Y {String x='hi';mth() {x.l!1ength;int n = 0;x!2.codeUnitAt(n!3);}}''',
38 <String>["1+length", "2+x", "3+n"]);
39
40 CompletionTestCase.buildTests('testCommentSnippets004', '''
41 class A {!1int x; !2mth() {!3int y = this.!5x!6;}}class B{}''',
42 <String>["1+A", "2+B", "3+x", "3-y", "5+mth", "6+x"]);
43
44 CompletionTestCase.buildTests('testCommentSnippets005', '''
45 class Date { static Date JUN, JUL;}class X { m() { return Da!1te.JU!2L; }}''',
46 <String>["1+Date", "2+JUN", "2+JUL"]);
47
48 CompletionTestCase.buildTests('testCommentSnippets007', '''
49 class C {mth(Map x, !1) {}mtf(!2, Map x) {}m() {for (in!3t i=0; i<5; i++); A!4 x ;}}class int{}class Arrays{}class bool{}''',
50 <String>["1+bool", "2+bool", "3+int", "4+Arrays"]);
51
52 CompletionTestCase.buildTests('testCommentSnippets008', '''
53 class Date{}final num M = Dat!1''', <String>["1+Date"]);
54
55 // space, char, eol are important
56 CompletionTestCase.buildTests('testCommentSnippets009', '''
57 class Map{}class Maps{}class x extends!5 !2M!3 !4implements!6 !1\n{}''',
58 <String>[
59 "1+Map",
60 "2+Maps",
61 "3+Maps",
62 "4-Maps",
63 "4+implements",
64 "5-Maps",
65 "6-Map",
66 "6+implements"]);
67
68 // space, char, eol are important
69 CompletionTestCase.buildTests('testCommentSnippets010', '''
70 class Map{}class x implements !1{}''', <String>["1+Map"]);
71
72 // space, char, eol are important
73 CompletionTestCase.buildTests('testCommentSnippets011', '''
74 class Map{}class x implements M!1{}''', <String>["1+Map"]);
75
76 // space, char, eol are important
77 CompletionTestCase.buildTests('testCommentSnippets012', '''
78 class Map{}class x implements M!1\n{}''', <String>["1+Map"]);
79
80 CompletionTestCase.buildTests('testCommentSnippets013', '''
81 class num{}class x !2{!1}!3''', <String>["1+num", "2-num", "3-num"]);
82
83 // trailing space is important
84 CompletionTestCase.buildTests('testCommentSnippets014', '''
85 class num{}typedef n!1 ;''', <String>["1+num"]);
86
87 CompletionTestCase.buildTests('testCommentSnippets015', '''
88 class D {f(){} g(){f!1(f!2);}}''', <String>["1+f", "2+f"]);
89
90 CompletionTestCase.buildTests('testCommentSnippets016', '''
91 class F {m() { m(); !1}}''', <String>["1+m"]);
92
93 CompletionTestCase.buildTests('testCommentSnippets017', '''
94 class F {var x = !1false;}''', <String>["1+true"]);
95
96 CompletionTestCase.buildTests('testCommentSnippets018', '''
97 class Map{}class Arrays{}class C{ m(!1){} n(!2 x, q)''',
98 <String>["1+Map", "1-void", "1-null", "2+Arrays", "2-void", "2-null"]);
99
100 CompletionTestCase.buildTests('testCommentSnippets019', '''
101 class A{m(){Object x;x.!1/**/clear()''', <String>["1+toString"]);
102
103 CompletionTestCase.buildTests('testCommentSnippets020', '''
104 classMap{}class tst {var newt;void newf(){}test() {var newz;new!1/**/;}}''',
105 <String>["1+newt", "1+newf", "1+newz", "1-Map"]);
106
107 CompletionTestCase.buildTests('testCommentSnippets021', '''
108 class Map{}class tst {var newt;void newf(){}test() {var newz;new !1/**/;}}''',
109 <String>["1+Map", "1-newt"]);
110
111 CompletionTestCase.buildTests('testCommentSnippets022', '''
112 class Map{}class F{m(){new !1;}}''', <String>["1+Map"]);
113
114 CompletionTestCase.buildTests('testCommentSnippets022a', '''
115 class Map{}class F{m(){new !1''', <String>["1+Map"]);
116
117 CompletionTestCase.buildTests('testCommentSnippets022b', '''
118 class Map{factory Map.qq(){return null;}}class F{m(){new Map.!1qq();}}''',
119 <String>["1+qq"]);
120
121 CompletionTestCase.buildTests('testCommentSnippets023', '''
122 class X {X c; X(this.!1c!3) : super() {c.!2}}''',
123 <String>["1+c", "2+c", "3+c"]);
124
125 CompletionTestCase.buildTests('testCommentSnippets024', '''
126 class q {m(Map q){var x;m(!1)}n(){var x;n(!2)}}''', <String>["1+x", "2+x"]);
127
128 CompletionTestCase.buildTests('testCommentSnippets025', '''
129 class q {num m() {var q; num x=!1 q!3 + !2/**/;}}''',
130 <String>["1+q", "2+q", "3+q"]);
131
132 CompletionTestCase.buildTests('testCommentSnippets026', '''
133 class List{}class a implements !1{}''', <String>["1+List"]);
134
135 CompletionTestCase.buildTests('testCommentSnippets027', '''
136 class String{}class List{}class test <X extends !1String!2> {}''',
137 <String>["1+List", "2+String", "2-List"]);
138
139 CompletionTestCase.buildTests('testCommentSnippets028', '''
140 class String{}class List{}class DateTime{}typedef T Y<T extends !1>(List input); ''',
141 <String>["1+DateTime", "1+String"]);
142
143 CompletionTestCase.buildTests('testCommentSnippets029', '''
144 interface A<X> default B<X extends !1List!2> {}''',
145 <String>["1+DateTime", "2+List"]);
146
147 CompletionTestCase.buildTests('testCommentSnippets030', '''
148 class Bar<T extends Foo> {const Bar(!1T!2 k);T!3 m(T!4 a, T!5 b){}final T!6 f = null;}''',
149 <String>["1+T", "2+T", "3+T", "4+T", "5+T", "6+T"]);
150
151 CompletionTestCase.buildTests('testCommentSnippets031', '''
152 class Bar<T extends Foo> {m(x){if (x is !1) return;if (x is!!!2)}}''',
153 <String>["1+Bar", "1+T", "2+T", "2+Bar"]);
154
155 CompletionTestCase.buildTests('testCommentSnippets032', '''
156 class Fit{}class Bar<T extends Fooa> {const F!1ara();}''',
157 <String>["1+Fit", "1+Fara", "1-Bar"]);
158
159 // Type propagation
160 CompletionTestCase.buildTests('testCommentSnippets033', '''
161 class List{add(){}length(){}}t1() {var x;if (x is List) {x.!1add(3);}}''',
162 <String>["1+add", "1+length"]);
163
164 // Type propagation
165 CompletionTestCase.buildTests('testCommentSnippets035', '''
166 class List{clear(){}length(){}}t3() {var x=new List(), y=x.!1length();x.!2clear( );}''',
167 <String>["1+length", "2+clear"]);
168
169 CompletionTestCase.buildTests('testCommentSnippets036', '''
170 class List{}t3() {var x=new List!1}''', <String>["1+List"]);
171
172 CompletionTestCase.buildTests('testCommentSnippets037', '''
173 class List{factory List.from(){}}t3() {var x=new List.!1}''',
174 <String>["1+from"]);
175
176 CompletionTestCase.buildTests('testCommentSnippets038', '''
177 f(){int xa; String s = '\$x!1';}''', <String>["1+xa"]);
178
179 CompletionTestCase.buildTests('testCommentSnippets038a', '''
180 int xa; String s = '\$x!1\'''', <String>["1+xa"]);
181
182 CompletionTestCase.buildTests('testCommentSnippets039', '''
183 f(){int xa; String s = '\$!1';}''', <String>["1+xa"]);
184
185 CompletionTestCase.buildTests('testCommentSnippets039a', '''
186 int xa; String s = '\$!1\'''', <String>["1+xa"]);
187
188 CompletionTestCase.buildTests('testCommentSnippets040', '''
189 class List{add(){}}class Map{}class X{m(){List list; list.!1 Map map;}}''',
190 <String>["1+add"]);
191
192 CompletionTestCase.buildTests('testCommentSnippets041', '''
193 class List{add(){}length(){}}class X{m(){List list; list.!1 zox();}}''',
194 <String>["1+add"]);
195
196 CompletionTestCase.buildTests('testCommentSnippets042', '''
197 class DateTime{static const int WED=3;int get day;}fd(){DateTime d=new DateTime. now();d.!1WED!2;}''',
198 <String>["1+day", "2-WED"]);
199
200 CompletionTestCase.buildTests('testCommentSnippets043', '''
201 class L{var k;void.!1}''', <String>["1-k"]);
202
203 CompletionTestCase.buildTests('testCommentSnippets044', '''
204 class List{}class XXX {XXX.fisk();}main() {main(); new !1}}''',
205 <String>["1+List", "1+XXX.fisk"]);
206
207 CompletionTestCase.buildTests('testCommentSnippets047', '''
208 f(){int x;int y=!1;}''', <String>["1+x"]);
209
210 CompletionTestCase.buildTests('testCommentSnippets048', '''
211 import 'dart:convert' as json;f() {var x=new js!1}''', <String>["1+json"]);
212
213 CompletionTestCase.buildTests('testCommentSnippets049', '''
214 import 'dart:convert' as json;
215 import 'dart:convert' as jxx;
216 class JsonParserX{}
217 f1() {var x=new !2j!1s!3}''',
218 <String>[
219 "1+json",
220 "1+jxx",
221 "2+json",
222 "2+jxx",
223 "2-JsonParser",
224 "3+json",
225 "3-jxx"]);
226
227 CompletionTestCase.buildTests('testCommentSnippets050', '''
228 class xdr {
229 xdr();
230 const xdr.a(a,b,c);
231 xdr.b();
232 f() => 3;
233 }
234 class xa{}
235 k() {
236 new x!1dr().f();
237 const x!2dr.!3a(1, 2, 3);
238 }''',
239 <String>[
240 "1+xdr",
241 "1+xa",
242 "1+xdr.a",
243 "1+xdr.b",
244 "2-xa",
245 "2-xdr",
246 "2+xdr.a",
247 "2-xdr.b",
248 "3-b",
249 "3+a"]);
250
251 // Type propagation.
252 CompletionTestCase.buildTests('testCommentSnippets051', '''
253 class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{ge tKeys(){}}
254 void r() {
255 var v;
256 if (v is String) {
257 v.!1length;
258 v.!2getKeys;
259 }
260 }''', <String>["1+length", "2-getKeys"]);
261
262 // Type propagation.
263 CompletionTestCase.buildTests('testCommentSnippets052', '''
264 class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{ge tKeys(){}}
265 void r() {
266 List<String> values = ['a','b','c'];
267 for (var v in values) {
268 v.!1toUpperCase;
269 v.!2getKeys;
270 }
271 }''', <String>["1+toUpperCase", "2-getKeys"]);
272
273 // Type propagation.
274 CompletionTestCase.buildTests('testCommentSnippets053', '''
275 class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{ge tKeys(){}}
276 void r() {
277 var v;
278 while (v is String) {
279 v.!1toUpperCase;
280 v.!2getKeys;
281 }
282 }''', <String>["1+toUpperCase", "2-getKeys"]);
283
284 CompletionTestCase.buildTests('testCommentSnippets054', '''
285 class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{ge tKeys(){}}
286 void r() {
287 var v;
288 for (; v is String; v.!1isEmpty) {
289 v.!2toUpperCase;
290 v.!3getKeys;
291 }
292 }''', <String>["1+isEmpty", "2+toUpperCase", "3-getKeys"]);
293
294 CompletionTestCase.buildTests('testCommentSnippets055', '''
295 class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{ge tKeys(){}}
296 void r() {
297 String v;
298 if (v is Object) {
299 v.!1toUpperCase;
300 }
301 }''', <String>["1+toUpperCase"]);
302
303 // Type propagation.
304 CompletionTestCase.buildTests('testCommentSnippets056', '''
305 class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{ge tKeys(){}}
306 void f(var v) {
307 if (v is!! String) {
308 return;
309 }
310 v.!1toUpperCase;
311 }''', <String>["1+toUpperCase"]);
312
313 // Type propagation.
314 CompletionTestCase.buildTests('testCommentSnippets057', '''
315 class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{ge tKeys(){}}
316 void f(var v) {
317 if ((v as String).length == 0) {
318 v.!1toUpperCase;
319 }
320 }''', <String>["1+toUpperCase"]);
321
322 CompletionTestCase.buildTests('testCommentSnippets058', '''
323 typedef vo!2id callback(int k);
324 void x(callback q){}
325 void r() {
326 callback v;
327 x(!1);
328 }''', <String>["1+v", "2+void"]);
329
330 CompletionTestCase.buildTests('testCommentSnippets059', '''
331 f(){((int x) => x+4).!1call(1);}''', <String>["1-call"]);
332
333 CompletionTestCase.buildTests('testCommentSnippets060', '''
334 class Map{}
335 abstract class MM extends Map{factory MM() => new Map();}
336 class Z {
337 MM x;
338 f() {
339 x!1
340 }
341 }''', <String>["1+x", "1-x[]"]);
342
343 CompletionTestCase.buildTests('testCommentSnippets061', '''
344 class A{m(){!1f(3);!2}}n(){!3f(3);!4}f(x)=>x*3;''',
345 <String>["1+f", "1+n", "2+f", "2+n", "3+f", "3+n", "4+f", "4+n"]);
346
347 // Type propagation.
348 CompletionTestCase.buildTests('testCommentSnippets063', '''
349 class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{ge tKeys(){}}
350 void r(var v) {
351 v.!1toUpperCase;
352 assert(v is String);
353 v.!2toUpperCase;
354 }''', <String>["1-toUpperCase", "2+toUpperCase"]);
355
356 CompletionTestCase.buildTests('testCommentSnippets064', '''
357 class Spline {
358 Line c;
359 Spline a() {
360 return this;
361 }
362 Line b() {
363 return null;
364 }
365 Spline f() {
366 Line x = new Line();
367 x.!9h()..!1a()..!2b().!7g();
368 x.!8j..!3b()..!4c..!6c..!5a();
369 }
370 }
371 class Line {
372 Spline j;
373 Line g() {
374 return this;
375 }
376 Spline h() {
377 return null;
378 }
379 }''',
380 <String>[
381 "1+a",
382 "2+b",
383 "1-g",
384 "2-h",
385 "3+b",
386 "4+c",
387 "5+a",
388 "6+c",
389 "7+g",
390 "8+j",
391 "9+h"]);
392
393 CompletionTestCase.buildTests('testCommentSnippets065', '''
394 class Spline {
395 Line c;
396 Spline a() {
397 return this;
398 }
399 Line b() {
400 return null;
401 }
402 Spline f() {
403 Line x = new Line();
404 x.h()..!1;
405 }
406 }
407 class Line {
408 Spline j;
409 Line g() {
410 return this;
411 }
412 Spline h() {
413 return null;
414 }
415 }''', <String>["1+a"]);
416
417 CompletionTestCase.buildTests('testCommentSnippets066', '''
418 class Spline {
419 Line c;
420 Spline a() {
421 return this;
422 }
423 Line b() {
424 return null;
425 }
426 Spline f() {
427 Line x = new Line();
428 x.h()..a()..!1;
429 }
430 }
431 class Line {
432 Spline j;
433 Line g() {
434 return this;
435 }
436 Spline h() {
437 return null;
438 }
439 }''', <String>["1+b"]);
440
441 CompletionTestCase.buildTests('testCommentSnippets067', '''
442 class Spline {
443 Line c;
444 Spline a() {
445 return this;
446 }
447 Line b() {
448 return null;
449 }
450 Spline f() {
451 Line x = new Line();
452 x.h()..a()..c..!1;
453 }
454 }
455 class Line {
456 Spline j;
457 Line g() {
458 return this;
459 }
460 Spline h() {
461 return null;
462 }
463 }''', <String>["1+b"]);
464
465 CompletionTestCase.buildTests('testCommentSnippets068', '''
466 class Spline {
467 Line c;
468 Spline a() {
469 return this;
470 }
471 Line b() {
472 return null;
473 }
474 Spline f() {
475 Line x = new Line();
476 x.j..b()..c..!1;
477 }
478 }
479 class Line {
480 Spline j;
481 Line g() {
482 return this;
483 }
484 Spline h() {
485 return null;
486 }
487 }''', <String>["1+c"]);
488
489 CompletionTestCase.buildTests('testCommentSnippets069', '''
490 class Spline {
491 Line c;
492 Spline a() {
493 return this;
494 }
495 Line b() {
496 return null;
497 }
498 Spline f() {
499 Line x = new Line();
500 x.j..b()..!1;
501 }
502 }
503 class Line {
504 Spline j;
505 Line g() {
506 return this;
507 }
508 Spline h() {
509 return null;
510 }
511 }''', <String>["1+c"]);
512
513 CompletionTestCase.buildTests('testCommentSnippets070', '''
514 class Spline {
515 Line c;
516 Spline a() {
517 return this;
518 }
519 Line b() {
520 return null;
521 }
522 Spline f() {
523 Line x = new Line();
524 x.j..!1;
525 }
526 }
527 class Line {
528 Spline j;
529 Line g() {
530 return this;
531 }
532 Spline h() {
533 return null;
534 }
535 }''', <String>["1+b"]);
536
537 CompletionTestCase.buildTests('testCommentSnippets072', '''
538 class X {
539 int _p;
540 set p(int x) => _p = x;
541 }
542 f() {
543 X x = new X();
544 x.!1p = 3;
545 }''', <String>["1+p"]);
546
547 CompletionTestCase.buildTests('testCommentSnippets073', '''
548 class X {
549 m() {
550 JSON.stri!1;
551 X f = null;
552 }
553 }
554 class JSON {
555 static stringify() {}
556 }''', <String>["1+stringify"]);
557
558 CompletionTestCase.buildTests('testCommentSnippets074', '''
559 class X {
560 m() {
561 _x!1
562 }
563 _x1(){}
564 }''', <String>["1+_x1"]);
565
566 CompletionTestCase.buildTests('testCommentSnippets075', '''
567 p(x)=>0;var E;f(q)=>!1p(!2E);''', <String>["1+p", "2+E"]);
568
569 CompletionTestCase.buildTests('testCommentSnippets076', '''
570 class Map<K,V>{}class List<E>{}class int{}main() {var m=new Map<Lis!1t<Map<int,i n!2t>>,List<!3int>>();}''',
571 <String>["1+List", "2+int", "3+int"]);
572
573 CompletionTestCase.buildTests('testCommentSnippets076a', '''
574 class Map<K,V>{}class List<E>{}class int{}main() {var m=new Map<Lis!1t<Map<int,i n!2t>>,List<!3>>();}''',
575 <String>["1+List", "2+int", "3+int"]);
576
577 CompletionTestCase.buildTests('testCommentSnippets077', '''
578 class FileMode {
579 static const READ = const FileMode._internal(0);
580 static const WRITE = const FileMode._internal(1);
581 static const APPEND = const FileMode._internal(2);
582 const FileMode._internal(int this._mode);
583 factory FileMode._internal1(int this._mode);
584 factory FileMode(_mode);
585 final int _mode;
586 }
587 class File {
588 factory File(String path) => null;
589 factory File.fromPath(Path path) => null;
590 }
591 f() => new Fil!1''',
592 <String>[
593 "1+File",
594 "1+File.fromPath",
595 "1+FileMode",
596 "1+FileMode._internal1",
597 "1+FileMode._internal"]);
598
599 CompletionTestCase.buildTests('testCommentSnippets078', '''
600 class Map{static from()=>null;clear(){}}void main() { Map.!1 }''',
601 <String>["1+from", "1-clear"]); // static method, instance method
602
603 CompletionTestCase.buildTests('testCommentSnippets079', '''
604 class Map{static from()=>null;clear(){}}void main() { Map s; s.!1 }''',
605 <String>["1-from", "1+clear"]); // static method, instance method
606
607 CompletionTestCase.buildTests('testCommentSnippets080', '''
608 class RuntimeError{var message;}void main() { RuntimeError.!1 }''',
609 <String>["1-message"]); // field
610
611 CompletionTestCase.buildTests('testCommentSnippets081', '''
612 class Foo {this.!1}''', <String>["1-Object"]);
613
614 CompletionTestCase.buildTests('testCommentSnippets082', '''
615 class HttpRequest {}
616 class HttpResponse {}
617 main() {
618 var v = (HttpRequest req, HttpResp!1)
619 }''', <String>["1+HttpResponse"]);
620
621 CompletionTestCase.buildTests('testCommentSnippets083', '''
622 main() {(.!1)}''', <String>["1-toString"]);
623
624 CompletionTestCase.buildTests('testCommentSnippets083a', '''
625 main() { .!1 }''', <String>["1-toString"]);
626
627 CompletionTestCase.buildTests('testCommentSnippets083b', '''
628 main() { null.!1 }''', <String>["1+toString"]);
629
630 CompletionTestCase.buildTests('testCommentSnippets084', '''
631 class List{}class Map{}typedef X = !1Lis!2t with !3Ma!4p;''',
632 <String>["1+Map", "2+List", "2-Map", "3+List", "4+Map", "4-List"]);
633
634 CompletionTestCase.buildTests('testCommentSnippets085', '''
635 class List{}class Map{}class Z extends List with !1Ma!2p {}''',
636 <String>["1+List", "1+Map", "2+Map", "2-List"]);
637
638 CompletionTestCase.buildTests('testCommentSnippets086', '''
639 class Q{f(){xy() {!2};x!1y();}}''', <String>["1+xy", "2+f", "2-xy"]);
640
641 CompletionTestCase.buildTests('testCommentSnippets087', '''
642 class Map{}class Q extends Object with !1Map {}''',
643 <String>["1+Map", "1-HashMap"]);
644
645 CompletionTestCase.buildTests('testCommentSnippets088', '''
646 class A {
647 int f;
648 B m(){}
649 }
650 class B extends A {
651 num f;
652 A m(){}
653 }
654 class Z {
655 B q;
656 f() {q.!1}
657 }''', <String>["1+f", "1+m"]); // f->num, m()->A
658
659 CompletionTestCase.buildTests('testCommentSnippets089', '''
660 class Q {
661 fqe() {
662 xya() {
663 xyb() {
664 !1
665 }
666 !3 xyb();
667 };
668 xza() {
669 !2
670 }
671 xya();
672 !4 xza();
673 }
674 fqi() {
675 !5
676 }
677 }''',
678 <String>[
679 "1+fqe",
680 "1+fqi",
681 "1+Q",
682 "1-xya",
683 "1-xyb",
684 "1-xza",
685 "2+fqe",
686 "2+fqi",
687 "2+Q",
688 "2-xya",
689 "2-xyb",
690 "2-xza",
691 "3+fqe",
692 "3+fqi",
693 "3+Q",
694 "3-xya",
695 "3+xyb",
696 "3-xza",
697 "4+fqe",
698 "4+fqi",
699 "4+Q",
700 "4+xya",
701 "4-xyb",
702 "4+xza",
703 "5+fqe",
704 "5+fqi",
705 "5+Q",
706 "5-xya",
707 "5-xyb",
708 "5-xza"]);
709
710 CompletionTestCase.buildTests('testCommentSnippets090', '''
711 class X { f() { var a = 'x'; a.!1 }}''', <String>["1+length"]);
712 }
713
714 void buildCompletionTests() {
715 CompletionTestCase.buildTests('testCompletion_alias_field', '''
716 typedef int fnint(int k); fn!1int x;''', <String>["1+fnint"]);
717
718 CompletionTestCase.buildTests('testCompletion_annotation_argumentList', '''
719 class AAA {",
720 const AAA({int aaa, int bbb});",
721 }",
722 ",
723 @AAA(!1)
724 main() {
725 }''', <String>["1+AAA" /*":" + ProposalKind.ARGUMENT_LIST*/, "1+aaa", "1+bbb"]);
726
727 CompletionTestCase.buildTests('testCompletion_annotation_topLevelVar', '''
728 const fooConst = null;
729 final fooNotConst = null;
730 const bar = null;
731
732 @foo!1
733 main() {
734 }''', <String>["1+fooConst", "1-fooNotConst", "1-bar"]);
735
736 CompletionTestCase.buildTests('testCompletion_annotation_type', '''
737 class AAA {
738 const AAA({int a, int b});
739 const AAA.nnn(int c, int d);
740 }
741 @AAA!1
742 main() {
743 }''',
744 <String>[
745 "1+AAA" /*":" + ProposalKind.CONSTRUCTOR*/,
746 "1+AAA.nnn" /*":" + ProposalKind.CONSTRUCTOR*/]);
747
748 CompletionTestCase.buildTests(
749 'testCompletion_annotation_type_inClass_withoutMember',
750 '''
751 class AAA {
752 const AAA();
753 }
754
755 class C {
756 @A!1
757 }''', <String>["1+AAA" /*":" + ProposalKind.CONSTRUCTOR*/]);
758
759 CompletionTestCase.buildTests('testCompletion_argument_typeName', '''
760 class Enum {
761 static Enum FOO = new Enum();
762 }
763 f(Enum e) {}
764 main() {
765 f(En!1);
766 }''', <String>["1+Enum"]);
767
768 CompletionTestCase.buildTests('testCompletion_arguments_ignoreEmpty', '''
769 class A {
770 test() {}
771 }
772 main(A a) {
773 a.test(!1);
774 }''', <String>["1-test"]);
775
776 CompletionTestCase.buildTests('testCompletion_as_asIdentifierPrefix', '''
777 main(p) {
778 var asVisible;
779 var v = as!1;
780 }''', <String>["1+asVisible"]);
781
782 CompletionTestCase.buildTests(
783 'testCompletion_as_asPrefixedIdentifierStart',
784 '''
785 class A {
786 var asVisible;
787 }
788
789 main(A p) {
790 var v = p.as!1;
791 }''', <String>["1+asVisible"]);
792
793 CompletionTestCase.buildTests('testCompletion_as_incompleteStatement', '''
794 class MyClass {}
795 main(p) {
796 var justSomeVar;
797 var v = p as !1
798 }''', <String>["1+MyClass", "1-justSomeVar"]);
799
800 CompletionTestCase.buildTests('testCompletion_cascade', '''
801 class A {
802 aaa() {}
803 }
804
805
806 main(A a) {
807 a..!1 aaa();
808 }''', <String>["1+aaa", "1-main"]);
809
810 CompletionTestCase.buildTests('testCompletion_combinator_afterComma', '''
811 "import 'dart:math' show cos, !1;''',
812 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
813
814 CompletionTestCase.buildTests('testCompletion_combinator_ended', '''
815 import 'dart:math' show !1;"''',
816 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
817
818 CompletionTestCase.buildTests('testCompletion_combinator_export', '''
819 export 'dart:math' show !1;"''',
820 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
821
822 CompletionTestCase.buildTests('testCompletion_combinator_hide', '''
823 import 'dart:math' hide !1;"''',
824 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
825
826 CompletionTestCase.buildTests('testCompletion_combinator_notEnded', '''
827 import 'dart:math' show !1"''',
828 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
829
830 CompletionTestCase.buildTests('testCompletion_combinator_usePrefix', '''
831 import 'dart:math' show s!1"''',
832 <String>["1+sin", "1+sqrt", "1-cos", "1-String"]);
833
834 CompletionTestCase.buildTests('testCompletion_constructor_field', '''
835 class X { X(this.field); int f!1ield;}''', <String>["1+field"]);
836
837 CompletionTestCase.buildTests(
838 'testCompletion_constructorArguments_showOnlyCurrent',
839 '''
840 class A {
841 A.first(int p);
842 A.second(double p);
843 }
844 main() {
845 new A.first(!1);
846 }''', <String>["1+A.first", "1-A.second"]);
847
848 CompletionTestCase.buildTests(
849 'testCompletion_constructorArguments_whenPrefixedType',
850 '''
851 import 'dart:math' as m;
852 main() {
853 new m.Random(!1);
854 }''', <String>["1+Random:ARGUMENT_LIST"]);
855
856 CompletionTestCase.buildTests(
857 'testCompletion_dartDoc_reference_forClass',
858 '''
859 /**
860 * [int!1]
861 * [method!2]
862 */
863 class AAA {
864 methodA() {}
865 }''', <String>["1+int", "1-method", "2+methodA", "2-int"]);
866
867 CompletionTestCase.buildTests(
868 'testCompletion_dartDoc_reference_forConstructor',
869 '''
870 class A {
871 /**
872 * [aa!1]
873 * [int!2]
874 * [method!3]
875 */
876 A.named(aaa, bbb) {}
877 methodA() {}
878 }''', <String>["1+aaa", "1-bbb", "2+int", "2-double", "3+methodA"]);
879
880 CompletionTestCase.buildTests(
881 'testCompletion_dartDoc_reference_forFunction',
882 '''
883 /**
884 * [aa!1]
885 * [int!2]
886 * [function!3]
887 */
888 functionA(aaa, bbb) {}
889 functionB() {}''',
890 <String>[
891 "1+aaa",
892 "1-bbb",
893 "2+int",
894 "2-double",
895 "3+functionA",
896 "3+functionB",
897 "3-int"]);
898
899 CompletionTestCase.buildTests(
900 'testCompletion_dartDoc_reference_forFunctionTypeAlias',
901 '''
902 /**
903 * [aa!1]
904 * [int!2]
905 * [Function!3]
906 */
907 typedef FunctionA(aaa, bbb) {}
908 typedef FunctionB() {}''',
909 <String>[
910 "1+aaa",
911 "1-bbb",
912 "2+int",
913 "2-double",
914 "3+FunctionA",
915 "3+FunctionB",
916 "3-int"]);
917
918 CompletionTestCase.buildTests(
919 'testCompletion_dartDoc_reference_forMethod',
920 '''
921 class A {
922 /**
923 * [aa!1]
924 * [int!2]
925 * [method!3]
926 */
927 methodA(aaa, bbb) {}
928 methodB() {}
929 }''',
930 <String>[
931 "1+aaa",
932 "1-bbb",
933 "2+int",
934 "2-double",
935 "3+methodA",
936 "3+methodB",
937 "3-int"]);
938
939 CompletionTestCase.buildTests(
940 'testCompletion_dartDoc_reference_incomplete',
941 '''
942 /**
943 * [doubl!1 some text
944 * other text
945 */
946 class A {}
947 /**
948 * [!2 some text
949 * other text
950 */
951 class B {}
952 /**
953 * [!3] some text
954 */
955 class C {}''',
956 <String>["1+double", "1-int", "2+int", "2+String", "3+int", "3+String"]) ;
957
958 CompletionTestCase.buildTests('testCompletion_double_inFractionPart', '''
959 main() {
960 1.0!1
961 }''', <String>["1-abs", "1-main"]);
962
963 CompletionTestCase.buildTests('testCompletion_enum', '''
964 enum MyEnum {A, B, C}
965 main() {
966 MyEnum.!1;
967 }''', <String>["1+values", "1+A", "1+B", "1+C"]);
968
969 CompletionTestCase.buildTests(
970 'testCompletion_exactPrefix_hasHigherRelevance',
971 '''
972 var STR;
973 main(p) {
974 var str;
975 str!1;
976 STR!2;
977 Str!3;
978 }''',
979 <String>[
980 "1+str" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 1)*/,
981 "1+STR" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 0)*/,
982 "2+STR" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 1)*/,
983 "2+str" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 0)*/,
984 "3+String" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 1)*/,
985 "3+STR" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 0)*/,
986 "3+str" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 0)*/]);
987
988 CompletionTestCase.buildTests('testCompletion_export_dart', '''
989 import 'dart:math
990 import 'dart:_chrome
991 import 'dart:_collection.dev
992 export 'dart:!1''',
993 <String>[
994 "1+dart:core",
995 "1+dart:math",
996 "1-dart:_chrome",
997 "1-dart:_collection.dev"]);
998
999 CompletionTestCase.buildTests(
1000 'testCompletion_export_noStringLiteral_noSemicolon',
1001 '''
1002 import !1
1003
1004 class A {}''', <String>["1+'dart:!';", "1+'package:!';"]);
1005
1006 CompletionTestCase.buildTests('testCompletion_forStmt_vars', '''
1007 class int{}class Foo { mth() { for (in!1t i = 0; i!2 < 5; i!3++); }}''',
1008 <String>["1+int", "2+i", "3+i"]);
1009
1010 CompletionTestCase.buildTests('testCompletion_function', '''
1011 class String{}class Foo { int boo = 7; mth() { PNGS.sort((String a, Str!1) => a. compareTo(b)); }}''',
1012 <String>["1+String"]);
1013
1014 CompletionTestCase.buildTests('testCompletion_function_partial', '''
1015 class String{}class Foo { int boo = 7; mth() { PNGS.sort((String a, Str!1)); }}' '',
1016 <String>["1+String"]);
1017
1018 CompletionTestCase.buildTests(
1019 'testCompletion_functionTypeParameter_namedArgument',
1020 '''
1021 typedef FFF(a, b, {x1, x2, y});
1022 main(FFF fff) {
1023 fff(1, 2, !1)!2;
1024 }''', <String>["1+x1", "2-x2"]);
1025
1026 CompletionTestCase.buildTests('testCompletion_ifStmt_field1', '''
1027 class Foo { int myField = 7; mth() { if (!1) {}}}''', <String>["1+myField"]);
1028
1029 CompletionTestCase.buildTests('testCompletion_ifStmt_field1a', '''
1030 class Foo { int myField = 7; mth() { if (!1) }}''', <String>["1+myField"]);
1031
1032 CompletionTestCase.buildTests('testCompletion_ifStmt_field2', '''
1033 class Foo { int myField = 7; mth() { if (m!1) {}}}''', <String>["1+myField"]);
1034
1035 CompletionTestCase.buildTests('testCompletion_ifStmt_field2a', '''
1036 class Foo { int myField = 7; mth() { if (m!1) }}''', <String>["1+myField"]);
1037
1038 CompletionTestCase.buildTests('testCompletion_ifStmt_field2b', '''
1039 class Foo { myField = 7; mth() { if (m!1) {}}}''', <String>["1+myField"]);
1040
1041 CompletionTestCase.buildTests('testCompletion_ifStmt_localVar', '''
1042 class Foo { mth() { int value = 7; if (v!1) {}}}''', <String>["1+value"]);
1043
1044 CompletionTestCase.buildTests('testCompletion_ifStmt_localVara', '''
1045 class Foo { mth() { value = 7; if (v!1) {}}}''', <String>["1-value"]);
1046
1047 CompletionTestCase.buildTests('testCompletion_ifStmt_topLevelVar', '''
1048 int topValue = 7; class Foo { mth() { if (t!1) {}}}''', <String>["1+topValue"]);
1049
1050 CompletionTestCase.buildTests('testCompletion_ifStmt_topLevelVara', '''
1051 topValue = 7; class Foo { mth() { if (t!1) {}}}''', <String>["1+topValue"]);
1052
1053 CompletionTestCase.buildTests(
1054 'testCompletion_ifStmt_unionType_nonStrict',
1055 '''
1056 class A { a() => null; x() => null}
1057 class B { a() => null; y() => null}
1058 void main() {
1059 var x;
1060 var c;
1061 if(c) {
1062 x = new A();
1063 } else {
1064 x = new B();
1065 }
1066 x.!1;
1067 }''', <String>["1+a", "1+x", "1+y"]);
1068
1069 CompletionTestCase.buildTests('testCompletion_ifStmt_unionType_strict', '''
1070 class A { a() => null; x() => null}
1071 class B { a() => null; y() => null}
1072 void main() {
1073 var x;
1074 var c;
1075 if(c) {
1076 x = new A();
1077 } else {
1078 x = new B();
1079 }
1080 x.!1;
1081 }''', <String>["1+a", "1-x", "1-y"]);
1082
1083 CompletionTestCase.buildTests('testCompletion_import', '''
1084 import '!1';''', <String>["1+dart:!", "1+package:!"]);
1085
1086 CompletionTestCase.buildTests('testCompletion_import_dart', '''
1087 import 'dart:math
1088 import 'dart:_chrome
1089 import 'dart:_collection.dev
1090 import 'dart:!1''',
1091 <String>[
1092 "1+dart:core",
1093 "1+dart:math",
1094 "1-dart:_chrome",
1095 "1-dart:_collection.dev"]);
1096
1097 CompletionTestCase.buildTests(
1098 'testCompletion_import_hasStringLiteral_noSemicolon',
1099 '''
1100 import '!1'
1101
1102 class A {}''', <String>["1+dart:!", "1+package:!"]);
1103
1104 CompletionTestCase.buildTests('testCompletion_import_noSpace', '''
1105 import!1''', <String>["1+ 'dart:!';", "1+ 'package:!';"]);
1106
1107 CompletionTestCase.buildTests('testCompletion_import_noStringLiteral', '''
1108 import !1;''', <String>["1+'dart:!'", "1+'package:!'"]);
1109
1110 CompletionTestCase.buildTests(
1111 'testCompletion_import_noStringLiteral_noSemicolon',
1112 '''
1113 import !1
1114
1115 class A {}''', <String>["1+'dart:!';", "1+'package:!';"]);
1116
1117 CompletionTestCase.buildTests('testCompletion_incompleteClassMember', '''
1118 class A {
1119 Str!1
1120 final f = null;
1121 }''', <String>["1+String", "1-bool"]);
1122
1123 CompletionTestCase.buildTests(
1124 'testCompletion_incompleteClosure_parameterType',
1125 '''
1126 f1(cb(String s)) {}
1127 f2(String s) {}
1128 main() {
1129 f1((Str!1));
1130 f2((Str!2));
1131 }''', <String>["1+String", "1-bool", "2+String", "2-bool"]);
1132
1133 CompletionTestCase.buildTests('testCompletion_inPeriodPeriod', '''
1134 main(String str) {
1135 1 < str.!1.length;
1136 1 + str.!2.length;
1137 1 + 2 * str.!3.length;
1138 }''', <String>["1+codeUnits", "2+codeUnits", "3+codeUnits"]);
1139
1140 // no checks, but no exceptions
1141 CompletionTestCase.buildTests(
1142 'testCompletion_instanceCreation_unresolved',
1143 '''
1144 class A {
1145 }
1146 main() {
1147 new NoSuchClass(!1);
1148 new A.noSuchConstructor(!2);
1149 }''', <String>["1+int", "2+int"]);
1150
1151 CompletionTestCase.buildTests('testCompletion_import_lib', '''
1152 import '!1''', <String>["1+my_lib.dart"], <String, String>{
1153 "/my_lib.dart": ""
1154 });
1155
1156 CompletionTestCase.buildTests('testCompletion_is', '''
1157 class MyClass {}
1158 main(p) {
1159 var isVariable;
1160 if (p is MyCla!1) {}
1161 var v1 = p is MyCla!2;
1162 var v2 = p is !3;
1163 var v2 = p is!4;
1164 }''',
1165 <String>[
1166 "1+MyClass",
1167 "2+MyClass",
1168 "3+MyClass",
1169 "3-v1",
1170 "4+is",
1171 "4-isVariable"]);
1172
1173 CompletionTestCase.buildTests('testCompletion_is_asIdentifierStart', '''
1174 main(p) {
1175 var isVisible;
1176 var v1 = is!1;
1177 var v2 = is!2
1178 }''', <String>["1+isVisible", "2+isVisible"]);
1179
1180 CompletionTestCase.buildTests(
1181 'testCompletion_is_asPrefixedIdentifierStart',
1182 '''
1183 class A {
1184 var isVisible;
1185 }
1186
1187 main(A p) {
1188 var v1 = p.is!1;
1189 var v2 = p.is!2
1190 }''', <String>["1+isVisible", "2+isVisible"]);
1191
1192 CompletionTestCase.buildTests('testCompletion_is_incompleteStatement1', '''
1193 class MyClass {}
1194 main(p) {
1195 var justSomeVar;
1196 var v = p is !1
1197 }''', <String>["1+MyClass", "1-justSomeVar"]);
1198
1199 CompletionTestCase.buildTests('testCompletion_is_incompleteStatement2', '''
1200 class MyClass {}
1201 main(p) {
1202 var isVariable;
1203 var v = p is!1
1204 }''', <String>["1+is", "1-isVariable"]);
1205
1206 CompletionTestCase.buildTests('testCompletion_keyword_in', '''
1207 class Foo { int input = 7; mth() { if (in!1) {}}}''', <String>["1+input"]);
1208
1209 CompletionTestCase.buildTests(
1210 'testCompletion_keyword_syntheticIdentifier',
1211 '''
1212 main() {
1213 var caseVar;
1214 var otherVar;
1215 var v = case!1
1216 }''', <String>["1+caseVar", "1-otherVar"]);
1217
1218 CompletionTestCase.buildTests('testCompletion_libraryIdentifier_atEOF', '''
1219 library int.!1''', <String>["1-parse", "1-bool"]);
1220
1221 CompletionTestCase.buildTests('testCompletion_libraryIdentifier_notEOF', '''
1222 library int.!1''', <String>["1-parse", "1-bool"]);
1223
1224 CompletionTestCase.buildTests(
1225 'testCompletion_methodRef_asArg_incompatibleFunctionType',
1226 '''
1227 foo( f(int p) ) {}
1228 class Functions {
1229 static myFuncInt(int p) {}
1230 static myFuncDouble(double p) {}
1231 }
1232 bar(p) {}
1233 main(p) {
1234 foo( Functions.!1; );
1235 }''',
1236 <String>[
1237 "1+myFuncInt" /*":" + ProposalKind.METHOD_NAME*/,
1238 "1-myFuncDouble" /*":" + ProposalKind.METHOD_NAME*/]);
1239
1240 CompletionTestCase.buildTests(
1241 'testCompletion_methodRef_asArg_notFunctionType',
1242 '''
1243 foo( f(int p) ) {}
1244 class Functions {
1245 static myFunc(int p) {}
1246 }
1247 bar(p) {}
1248 main(p) {
1249 foo( (int p) => Functions.!1; );
1250 }''',
1251 <String>[
1252 "1+myFunc" /*":" + ProposalKind.METHOD*/,
1253 "1-myFunc" /*":" + ProposalKind.METHOD_NAME*/]);
1254
1255 CompletionTestCase.buildTests(
1256 'testCompletion_methodRef_asArg_ofFunctionType',
1257 '''
1258 foo( f(int p) ) {}
1259 class Functions {
1260 static int myFunc(int p) {}
1261 }
1262 main(p) {
1263 foo(Functions.!1);
1264 }''',
1265 <String>[
1266 "1+myFunc" /*":" + ProposalKind.METHOD*/,
1267 "1+myFunc" /*":" + ProposalKind.METHOD_NAME*/]);
1268
1269 CompletionTestCase.buildTests(
1270 'testCompletion_namedArgument_alreadyUsed',
1271 '''
1272 func({foo}) {} main() { func(foo: 0, fo!1); }''', <String>["1-foo"]);
1273
1274 CompletionTestCase.buildTests(
1275 'testCompletion_namedArgument_constructor',
1276 '''
1277 class A {A({foo, bar}) {}} main() { new A(fo!1); }''',
1278 <String>["1+foo", "1-bar"]);
1279
1280 CompletionTestCase.buildTests('testCompletion_namedArgument_empty', '''
1281 func({foo, bar}) {} main() { func(!1); }''',
1282 <String>[
1283 "1+foo" /*":" + ProposalKind.NAMED_ARGUMENT*/,
1284 "1-foo" /*":" + ProposalKind.OPTIONAL_ARGUMENT*/]);
1285
1286 CompletionTestCase.buildTests('testCompletion_namedArgument_function', '''
1287 func({foo, bar}) {} main() { func(fo!1); }''', <String>["1+foo", "1-bar"]);
1288
1289 CompletionTestCase.buildTests('testCompletion_namedArgument_notNamed', '''
1290 func([foo]) {} main() { func(fo!1); }''', <String>["1-foo"]);
1291
1292 CompletionTestCase.buildTests(
1293 'testCompletion_namedArgument_unresolvedFunction',
1294 '''
1295 main() { func(fo!1); }''', <String>["1-foo"]);
1296
1297 CompletionTestCase.buildTests('testCompletion_newMemberType1', '''
1298 class Collection{}class List extends Collection{}class Foo { !1 }''',
1299 <String>["1+Collection", "1+List"]);
1300
1301 CompletionTestCase.buildTests('testCompletion_newMemberType2', '''
1302 class Collection{}class List extends Collection{}class Foo {!1}''',
1303 <String>["1+Collection", "1+List"]);
1304
1305 CompletionTestCase.buildTests('testCompletion_newMemberType3', '''
1306 class Collection{}class List extends Collection{}class Foo {L!1}''',
1307 <String>["1-Collection", "1+List"]);
1308
1309 CompletionTestCase.buildTests('testCompletion_newMemberType4', '''
1310 class Collection{}class List extends Collection{}class Foo {C!1}''',
1311 <String>["1+Collection", "1-List"]);
1312
1313 CompletionTestCase.buildTests(
1314 'testCompletion_positionalArgument_constructor',
1315 '''
1316 class A {
1317 A([foo, bar]);
1318 }
1319 main() {
1320 new A(!1);
1321 new A(0, !2);
1322 }''',
1323 <String>[
1324 "1+foo" /*":" + ProposalKind.OPTIONAL_ARGUMENT*/,
1325 "1-bar",
1326 "2-foo",
1327 "2+bar" /*":"
1328 + ProposalKind.OPTIONAL_ARGUMENT*/]);
1329
1330 CompletionTestCase.buildTests(
1331 'testCompletion_positionalArgument_function',
1332 '''
1333 func([foo, bar]) {}
1334 main() {
1335 func(!1);
1336 func(0, !2);
1337 }''',
1338 <String>[
1339 "1+foo" /*":" + ProposalKind.OPTIONAL_ARGUMENT*/,
1340 "1-bar",
1341 "2-foo",
1342 "2+bar" /*":"
1343 + ProposalKind.OPTIONAL_ARGUMENT*/]);
1344
1345 CompletionTestCase.buildTests('testCompletion_preferStaticType', '''
1346 class A {
1347 foo() {}
1348 }
1349 class B extends A {
1350 bar() {}
1351 }
1352 main() {
1353 A v = new B();
1354 v.!1
1355 }''',
1356 <String>[
1357 "1+foo",
1358 "1-bar,potential=false,declaringType=B",
1359 "1+bar,potential=true,declaringType=B"]);
1360
1361 CompletionTestCase.buildTests(
1362 'testCompletion_privateElement_sameLibrary_constructor',
1363 '''
1364 class A {
1365 A._c();
1366 A.c();
1367 }
1368 main() {
1369 new A.!1
1370 }''', <String>["1+_c", "1+c"]);
1371
1372 CompletionTestCase.buildTests(
1373 'testCompletion_privateElement_sameLibrary_member',
1374 '''
1375 class A {
1376 _m() {}
1377 m() {}
1378 }
1379 main(A a) {
1380 a.!1
1381 }''', <String>["1+_m", "1+m"]);
1382
1383 CompletionTestCase.buildTests(
1384 'testCompletion_propertyAccess_whenClassTarget',
1385 '''
1386 class A {
1387 static int FIELD;
1388 int field;
1389 }
1390 main() {
1391 A.!1
1392 }''', <String>["1+FIELD", "1-field"]);
1393
1394 CompletionTestCase.buildTests(
1395 'testCompletion_propertyAccess_whenClassTarget_excludeSuper',
1396 '''
1397 class A {
1398 static int FIELD_A;
1399 static int methodA() {}
1400 }
1401 class B extends A {
1402 static int FIELD_B;
1403 static int methodB() {}
1404 }
1405 main() {
1406 B.!1;
1407 }''', <String>["1+FIELD_B", "1-FIELD_A", "1+methodB", "1-methodA"]);
1408
1409 CompletionTestCase.buildTests(
1410 'testCompletion_propertyAccess_whenInstanceTarget',
1411 '''
1412 class A {
1413 static int FIELD;
1414 int fieldA;
1415 }
1416 class B {
1417 A a;
1418 }
1419 class C extends A {
1420 int fieldC;
1421 }
1422 main(B b, C c) {
1423 b.a.!1;
1424 c.!2;
1425 }''', <String>["1-FIELD", "1+fieldA", "2+fieldC", "2+fieldA"]);
1426
1427 CompletionTestCase.buildTests(
1428 'testCompletion_return_withIdentifierPrefix',
1429 '''
1430 f() { var vvv = 42; return v!1 }''', <String>["1+vvv"]);
1431
1432 CompletionTestCase.buildTests('testCompletion_return_withoutExpression', '''
1433 f() { var vvv = 42; return !1 }''', <String>["1+vvv"]);
1434
1435 CompletionTestCase.buildTests('testCompletion_staticField1', '''
1436 class num{}class Sunflower {static final n!2um MAX_D = 300;nu!3m xc, yc;Sun!4flo wer() {x!Xc = y!Yc = MA!1 }}''',
1437 <String>["1+MAX_D", "X+xc", "Y+yc", "2+num", "3+num", "4+Sunflower"]);
1438
1439 CompletionTestCase.buildTests('testCompletion_super_superType', '''
1440 class A {
1441 var fa;
1442 ma() {}
1443 }
1444 class B extends A {
1445 var fb;
1446 mb() {}
1447 main() {
1448 super.!1
1449 }
1450 }''', <String>["1+fa", "1-fb", "1+ma", "1-mb"]);
1451
1452 CompletionTestCase.buildTests(
1453 'testCompletion_superConstructorInvocation_noNamePrefix',
1454 '''
1455 class A {
1456 A.fooA();
1457 A.fooB();
1458 A.bar();
1459 }
1460 class B extends A {
1461 B() : super.!1
1462 }''', <String>["1+fooA", "1+fooB", "1+bar"]);
1463
1464 CompletionTestCase.buildTests(
1465 'testCompletion_superConstructorInvocation_withNamePrefix',
1466 '''
1467 class A {
1468 A.fooA();
1469 A.fooB();
1470 A.bar();
1471 }
1472 class B extends A {
1473 B() : super.f!1
1474 }''', <String>["1+fooA", "1+fooB", "1-bar"]);
1475
1476 CompletionTestCase.buildTests(
1477 'testCompletion_this_bad_inConstructorInitializer',
1478 '''
1479 class A {
1480 var f;
1481 A() : f = this.!1;
1482 }''', <String>["1-toString"]);
1483
1484 CompletionTestCase.buildTests(
1485 'testCompletion_this_bad_inFieldDeclaration',
1486 '''
1487 class A {
1488 var f = this.!1;
1489 }''', <String>["1-toString"]);
1490
1491 CompletionTestCase.buildTests('testCompletion_this_bad_inStaticMethod', '''
1492 class A {
1493 static m() {
1494 this.!1;
1495 }
1496 }''', <String>["1-toString"]);
1497
1498 CompletionTestCase.buildTests(
1499 'testCompletion_this_bad_inTopLevelFunction',
1500 '''
1501 main() {
1502 this.!1;
1503 }''', <String>["1-toString"]);
1504
1505 CompletionTestCase.buildTests(
1506 'testCompletion_this_bad_inTopLevelVariableDeclaration',
1507 '''
1508 var v = this.!1;''', <String>["1-toString"]);
1509
1510 CompletionTestCase.buildTests(
1511 'testCompletion_this_OK_inConstructorBody',
1512 '''
1513 class A {
1514 var f;
1515 m() {}
1516 A() {
1517 this.!1;
1518 }
1519 }''', <String>["1+f", "1+m"]);
1520
1521 CompletionTestCase.buildTests('testCompletion_this_OK_localAndSuper', '''
1522 class A {
1523 var fa;
1524 ma() {}
1525 }
1526 class B extends A {
1527 var fb;
1528 mb() {}
1529 main() {
1530 this.!1
1531 }
1532 }''', <String>["1+fa", "1+fb", "1+ma", "1+mb"]);
1533
1534 CompletionTestCase.buildTests('testCompletion_topLevelField_init2', '''
1535 class DateTime{static var JUN;}final num M = Dat!1eTime.JUN;''',
1536 <String>["1+DateTime", "1-void"]);
1537
1538 CompletionTestCase.buildTests('testCompletion_while', '''
1539 class Foo { int boo = 7; mth() { while (b!1) {} }}''', <String>["1+boo"]);
1540 }
1541
1542 void buildLibraryTests() {
1543 Map<String, String> sources = new HashMap<String, String>();
1544
1545 CompletionTestCase.buildTests('test_export_ignoreIfThisLibraryExports', '''
1546 export 'dart:math';
1547 libFunction() {};
1548 main() {
1549 !1
1550 }''', <String>["1-cos", "1+libFunction"]);
1551
1552 sources.clear();
1553 sources["/lib.dart"] = '''
1554 library lib;
1555 export 'dart:math' hide sin;
1556 libFunction() {};''';
1557 CompletionTestCase.buildTests(
1558 'test_export_showIfImportLibraryWithExport',
1559 '''
1560 import 'lib.dart' as p;
1561 main() {
1562 p.!1
1563 }''', <String>["1+cos", "1-sin", "1+libFunction"], sources);
1564
1565 CompletionTestCase.buildTests('test_importPrefix_hideCombinator', '''
1566 import 'dart:math' as math hide PI;
1567 main() {
1568 math.!1
1569 }''', <String>["1-PI", "1+LN10"]);
1570
1571 CompletionTestCase.buildTests('test_importPrefix_showCombinator', '''
1572 import 'dart:math' as math show PI;
1573 main() {
1574 math.!1
1575 }''', <String>["1+PI", "1-LN10"]);
1576
1577 sources.clear();
1578 sources["/lib.dart"] = '''
1579 library lib
1580 class _A
1581 foo() {}
1582
1583 class A extends _A {
1584 }''';
1585 CompletionTestCase.buildTests('test_memberOfPrivateClass_otherLibrary', '''
1586 import 'lib.dart';
1587 main(A a) {
1588 a.!1
1589 }''', <String>["1+foo"], sources);
1590
1591 sources.clear();
1592 sources["/lib.dart"] = '''
1593 library lib;
1594 class A {
1595 A.c();
1596 A._c();
1597 }''';
1598 CompletionTestCase.buildTests(
1599 'test_noPrivateElement_otherLibrary_constructor',
1600 '''
1601 import 'lib.dart';
1602 main() {
1603 new A.!1
1604 }''', <String>["1-_c", "1+c"]);
1605
1606 sources.clear();
1607 sources["/lib.dart"] = '''
1608 library lib;
1609 class A {
1610 var f;
1611 var _f;
1612 }''';
1613 CompletionTestCase.buildTests(
1614 'test_noPrivateElement_otherLibrary_member',
1615 '''
1616 import 'lib.dart';
1617 main(A a) {
1618 a.!1
1619 }''', <String>["1-_f", "1+f"], sources);
1620
1621 sources.clear();
1622 sources["/firth.dart"] = '''
1623 library firth;
1624 class SerializationException {
1625 const SerializationException();
1626 }''';
1627 CompletionTestCase.buildTests('test001', '''
1628 import 'firth.dart';
1629 main() {
1630 throw new Seria!1lizationException();}''',
1631 <String>["1+SerializationException"],
1632 sources);
1633
1634 // Type propagation.
1635 // TODO Include corelib analysis (this works in the editor)
1636 CompletionTestCase.buildTests(
1637 'test002',
1638 '''t2() {var q=[0],z=q.!1length;q.!2clear();}''',
1639 <String>["1+length", "1+isEmpty", "2+clear"]);
1640
1641 // TODO Include corelib analysis
1642 CompletionTestCase.buildTests(
1643 'test003',
1644 '''class X{var q; f() {q.!1a!2}}''',
1645 <String>["1+end", "2+abs", "2-end"]);
1646
1647 // TODO Include corelib analysis
1648 // Resolving dart:html takes between 2.5s and 30s; json, about 0.12s
1649 CompletionTestCase.buildTests('test004()', '''
1650 library foo;
1651 import 'dart:convert' as json;
1652 class JsonParserX{}
1653 f1() {var x=new json.!1}
1654 f2() {var x=new json.JsonPa!2}
1655 f3() {var x=new json.JsonParser!3}''',
1656 <String>[
1657 "1+JsonParser",
1658 "1-JsonParserX",
1659 "2+JsonParser",
1660 "2-JsonParserX",
1661 "3+JsonParser",
1662 "3-JsonParserX"]);
1663
1664 // TODO Enable after type propagation is implemented. Not yet.
1665 // TODO Include corelib analysis
1666 CompletionTestCase.buildTests(
1667 'test005',
1668 '''var PHI;main(){PHI=5.3;PHI.abs().!1 Object x;}''',
1669 <String>["1+abs"]);
1670
1671 // Exercise import and export handling.
1672 // Libraries are defined in partial order of increasing dependency.
1673 sources.clear();
1674 sources["/exp2a.dart"] = '''
1675 library exp2a;
1676 e2a() {}''';
1677 sources["/exp1b.dart"] = '''
1678 library exp1b;",
1679 e1b() {}''';
1680 sources["/exp1a.dart"] = '''
1681 library exp1a;",
1682 export 'exp1b.dart';",
1683 e1a() {}''';
1684 sources["/imp1.dart"] = '''
1685 library imp1;
1686 export 'exp1a.dart';
1687 i1() {}''';
1688 sources["/imp2.dart"] = '''
1689 library imp2;
1690 export 'exp2a.dart';
1691 i2() {}''';
1692 CompletionTestCase.buildTests('test007', '''
1693 import 'imp1.dart';
1694 import 'imp2.dart';
1695 main() {!1
1696 i1();
1697 i2();
1698 e1a();
1699 e1b();
1700 e2a();
1701 }''', <String>["1+i1", "1+i2", "1+e1a", "1+e2a", "1+e1b"], sources);
1702
1703 // Exercise import and export handling.
1704 // Libraries are defined in partial order of increasing dependency.
1705 sources.clear();
1706 sources["/l1.dart"] = '''
1707 library l1;
1708 var _l1t; var l1t;''';
1709 CompletionTestCase.buildTests('test007', '''
1710 import 'l1.dart';
1711 main() {
1712 var x = l!1
1713 var y = _!2
1714 }''', <String>["1+l1t", "1-_l1t", "2-_l1t"], sources);
1715
1716 // Check private library exclusion
1717 sources.clear();
1718 sources["/public.dart"] = '''
1719 library public;
1720 class NonPrivate {
1721 void publicMethod() {
1722 }
1723 }''';
1724 sources["/private.dart"] = '''
1725 library _private;
1726 import 'public.dart';
1727 class Private extends NonPrivate {
1728 void privateMethod() {
1729 }
1730 }''';
1731 CompletionTestCase.buildTests('test008', '''
1732 import 'private.dart';
1733 import 'public.dart';
1734 class Test {
1735 void test() {
1736 NonPrivate x = new NonPrivate();
1737 x.!1 //publicMethod but not privateMethod should appear
1738 }
1739 }''', <String>["1-privateMethod", "1+publicMethod"], sources);
1740
1741 // Exercise library prefixes.
1742 sources.clear();
1743 sources["/lib.dart"] = '''
1744 library lib;
1745 int X = 1;
1746 void m(){}
1747 class Y {}''';
1748 CompletionTestCase.buildTests('test009', '''
1749 import 'lib.dart' as Q;
1750 void a() {
1751 var x = Q.!1
1752 }
1753 void b() {
1754 var x = [Q.!2]
1755 }
1756 void c() {
1757 var x = new List([Q.!3])
1758 }
1759 void d() {
1760 new Q.!4
1761 }''',
1762 <String>[
1763 "1+X",
1764 "1+m",
1765 "1+Y",
1766 "2+X",
1767 "2+m",
1768 "2+Y",
1769 "3+X",
1770 "3+m",
1771 "3+Y",
1772 "4+Y",
1773 "4-m",
1774 "4-X"],
1775 sources);
1776 }
1777
1778 void buildNumberedTests() {
1779 CompletionTestCase.buildTests('test001', '''
1780 void r1(var v) {
1781 v.!1toString!2().!3hash!4Code
1782 }''',
1783 <String>[
1784 "1+toString",
1785 "1-==",
1786 "2+toString",
1787 "3+hashCode",
1788 "3+toString",
1789 "4+hashCode",
1790 "4-toString"]);
1791
1792 CompletionTestCase.buildTests('test002', '''
1793 void r2(var vim) {
1794 v!1.toString()
1795 }''', <String>["1+vim"]);
1796
1797 CompletionTestCase.buildTests('test003', '''
1798 class A {
1799 int a() => 3;
1800 int b() => this.!1a();
1801 }''', <String>["1+a"]);
1802
1803 CompletionTestCase.buildTests('test004', '''
1804 class A {
1805 int x;
1806 A() : this.!1x = 1;
1807 A.b() : this();
1808 A.c() : this.!2b();
1809 g() => new A.!3c();
1810 }''', <String>["1+x", "2+b", "3+c"]);
1811
1812 CompletionTestCase.buildTests('test005', '''
1813 class A {}
1814 void rr(var vim) {
1815 var !1vq = v!2.toString();
1816 var vf;
1817 v!3.toString();
1818 }''',
1819 <String>[
1820 "1-A",
1821 "1-vim",
1822 "1+vq",
1823 "1-vf",
1824 "1-this",
1825 "1-void",
1826 "1-null",
1827 "1-false",
1828 "2-A",
1829 "2+vim",
1830 "2-vf",
1831 "2-vq",
1832 "2-this",
1833 "2-void",
1834 "2-null",
1835 "2-false",
1836 "3+vf",
1837 "3+vq",
1838 "3+vim",
1839 "3-A"]);
1840
1841 CompletionTestCase.buildTests('test006', '''
1842 void r2(var vim, {va: 2, b: 3}) {
1843 v!1.toString()
1844 }''', <String>["1+va", "1-b"]);
1845
1846 CompletionTestCase.buildTests('test007', '''
1847 void r2(var vim, [va: 2, b: 3]) {
1848 v!1.toString()
1849 }''', <String>["1+va", "1-b"]);
1850
1851 // keywords
1852 CompletionTestCase.buildTests('test008', '''
1853 !1class Aclass {}
1854 class Bclass !2extends!3 !4Aclass {}
1855 !5typedef Ctype = !6Bclass with !7Aclass;
1856 class Dclass extends !8Ctype {}
1857 !9abstract class Eclass implements Dclass,!C Ctype, Bclass {}
1858 class Fclass extends Bclass !Awith !B Eclass {}''',
1859 <String>[
1860 "1+class",
1861 "1-implements",
1862 "1-extends",
1863 "1-with",
1864 "2+extends",
1865 "3+extends",
1866 "4+Aclass",
1867 "4-Bclass",
1868 "5+typedef",
1869 "6+Bclass",
1870 "6-Ctype",
1871 "7+Aclass",
1872 "7-Bclass",
1873 "8+Ctype",
1874 "9+abstract",
1875 "A+with",
1876 "B+Eclass",
1877 "B-Dclass",
1878 "B-Ctype",
1879 "C+Bclass",
1880 "C-Eclass"]);
1881
1882 // keywords
1883 CompletionTestCase.buildTests('test009', '''
1884 class num{}
1885 typedef !1dy!2namic TestFn1();
1886 typedef !3vo!4id TestFn2();
1887 typ!7edef !5n!6''',
1888 <String>[
1889 "1+void",
1890 "1+TestFn2",
1891 "2+dynamic",
1892 "2-void",
1893 "3+dynamic",
1894 "4+void",
1895 "4-dynamic",
1896 "5+TestFn2",
1897 "6+num",
1898 "7+typedef"]);
1899
1900 CompletionTestCase.buildTests('test010', '''
1901 class String{}class List{}
1902 class test !8<!1t !2 !3extends String,!4 List,!5 !6>!7 {}
1903 class tezetst !9<!BString,!C !DList>!A {}''',
1904 <String>[
1905 "1+String",
1906 "1+List",
1907 "1-test",
1908 "2-String",
1909 "2-test",
1910 "3+extends",
1911 "4+tezetst",
1912 "4-test",
1913 "5+String",
1914 "6+List",
1915 "7-List",
1916 "8-List",
1917 "9-String",
1918 "A-String",
1919 "B+String",
1920 "C+List",
1921 "C-tezetst",
1922 "D+List",
1923 "D+test"]);
1924
1925 // name generation with conflicts
1926 CompletionTestCase.buildTests(
1927 'test011',
1928 '''r2(var object, Object object1, Object !1);''',
1929 <String>["1+object2"]);
1930
1931 // reserved words
1932 CompletionTestCase.buildTests('test012', '''
1933 class X {
1934 f() {
1935 g(!1var!2 z) {!3true.!4toString();};
1936 }
1937 }''',
1938 <String>[
1939 "1+var",
1940 "1+dynamic",
1941 "1-f",
1942 "2+var",
1943 "2-dynamic",
1944 "3+false",
1945 "3+true",
1946 "4+toString"]);
1947
1948 // conditions & operators
1949 CompletionTestCase.buildTests('test013', '''
1950 class Q {
1951 bool x;
1952 List zs;
1953 int k;
1954 var a;
1955 mth() {
1956 while (!1x !9);
1957 do{} while(!2x !8);
1958 for(z in !3zs) {}
1959 switch(!4k) {case 1:{!0}}
1960 try {
1961 } on !5Object catch(a){}
1962 if (!7x !6) {} else {};
1963 }
1964 }''',
1965 <String>[
1966 "1+x",
1967 "2+x",
1968 "3+zs",
1969 "4+k",
1970 "5+Q",
1971 "5-a",
1972 "6+==",
1973 "7+x",
1974 "8+==",
1975 "9+==",
1976 "0+k"]);
1977
1978 // keywords
1979 CompletionTestCase.buildTests('test014', '''
1980 class Q {
1981 bool x;
1982 List zs;
1983 int k;
1984 !Dvar a;
1985 !Evoid mth() {
1986 !1while (z) { !Gcontinue; };
1987 !2do{ !Hbreak; } !3while(x);
1988 !4for(z !5in zs) {}
1989 !6for (int i; i < 3; i++);
1990 !7switch(k) {!8case 1:{} !9default:{}}
1991 !Atry {
1992 } !Bon Object !Ccatch(a){}
1993 !Fassert true;
1994 !Jif (x) {} !Kelse {};
1995 !Lreturn;
1996 }
1997 }''',
1998 <String>[
1999 "1+while",
2000 "2+do",
2001 "3+while",
2002 "4+for",
2003 "5+in",
2004 "6+for",
2005 "7+switch",
2006 "8+case",
2007 "9+default",
2008 "A+try",
2009 "B+on",
2010 "C+catch",
2011 "D+var",
2012 "E+void",
2013 "F+assert",
2014 "G+continue",
2015 "H+break",
2016 "J+if",
2017 "K+else",
2018 "L+return"]);
2019
2020 // operators in function
2021 CompletionTestCase.buildTests(
2022 'test015',
2023 '''f(a,b,c) => a + b * c !1;''',
2024 <String>["1+=="]);
2025
2026 // operators in return
2027 CompletionTestCase.buildTests(
2028 'test016',
2029 '''class X {dynamic f(a,b,c) {return a + b * c !1;}}''',
2030 <String>["1+=="]);
2031
2032 // keywords
2033 CompletionTestCase.buildTests('test017', '''
2034 !1library foo;
2035 !2import 'x' !5as r;
2036 !3export '!8uri' !6hide Q !7show X;
2037 !4part 'x';''',
2038 <String>[
2039 "1+library",
2040 "2+import",
2041 "3+export",
2042 "4+part",
2043 "5+as",
2044 "6+hide",
2045 "7+show",
2046 "8-null"]);
2047
2048 // keywords
2049 CompletionTestCase.buildTests(
2050 'test018',
2051 '''!1part !2of foo;''',
2052 <String>["1+part", "2+of"]);
2053
2054 CompletionTestCase.buildTests('test019', '''
2055 var truefalse = 0;
2056 var falsetrue = 1;
2057 main() {
2058 var foo = true!1
2059 }''', <String>["1+true", "1+truefalse", "1-falsetrue"]);
2060
2061 CompletionTestCase.buildTests(
2062 'test020',
2063 '''var x = null.!1''',
2064 <String>["1+toString"]);
2065
2066 CompletionTestCase.buildTests(
2067 'test021',
2068 '''var x = .!1''',
2069 <String>["1-toString"]);
2070
2071 CompletionTestCase.buildTests(
2072 'test022',
2073 '''var x = .!1;''',
2074 <String>["1-toString"]);
2075
2076 CompletionTestCase.buildTests('test023', '''
2077 class Map{getKeys(){}}
2078 class X {
2079 static x1(Map m) {
2080 m.!1getKeys;
2081 }
2082 x2(Map m) {
2083 m.!2getKeys;
2084 }
2085 }''', <String>["1+getKeys", "2+getKeys"]);
2086
2087 // Note lack of semicolon following completion location
2088 CompletionTestCase.buildTests('test024', '''
2089 class List{factory List.from(Iterable other) {}}
2090 class F {
2091 f() {
2092 new List.!1
2093 }
2094 }''', <String>["1+from"]);
2095
2096 CompletionTestCase.buildTests('test025', '''
2097 class R {
2098 static R _m;
2099 static R m;
2100 f() {
2101 var a = !1m;
2102 var b = _!2m;
2103 var c = !3g();
2104 }
2105 static g() {
2106 var a = !4m;
2107 var b = _!5m;
2108 var c = !6g();
2109 }
2110 }
2111 class T {
2112 f() {
2113 R x;
2114 x.!7g();
2115 x.!8m;
2116 x._!9m;
2117 }
2118 static g() {
2119 var q = R._!Am;
2120 var g = R.!Bm;
2121 var h = R.!Cg();
2122 }
2123 h() {
2124 var q = R._!Dm;
2125 var g = R.!Em;
2126 var h = R.!Fg();
2127 }
2128 }''',
2129 <String>[
2130 "1+m",
2131 "2+_m",
2132 "3+g",
2133 "4+m",
2134 "5+_m",
2135 "6+g",
2136 "7-g",
2137 "8-m",
2138 "9-_m",
2139 "A+_m",
2140 "B+m",
2141 "C+g",
2142 "D+_m",
2143 "E+m",
2144 "F+g"]);
2145
2146 CompletionTestCase.buildTests(
2147 'test026',
2148 '''var aBcD; var x=ab!1''',
2149 <String>["1+aBcD"]);
2150
2151 CompletionTestCase.buildTests(
2152 'test027',
2153 '''m(){try{}catch(eeee,ssss){s!1}''',
2154 <String>["1+ssss"]);
2155
2156 CompletionTestCase.buildTests(
2157 'test028',
2158 '''m(){var isX=3;if(is!1)''',
2159 <String>["1+isX"]);
2160
2161 CompletionTestCase.buildTests(
2162 'test029',
2163 '''m(){[1].forEach((x)=>!1x);}''',
2164 <String>["1+x"]);
2165
2166 CompletionTestCase.buildTests(
2167 'test030',
2168 '''n(){[1].forEach((x){!1});}''',
2169 <String>["1+x"]);
2170
2171 CompletionTestCase.buildTests(
2172 'test031',
2173 '''class Caster {} m() {try {} on Cas!1ter catch (CastBlock) {!2}}''',
2174 <String>["1+Caster", "1-CastBlock", "2+Caster", "2+CastBlock"]);
2175
2176 CompletionTestCase.buildTests('test032', '''
2177 const ONE = 1;
2178 const ICHI = 10;
2179 const UKSI = 100;
2180 const EIN = 1000;
2181 m() {
2182 int x;
2183 switch (x) {
2184 case !3ICHI:
2185 case UKSI:
2186 case EIN!2:
2187 case ONE!1: return;
2188 default: return;
2189 }
2190 }''',
2191 <String>[
2192 "1+ONE",
2193 "1-UKSI",
2194 "2+EIN",
2195 "2-ICHI",
2196 "3+ICHI",
2197 "3+UKSI",
2198 "3+EIN",
2199 "3+ONE"]);
2200
2201 CompletionTestCase.buildTests(
2202 'test033',
2203 '''class A{}class B extends A{b(){}}class C implements A {c(){}}class X{ x(){A f;f.!1}}''',
2204 <String>["1+b", "1-c"]);
2205
2206 // TODO(scheglov) decide what to do with Type for untyped field (not
2207 // supported by the new store)
2208 // test analysis of untyped fields and top-level vars
2209 CompletionTestCase.buildTests('test034', '''
2210 var topvar;
2211 class Top {top(){}}
2212 class Left extends Top {left(){}}
2213 class Right extends Top {right(){}}
2214 t1() {
2215 topvar = new Left();
2216 }
2217 t2() {
2218 topvar = new Right();
2219 }
2220 class A {
2221 var field;
2222 a() {
2223 field = new Left();
2224 }
2225 b() {
2226 field = new Right();
2227 }
2228 test() {
2229 topvar.!1top();
2230 field.!2top();
2231 }
2232 }''', <String>["1+top", "2+top"]);
2233
2234 // test analysis of untyped fields and top-level vars
2235 CompletionTestCase.buildTests(
2236 'test035',
2237 '''class Y {final x='hi';mth() {x.!1length;}}''',
2238 <String>["1+length"]);
2239
2240 // TODO(scheglov) decide what to do with Type for untyped field (not
2241 // supported by the new store)
2242 // test analysis of untyped fields and top-level vars
2243 CompletionTestCase.buildTests('test036', '''
2244 class A1 {
2245 var field;
2246 A1() : field = 0;
2247 q() {
2248 A1 a = new A1();
2249 a.field.!1
2250 }
2251 }
2252 main() {
2253 A1 a = new A1();
2254 a.field.!2
2255 }''', <String>["1+round", "2+round"]);
2256
2257 CompletionTestCase.buildTests('test037', '''
2258 class HttpServer{}
2259 class HttpClient{}
2260 main() {
2261 new HtS!1
2262 }''', <String>["1+HttpServer", "1-HttpClient"]);
2263
2264 CompletionTestCase.buildTests('test038', '''
2265 class X {
2266 x(){}
2267 }
2268 class Y {
2269 y(){}
2270 }
2271 class A<Z extends X> {
2272 Y ay;
2273 Z az;
2274 A(this.ay, this.az) {
2275 ay.!1y;
2276 az.!2x;
2277 }
2278 }''', <String>["1+y", "1-x", "2+x", "2-y"]);
2279
2280 // test analysis of untyped fields and top-level vars
2281 CompletionTestCase.buildTests(
2282 'test039',
2283 '''class X{}var x = null as !1X;''',
2284 <String>["1+X", "1-void"]);
2285
2286 // test arg lists with named params
2287 CompletionTestCase.buildTests(
2288 'test040',
2289 '''m(){f(a, b, {x1, x2, y}) {};f(1, 2, !1)!2;}''',
2290 <String>["1+x1", "2-x2"]);
2291
2292 // test arg lists with named params
2293 CompletionTestCase.buildTests(
2294 'test041',
2295 '''m(){f(a, b, {x1, x2, y}) {};f(1, 2, !1''',
2296 <String>["1+x1", "1+x2", "1+y"]);
2297
2298 // test arg lists with named params
2299 CompletionTestCase.buildTests(
2300 'test042',
2301 '''m(){f(a, b, {x1, x2, y}) {};f(1, 2, !1;!2''',
2302 <String>["1+x1", "1+x2", "2-y"]);
2303 }
2304
2305 void buildOtherTests() {
2306 CompletionTestCase.buildTests(
2307 'test_classMembers_inGetter',
2308 '''class A { var fff; get z {ff!1}}''',
2309 <String>["1+fff"]);
2310
2311 CompletionTestCase.buildTests(
2312 'testSingle',
2313 '''class A {int x; !2mth() {int y = this.x;}}class B{}''',
2314 <String>["2+B"]);
2315 }
2316 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/completion_test_support.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698