blob: 93483ce8c03848839804e0c6d90cb0e2e9c197d6 [file] [log] [blame]
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001// 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
5library test.completion.support;
6
paulberry@google.com523dac82014-12-17 16:52:25 +00007import 'dart:async';
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00008import 'dart:collection';
9
Konstantin Shcheglovde4d8b32016-10-06 08:47:15 -070010import 'package:test/test.dart';
paulberry@google.com523dac82014-12-17 16:52:25 +000011
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000012import 'completion_test_support.dart';
Brian Wilkerson908708d2015-08-05 08:13:28 -070013
14main() {
Brian Wilkerson908708d2015-08-05 08:13:28 -070015 CompletionTestBuilder builder = new CompletionTestBuilder();
16 builder.buildAll();
17}
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000018
paulberry@google.com6d7155d2014-12-20 15:47:25 +000019/**
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000020 * A builder that builds the completion tests.
21 */
22class CompletionTestBuilder {
paulberry@google.com523dac82014-12-17 16:52:25 +000023 /**
24 * Number of tests that have been built that are expected to pass.
25 */
26 int expectedPassCount = 0;
27
28 /**
29 * Number of tests that have been built that are expected to fail.
30 */
31 int expectedFailCount = 0;
32
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000033 void buildAll() {
34 buildNumberedTests();
35 buildCommentSnippetTests();
36 buildCompletionTests();
37 buildOtherTests();
38 buildLibraryTests();
paulberry@google.com523dac82014-12-17 16:52:25 +000039 int testCount = expectedPassCount + expectedFailCount;
40 print(
41 'Total $testCount tests, of which $expectedFailCount are expected to fail.');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000042 }
43
44 void buildCommentSnippetTests() {
Brian Wilkerson908708d2015-08-05 08:13:28 -070045 buildTests(
46 'testCommentSnippets001',
47 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000048class X {static final num MAX = 0;num yc,xc;mth() {xc = yc = MA!1X;x!2c.abs();num f = M!3AX;}}''',
49 <String>["1+MAX", "2+xc", "3+MAX"]);
50
Brian Wilkerson908708d2015-08-05 08:13:28 -070051 buildTests(
52 'testCommentSnippets002',
53 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000054class Y {String x='hi';mth() {x.l!1ength;int n = 0;x!2.codeUnitAt(n!3);}}''',
55 <String>["1+length", "2+x", "3+n"]);
56
Brian Wilkerson908708d2015-08-05 08:13:28 -070057 buildTests(
58 'testCommentSnippets004',
59 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000060class A {!1int x; !2mth() {!3int y = this.!5x!6;}}class B{}''',
danrubel@google.com438aa442014-12-15 17:48:00 +000061 <String>["1+A", "2+B", "3+x", "3-y", "5+mth", "6+x"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000062
Brian Wilkerson908708d2015-08-05 08:13:28 -070063 buildTests(
64 'testCommentSnippets005',
65 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000066class Date { static Date JUN, JUL;}class X { m() { return Da!1te.JU!2L; }}''',
67 <String>["1+Date", "2+JUN", "2+JUL"]);
68
Brian Wilkerson908708d2015-08-05 08:13:28 -070069 buildTests(
70 'testCommentSnippets007',
71 '''
danrubel@google.comddc3cae2014-12-16 16:53:24 +000072class 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{}''',
danrubel@google.com676e0272015-03-12 21:40:55 +000073 <String>["1+bool", "2+bool", "3+int", "4+Arrays"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000074
Brian Wilkerson908708d2015-08-05 08:13:28 -070075 buildTests(
76 'testCommentSnippets008',
77 '''
78class Date{}final num M = Dat!1''',
79 <String>["1+Date"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000080
81 // space, char, eol are important
Brian Wilkerson908708d2015-08-05 08:13:28 -070082 buildTests(
83 'testCommentSnippets009',
84 '''
85class Maps{}class x extends!5 !2M!3 !4implements!6 !1\n{}''',
86 <String>[
87 "1+Map",
88 "2+Maps",
89 "3+Maps",
90 "4-Maps",
91 "4+implements",
92 "5-Maps",
93 "6-Map",
94 "6+implements"
95 ],
96 failingTests: '46');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +000097
98 // space, char, eol are important
Brian Wilkerson908708d2015-08-05 08:13:28 -070099 buildTests(
100 'testCommentSnippets010',
101 '''
102class x implements !1{}''',
103 <String>["1+Map"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000104
105 // space, char, eol are important
Brian Wilkerson908708d2015-08-05 08:13:28 -0700106 buildTests(
107 'testCommentSnippets011',
108 '''
109class x implements M!1{}''',
110 <String>["1+Map"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000111
112 // space, char, eol are important
Brian Wilkerson908708d2015-08-05 08:13:28 -0700113 buildTests(
114 'testCommentSnippets012',
115 '''
116class x implements M!1\n{}''',
117 <String>["1+Map"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000118
Brian Wilkerson908708d2015-08-05 08:13:28 -0700119 buildTests(
120 'testCommentSnippets013',
121 '''
122class x !2{!1}!3''',
123 <String>["1+num", "2-num", "3+num"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000124
125 // trailing space is important
Brian Wilkerson908708d2015-08-05 08:13:28 -0700126 buildTests(
127 'testCommentSnippets014',
128 '''
129typedef n!1 ;''',
130 <String>["1+num"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000131
Brian Wilkerson908708d2015-08-05 08:13:28 -0700132 buildTests(
133 'testCommentSnippets015',
134 '''
135class D {f(){} g(){f!1(f!2);}}''',
136 <String>["1+f", "2+f"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000137
Brian Wilkerson908708d2015-08-05 08:13:28 -0700138 buildTests(
139 'testCommentSnippets016',
140 '''
141class F {m() { m(); !1}}''',
142 <String>["1+m"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000143
Brian Wilkerson908708d2015-08-05 08:13:28 -0700144 buildTests(
145 'testCommentSnippets017',
146 '''
147class F {var x = !1false;}''',
148 <String>["1+true"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000149
Brian Wilkerson908708d2015-08-05 08:13:28 -0700150 buildTests(
151 'testCommentSnippets018',
152 '''
danrubel@google.com676e0272015-03-12 21:40:55 +0000153class Map{}class Arrays{}class C{ m(!1){} n(!2 x, q)''',
154 <String>["1+Map", "1-void", "1-null", "2+Arrays", "2-void", "2-null"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000155
Brian Wilkerson908708d2015-08-05 08:13:28 -0700156 buildTests(
157 'testCommentSnippets019',
158 '''
159class A{m(){Object x;x.!1/**/clear()''',
160 <String>["1+toString"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000161
Brian Wilkerson908708d2015-08-05 08:13:28 -0700162 buildTests(
163 'testCommentSnippets020',
164 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000165classMap{}class tst {var newt;void newf(){}test() {var newz;new!1/**/;}}''',
danrubel@google.comb9f35592015-01-28 20:39:36 +0000166 <String>["1+newt", "1+newf", "1+newz", "1-Map"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000167
Brian Wilkerson908708d2015-08-05 08:13:28 -0700168 buildTests(
169 'testCommentSnippets021',
170 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000171class Map{}class tst {var newt;void newf(){}test() {var newz;new !1/**/;}}''',
danrubel@google.com676e0272015-03-12 21:40:55 +0000172 <String>["1+Map", "1-newt"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000173
Brian Wilkerson908708d2015-08-05 08:13:28 -0700174 buildTests(
175 'testCommentSnippets022',
176 '''
177class Map{}class F{m(){new !1;}}''',
178 <String>["1+Map"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000179
Brian Wilkerson908708d2015-08-05 08:13:28 -0700180 buildTests(
181 'testCommentSnippets022a',
182 '''
183class Map{}class F{m(){new !1''',
184 <String>["1+Map"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000185
Brian Wilkerson908708d2015-08-05 08:13:28 -0700186 buildTests(
187 'testCommentSnippets022b',
188 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000189class Map{factory Map.qq(){return null;}}class F{m(){new Map.!1qq();}}''',
danrubel@google.comcd4ec282014-12-15 17:16:40 +0000190 <String>["1+qq"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000191
Brian Wilkerson908708d2015-08-05 08:13:28 -0700192 buildTests(
193 'testCommentSnippets023',
194 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000195class X {X c; X(this.!1c!3) : super() {c.!2}}''',
danrubel@google.com676e0272015-03-12 21:40:55 +0000196 <String>["1+c", "2+c", "3+c"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000197
Brian Wilkerson908708d2015-08-05 08:13:28 -0700198 buildTests(
199 'testCommentSnippets024',
200 '''
201class q {m(Map q){var x;m(!1)}n(){var x;n(!2)}}''',
202 <String>["1+x", "2+x"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000203
Brian Wilkerson908708d2015-08-05 08:13:28 -0700204 buildTests(
205 'testCommentSnippets025',
206 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000207class q {num m() {var q; num x=!1 q!3 + !2/**/;}}''',
danrubel@google.com676e0272015-03-12 21:40:55 +0000208 <String>["1+q", "2+q", "3+q"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000209
Brian Wilkerson908708d2015-08-05 08:13:28 -0700210 buildTests(
211 'testCommentSnippets026',
212 '''
213class List{}class a implements !1{}''',
214 <String>["1+List"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000215
Brian Wilkerson908708d2015-08-05 08:13:28 -0700216 buildTests(
217 'testCommentSnippets027',
218 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000219class String{}class List{}class test <X extends !1String!2> {}''',
danrubel@google.com676e0272015-03-12 21:40:55 +0000220 <String>["1+List", "2+String", "2-List"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000221
Brian Wilkerson908708d2015-08-05 08:13:28 -0700222 buildTests(
223 'testCommentSnippets028',
224 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000225class String{}class List{}class DateTime{}typedef T Y<T extends !1>(List input);''',
danrubel@google.com676e0272015-03-12 21:40:55 +0000226 <String>["1+DateTime", "1+String"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000227
Brian Wilkerson908708d2015-08-05 08:13:28 -0700228 buildTests(
229 'testCommentSnippets029',
230 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000231interface A<X> default B<X extends !1List!2> {}''',
232 <String>["1+DateTime", "2+List"]);
233
Brian Wilkerson908708d2015-08-05 08:13:28 -0700234 buildTests(
235 'testCommentSnippets030',
236 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000237class Bar<T extends Foo> {const Bar(!1T!2 k);T!3 m(T!4 a, T!5 b){}final T!6 f = null;}''',
paulberry@google.com24611252014-12-09 16:44:12 +0000238 <String>["1+T", "2+T", "3+T", "4+T", "5+T", "6+T"],
239 failingTests: '123456');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000240
Brian Wilkerson908708d2015-08-05 08:13:28 -0700241 buildTests(
242 'testCommentSnippets031',
243 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000244class Bar<T extends Foo> {m(x){if (x is !1) return;if (x is!!!2)}}''',
Brian Wilkerson908708d2015-08-05 08:13:28 -0700245 <String>["1+Bar", "1+T", "2+T", "2+Bar"],
246 failingTests: '12');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000247
Brian Wilkerson908708d2015-08-05 08:13:28 -0700248 buildTests(
249 'testCommentSnippets032',
250 '''
danrubel@google.comddc3cae2014-12-16 16:53:24 +0000251class Fit{}class Bar<T extends Fooa> {const !2F!1ara();}''',
Brian Wilkerson908708d2015-08-05 08:13:28 -0700252 <String>["1+Fit", "1+Fara", "1-Bar", "2+Fit"],
253 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000254
255 // Type propagation
Brian Wilkerson908708d2015-08-05 08:13:28 -0700256 buildTests(
257 'testCommentSnippets033',
258 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000259class List{add(){}length(){}}t1() {var x;if (x is List) {x.!1add(3);}}''',
260 <String>["1+add", "1+length"]);
261
262 // Type propagation
Brian Wilkerson908708d2015-08-05 08:13:28 -0700263 buildTests(
264 'testCommentSnippets035',
265 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000266class List{clear(){}length(){}}t3() {var x=new List(), y=x.!1length();x.!2clear();}''',
267 <String>["1+length", "2+clear"]);
268
Brian Wilkerson908708d2015-08-05 08:13:28 -0700269 buildTests(
270 'testCommentSnippets036',
271 '''
272class List{}t3() {var x=new List!1}''',
273 <String>["1+List"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000274
Brian Wilkerson908708d2015-08-05 08:13:28 -0700275 buildTests(
276 'testCommentSnippets037',
277 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000278class List{factory List.from(){}}t3() {var x=new List.!1}''',
danrubel@google.comcd4ec282014-12-15 17:16:40 +0000279 <String>["1+from"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000280
Brian Wilkerson908708d2015-08-05 08:13:28 -0700281 buildTests(
282 'testCommentSnippets038',
283 '''
284f(){int xa; String s = '\$x!1';}''',
285 <String>["1+xa"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000286
Brian Wilkerson908708d2015-08-05 08:13:28 -0700287 buildTests(
288 'testCommentSnippets038a',
289 '''
290int xa; String s = '\$x!1\'''',
291 <String>["1+xa"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000292
Brian Wilkerson908708d2015-08-05 08:13:28 -0700293 buildTests(
294 'testCommentSnippets039',
295 '''
296f(){int xa; String s = '\$!1';}''',
297 <String>["1+xa"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000298
Brian Wilkerson908708d2015-08-05 08:13:28 -0700299 buildTests(
300 'testCommentSnippets039a',
301 '''
302int xa; String s = '\$!1\'''',
303 <String>["1+xa"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000304
Brian Wilkerson908708d2015-08-05 08:13:28 -0700305 buildTests(
306 'testCommentSnippets040',
307 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000308class List{add(){}}class Map{}class X{m(){List list; list.!1 Map map;}}''',
309 <String>["1+add"]);
310
Brian Wilkerson908708d2015-08-05 08:13:28 -0700311 buildTests(
312 'testCommentSnippets041',
313 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000314class List{add(){}length(){}}class X{m(){List list; list.!1 zox();}}''',
315 <String>["1+add"]);
316
Brian Wilkerson908708d2015-08-05 08:13:28 -0700317 buildTests(
318 'testCommentSnippets042',
319 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000320class DateTime{static const int WED=3;int get day;}fd(){DateTime d=new DateTime.now();d.!1WED!2;}''',
danrubel@google.com5194a2b2015-02-07 00:56:15 +0000321 <String>["1+day", "2-WED"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000322
Brian Wilkerson908708d2015-08-05 08:13:28 -0700323 buildTests(
324 'testCommentSnippets043',
325 '''
326class L{var k;void.!1}''',
327 <String>["1-k"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000328
Brian Wilkerson908708d2015-08-05 08:13:28 -0700329 buildTests(
330 'testCommentSnippets044',
331 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000332class List{}class XXX {XXX.fisk();}main() {main(); new !1}}''',
danrubel@google.com676e0272015-03-12 21:40:55 +0000333 <String>["1+List", "1+XXX.fisk"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000334
Brian Wilkerson908708d2015-08-05 08:13:28 -0700335 buildTests(
336 'testCommentSnippets047',
337 '''
338f(){int x;int y=!1;}''',
339 <String>["1+x"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000340
Brian Wilkerson908708d2015-08-05 08:13:28 -0700341 buildTests(
342 'testCommentSnippets048',
343 '''
344import 'dart:convert' as json;f() {var x=new js!1}''',
345 <String>["1+json"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000346
Brian Wilkerson908708d2015-08-05 08:13:28 -0700347 buildTests(
348 'testCommentSnippets049',
349 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000350import 'dart:convert' as json;
351import 'dart:convert' as jxx;
paulberry@google.comdfb35c02014-12-19 17:02:18 +0000352class JsonDecoderX{}
Brian Wilkerson908708d2015-08-05 08:13:28 -0700353f1() {var x=new !2j!1s!3}''',
354 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -0700355 "1+json",
356 "1+jxx",
357 "2+json",
358 "2+jxx",
359 "2-JsonDecoder",
360 "3+json",
361 "3-jxx"
362 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000363
Brian Wilkerson908708d2015-08-05 08:13:28 -0700364 buildTests(
365 'testCommentSnippets050',
366 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000367class xdr {
368 xdr();
369 const xdr.a(a,b,c);
370 xdr.b();
371 f() => 3;
372}
373class xa{}
374k() {
375 new x!1dr().f();
376 const x!2dr.!3a(1, 2, 3);
Brian Wilkerson908708d2015-08-05 08:13:28 -0700377}''',
378 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -0700379 "1+xdr",
380 "1+xa",
381 "1+xdr.a",
382 "1+xdr.b",
383 "2+xa", // suggest default constructor
384 "2+xdr", // suggest normal constructor
385 "2+xdr.a",
386 "2+xdr.b", // suggest named constructor
387 "3+b", // suggest named constructor
388 "3+a"
389 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000390
391 // Type propagation.
Brian Wilkerson908708d2015-08-05 08:13:28 -0700392 buildTests(
393 'testCommentSnippets051',
394 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000395class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{getKeys(){}}
396void r() {
397 var v;
398 if (v is String) {
399 v.!1length;
400 v.!2getKeys;
401 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700402}''',
403 <String>["1+length", "2-getKeys"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000404
405 // Type propagation.
Brian Wilkerson908708d2015-08-05 08:13:28 -0700406 buildTests(
407 'testCommentSnippets052',
408 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000409class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{getKeys(){}}
410void r() {
411 List<String> values = ['a','b','c'];
412 for (var v in values) {
413 v.!1toUpperCase;
414 v.!2getKeys;
415 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700416}''',
417 <String>["1+toUpperCase", "2-getKeys"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000418
419 // Type propagation.
Brian Wilkerson908708d2015-08-05 08:13:28 -0700420 buildTests(
421 'testCommentSnippets053',
422 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000423class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{getKeys(){}}
424void r() {
425 var v;
426 while (v is String) {
427 v.!1toUpperCase;
428 v.!2getKeys;
429 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700430}''',
431 <String>["1+toUpperCase", "2-getKeys"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000432
Brian Wilkerson908708d2015-08-05 08:13:28 -0700433 buildTests(
434 'testCommentSnippets054',
435 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000436class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{getKeys(){}}
437void r() {
438 var v;
439 for (; v is String; v.!1isEmpty) {
440 v.!2toUpperCase;
441 v.!3getKeys;
442 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700443}''',
444 <String>["1+isEmpty", "2+toUpperCase", "3-getKeys"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000445
Brian Wilkerson908708d2015-08-05 08:13:28 -0700446 buildTests(
447 'testCommentSnippets055',
448 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000449class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{getKeys(){}}
450void r() {
451 String v;
452 if (v is Object) {
453 v.!1toUpperCase;
454 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700455}''',
456 <String>["1+toUpperCase"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000457
458 // Type propagation.
Brian Wilkerson908708d2015-08-05 08:13:28 -0700459 buildTests(
460 'testCommentSnippets056',
461 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000462class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{getKeys(){}}
463void f(var v) {
464 if (v is!! String) {
465 return;
466 }
467 v.!1toUpperCase;
Brian Wilkerson908708d2015-08-05 08:13:28 -0700468}''',
469 <String>["1+toUpperCase"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000470
471 // Type propagation.
Brian Wilkerson908708d2015-08-05 08:13:28 -0700472 buildTests(
473 'testCommentSnippets057',
474 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000475class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{getKeys(){}}
476void f(var v) {
danrubel@google.comdc95fd32015-02-06 04:43:15 +0000477 if ((v as String).!2length == 0) {
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000478 v.!1toUpperCase;
479 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700480}''',
481 <String>["1+toUpperCase", "2+length"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000482
Brian Wilkerson908708d2015-08-05 08:13:28 -0700483 buildTests(
484 'testCommentSnippets058',
485 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000486typedef vo!2id callback(int k);
487void x(callback q){}
488void r() {
489 callback v;
490 x(!1);
Brian Wilkerson908708d2015-08-05 08:13:28 -0700491}''',
492 <String>["1+v", "2+void"],
493 failingTests: '2');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000494
Brian Wilkerson908708d2015-08-05 08:13:28 -0700495 buildTests(
496 'testCommentSnippets059',
497 '''
498f(){((int x) => x+4).!1call(1);}''',
499 <String>["1-call"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000500
Brian Wilkerson908708d2015-08-05 08:13:28 -0700501 buildTests(
502 'testCommentSnippets060',
503 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000504class Map{}
505abstract class MM extends Map{factory MM() => new Map();}
506class Z {
507 MM x;
508 f() {
509 x!1
510 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700511}''',
512 <String>["1+x", "1-x[]"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000513
Brian Wilkerson908708d2015-08-05 08:13:28 -0700514 buildTests(
515 'testCommentSnippets061',
516 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000517class A{m(){!1f(3);!2}}n(){!3f(3);!4}f(x)=>x*3;''',
518 <String>["1+f", "1+n", "2+f", "2+n", "3+f", "3+n", "4+f", "4+n"]);
519
520 // Type propagation.
Brian Wilkerson908708d2015-08-05 08:13:28 -0700521 buildTests(
522 'testCommentSnippets063',
523 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000524class String{int length(){} String toUpperCase(){} bool isEmpty(){}}class Map{getKeys(){}}
525void r(var v) {
526 v.!1toUpperCase;
527 assert(v is String);
528 v.!2toUpperCase;
Brian Wilkerson908708d2015-08-05 08:13:28 -0700529}''',
530 <String>["1-toUpperCase", "2+toUpperCase"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000531
Brian Wilkerson908708d2015-08-05 08:13:28 -0700532 buildTests(
533 'testCommentSnippets064',
534 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000535class Spline {
536 Line c;
537 Spline a() {
538 return this;
539 }
540 Line b() {
541 return null;
542 }
543 Spline f() {
544 Line x = new Line();
545 x.!9h()..!1a()..!2b().!7g();
546 x.!8j..!3b()..!4c..!6c..!5a();
547 }
548}
549class Line {
550 Spline j;
551 Line g() {
552 return this;
553 }
554 Spline h() {
555 return null;
556 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700557}''',
558 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -0700559 "1+a",
560 "2+b",
561 "1-g",
562 "2-h",
563 "3+b",
564 "4+c",
565 "5+a",
566 "6+c",
567 "7+g",
568 "8+j",
569 "9+h"
570 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000571
Brian Wilkerson908708d2015-08-05 08:13:28 -0700572 buildTests(
573 'testCommentSnippets065',
574 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000575class Spline {
576 Line c;
577 Spline a() {
578 return this;
579 }
580 Line b() {
581 return null;
582 }
583 Spline f() {
584 Line x = new Line();
585 x.h()..!1;
586 }
587}
588class Line {
589 Spline j;
590 Line g() {
591 return this;
592 }
593 Spline h() {
594 return null;
595 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700596}''',
597 <String>["1+a"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000598
Brian Wilkerson908708d2015-08-05 08:13:28 -0700599 buildTests(
600 'testCommentSnippets066',
601 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000602class Spline {
603 Line c;
604 Spline a() {
605 return this;
606 }
607 Line b() {
608 return null;
609 }
610 Spline f() {
611 Line x = new Line();
612 x.h()..a()..!1;
613 }
614}
615class Line {
616 Spline j;
617 Line g() {
618 return this;
619 }
620 Spline h() {
621 return null;
622 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700623}''',
624 <String>["1+b"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000625
Brian Wilkerson908708d2015-08-05 08:13:28 -0700626 buildTests(
627 'testCommentSnippets067',
628 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000629class Spline {
630 Line c;
631 Spline a() {
632 return this;
633 }
634 Line b() {
635 return null;
636 }
637 Spline f() {
638 Line x = new Line();
639 x.h()..a()..c..!1;
640 }
641}
642class Line {
643 Spline j;
644 Line g() {
645 return this;
646 }
647 Spline h() {
648 return null;
649 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700650}''',
651 <String>["1+b"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000652
Brian Wilkerson908708d2015-08-05 08:13:28 -0700653 buildTests(
654 'testCommentSnippets068',
655 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000656class Spline {
657 Line c;
658 Spline a() {
659 return this;
660 }
661 Line b() {
662 return null;
663 }
664 Spline f() {
665 Line x = new Line();
666 x.j..b()..c..!1;
667 }
668}
669class Line {
670 Spline j;
671 Line g() {
672 return this;
673 }
674 Spline h() {
675 return null;
676 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700677}''',
678 <String>["1+c"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000679
Brian Wilkerson908708d2015-08-05 08:13:28 -0700680 buildTests(
681 'testCommentSnippets069',
682 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000683class Spline {
684 Line c;
685 Spline a() {
686 return this;
687 }
688 Line b() {
689 return null;
690 }
691 Spline f() {
692 Line x = new Line();
693 x.j..b()..!1;
694 }
695}
696class Line {
697 Spline j;
698 Line g() {
699 return this;
700 }
701 Spline h() {
702 return null;
703 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700704}''',
705 <String>["1+c"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000706
Brian Wilkerson908708d2015-08-05 08:13:28 -0700707 buildTests(
708 'testCommentSnippets070',
709 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000710class Spline {
711 Line c;
712 Spline a() {
713 return this;
714 }
715 Line b() {
716 return null;
717 }
718 Spline f() {
719 Line x = new Line();
720 x.j..!1;
721 }
722}
723class Line {
724 Spline j;
725 Line g() {
726 return this;
727 }
728 Spline h() {
729 return null;
730 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700731}''',
732 <String>["1+b"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000733
Brian Wilkerson908708d2015-08-05 08:13:28 -0700734 buildTests(
735 'testCommentSnippets072',
736 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000737class X {
738 int _p;
739 set p(int x) => _p = x;
740}
741f() {
742 X x = new X();
743 x.!1p = 3;
Brian Wilkerson908708d2015-08-05 08:13:28 -0700744}''',
745 <String>["1+p"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000746
Brian Wilkerson908708d2015-08-05 08:13:28 -0700747 buildTests(
748 'testCommentSnippets073',
749 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000750class X {
751 m() {
752 JSON.stri!1;
753 X f = null;
754 }
755}
756class JSON {
757 static stringify() {}
Brian Wilkerson908708d2015-08-05 08:13:28 -0700758}''',
759 <String>["1+stringify"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000760
Brian Wilkerson908708d2015-08-05 08:13:28 -0700761 buildTests(
762 'testCommentSnippets074',
763 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000764class X {
765 m() {
766 _x!1
767 }
768 _x1(){}
Brian Wilkerson908708d2015-08-05 08:13:28 -0700769}''',
770 <String>["1+_x1"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000771
Brian Wilkerson908708d2015-08-05 08:13:28 -0700772 buildTests(
773 'testCommentSnippets075',
774 '''
775p(x)=>0;var E;f(q)=>!1p(!2E);''',
776 <String>["1+p", "2+E"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000777
Brian Wilkerson908708d2015-08-05 08:13:28 -0700778 buildTests(
779 'testCommentSnippets076',
780 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000781class Map<K,V>{}class List<E>{}class int{}main() {var m=new Map<Lis!1t<Map<int,in!2t>>,List<!3int>>();}''',
danrubel@google.com676e0272015-03-12 21:40:55 +0000782 <String>["1+List", "2+int", "3+int"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000783
Brian Wilkerson908708d2015-08-05 08:13:28 -0700784 buildTests(
785 'testCommentSnippets076a',
786 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000787class Map<K,V>{}class List<E>{}class int{}main() {var m=new Map<Lis!1t<Map<int,in!2t>>,List<!3>>();}''',
danrubel@google.com676e0272015-03-12 21:40:55 +0000788 <String>["1+List", "2+int", "3+int"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000789
Brian Wilkerson908708d2015-08-05 08:13:28 -0700790 buildTests(
791 'testCommentSnippets077',
792 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000793class FileMode {
794 static const READ = const FileMode._internal(0);
795 static const WRITE = const FileMode._internal(1);
796 static const APPEND = const FileMode._internal(2);
797 const FileMode._internal(int this._mode);
798 factory FileMode._internal1(int this._mode);
799 factory FileMode(_mode);
800 final int _mode;
801}
802class File {
803 factory File(String path) => null;
804 factory File.fromPath(Path path) => null;
805}
Brian Wilkerson908708d2015-08-05 08:13:28 -0700806f() => new Fil!1''',
807 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -0700808 "1+File",
809 "1+File.fromPath",
810 "1+FileMode",
811 "1+FileMode._internal1",
812 "1+FileMode._internal"
813 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000814
Brian Wilkerson908708d2015-08-05 08:13:28 -0700815 buildTests(
816 'testCommentSnippets078',
817 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000818class Map{static from()=>null;clear(){}}void main() { Map.!1 }''',
819 <String>["1+from", "1-clear"]); // static method, instance method
820
Brian Wilkerson908708d2015-08-05 08:13:28 -0700821 buildTests(
822 'testCommentSnippets079',
823 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000824class Map{static from()=>null;clear(){}}void main() { Map s; s.!1 }''',
danrubel@google.com5194a2b2015-02-07 00:56:15 +0000825 <String>["1-from", "1+clear"]); // static method, instance method
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000826
Brian Wilkerson908708d2015-08-05 08:13:28 -0700827 buildTests(
828 'testCommentSnippets080',
829 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000830class RuntimeError{var message;}void main() { RuntimeError.!1 }''',
831 <String>["1-message"]); // field
832
Brian Wilkerson908708d2015-08-05 08:13:28 -0700833 buildTests(
834 'testCommentSnippets081',
835 '''
836class Foo {this.!1}''',
837 <String>["1-Object"],
838 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000839
Brian Wilkerson908708d2015-08-05 08:13:28 -0700840 buildTests(
841 'testCommentSnippets082',
842 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000843 class HttpRequest {}
844 class HttpResponse {}
845 main() {
846 var v = (HttpRequest req, HttpResp!1)
Brian Wilkerson908708d2015-08-05 08:13:28 -0700847 }''',
848 <String>["1+HttpResponse"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000849
Brian Wilkerson908708d2015-08-05 08:13:28 -0700850 buildTests(
851 'testCommentSnippets083',
852 '''
853main() {(.!1)}''',
854 <String>["1-toString"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000855
Brian Wilkerson908708d2015-08-05 08:13:28 -0700856 buildTests(
857 'testCommentSnippets083a',
858 '''
859main() { .!1 }''',
860 <String>["1-toString"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000861
Brian Wilkerson908708d2015-08-05 08:13:28 -0700862 buildTests(
863 'testCommentSnippets083b',
864 '''
865main() { null.!1 }''',
866 <String>["1+toString"],
867 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000868
Brian Wilkerson908708d2015-08-05 08:13:28 -0700869 buildTests(
870 'testCommentSnippets084',
871 '''
872class List{}class Map{}typedef X = !1Lis!2t with !3Ma!4p;''',
873 <String>["1+Map", "2+List", "2-Map", "3+List", "4+Map", "4-List"],
874 failingTests: '1234');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000875
Brian Wilkerson908708d2015-08-05 08:13:28 -0700876 buildTests(
877 'testCommentSnippets085',
878 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000879class List{}class Map{}class Z extends List with !1Ma!2p {}''',
Brian Wilkerson908708d2015-08-05 08:13:28 -0700880 <String>["1+List", "1+Map", "2+Map", "2-List"],
881 failingTests: '12');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000882
Brian Wilkerson908708d2015-08-05 08:13:28 -0700883 buildTests(
884 'testCommentSnippets086',
885 '''
886class Q{f(){xy() {!2};x!1y();}}''',
887 <String>["1+xy", "2+f", "2-xy"],
paulberry@google.com87998482014-12-17 14:42:29 +0000888 failingTests: '2');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000889
Brian Wilkerson908708d2015-08-05 08:13:28 -0700890 buildTests(
891 'testCommentSnippets087',
892 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000893class Map{}class Q extends Object with !1Map {}''',
Brian Wilkerson908708d2015-08-05 08:13:28 -0700894 <String>["1+Map", "1-HashMap"],
895 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000896
Brian Wilkerson908708d2015-08-05 08:13:28 -0700897 buildTests(
898 'testCommentSnippets088',
899 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000900class A {
901 int f;
902 B m(){}
903}
904class B extends A {
905 num f;
906 A m(){}
907}
908class Z {
909 B q;
910 f() {q.!1}
Brian Wilkerson908708d2015-08-05 08:13:28 -0700911}''',
912 <String>["1+f", "1+m"]); // f->num, m()->A
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000913
Brian Wilkerson908708d2015-08-05 08:13:28 -0700914 buildTests(
915 'testCommentSnippets089',
916 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000917class Q {
918 fqe() {
919 xya() {
920 xyb() {
921 !1
922 }
923 !3 xyb();
924 };
925 xza() {
926 !2
927 }
928 xya();
929 !4 xza();
930 }
931 fqi() {
932 !5
933 }
Brian Wilkerson908708d2015-08-05 08:13:28 -0700934}''',
935 <String>[
936 "1+fqe",
937 "1+fqi",
938 "1+Q",
939 "1-xya",
940 "1-xyb",
941 "1-xza",
942 "2+fqe",
943 "2+fqi",
944 "2+Q",
945 "2-xya",
946 "2-xyb",
947 "2-xza",
948 "3+fqe",
949 "3+fqi",
950 "3+Q",
951 "3-xya",
952 "3+xyb",
953 "3-xza",
954 "4+fqe",
955 "4+fqi",
956 "4+Q",
957 "4+xya",
958 "4-xyb",
959 "4+xza",
960 "5+fqe",
961 "5+fqi",
962 "5+Q",
963 "5-xya",
964 "5-xyb",
965 "5-xza"
966 ],
967 failingTests: '123');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000968
Brian Wilkerson908708d2015-08-05 08:13:28 -0700969 buildTests(
970 'testCommentSnippets090',
971 '''
972class X { f() { var a = 'x'; a.!1 }}''',
973 <String>["1+length"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000974 }
975
976 void buildCompletionTests() {
Brian Wilkerson908708d2015-08-05 08:13:28 -0700977 buildTests(
978 'testCompletion_alias_field',
979 '''
980typedef int fnint(int k); fn!1int x;''',
981 <String>["1+fnint"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000982
Brian Wilkerson908708d2015-08-05 08:13:28 -0700983 buildTests(
984 'testCompletion_annotation_argumentList',
985 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000986class AAA {",
987 const AAA({int aaa, int bbb});",
988}",
989",
990@AAA(!1)
991main() {
Brian Wilkerson908708d2015-08-05 08:13:28 -0700992}''',
993 <String>[
994 "1+AAA" /*":" + ProposalKind.ARGUMENT_LIST*/,
995 "1+aaa",
996 "1+bbb"
997 ],
paulberry@google.com24611252014-12-09 16:44:12 +0000998 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +0000999
Brian Wilkerson908708d2015-08-05 08:13:28 -07001000 buildTests(
1001 'testCompletion_annotation_topLevelVar',
1002 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001003const fooConst = null;
1004final fooNotConst = null;
1005const bar = null;
1006
1007@foo!1
1008main() {
Brian Wilkerson908708d2015-08-05 08:13:28 -07001009}''',
1010 <String>["1+fooConst", "1-fooNotConst", "1-bar"],
1011 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001012
Brian Wilkerson908708d2015-08-05 08:13:28 -07001013 buildTests(
1014 'testCompletion_annotation_type',
1015 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001016class AAA {
1017 const AAA({int a, int b});
1018 const AAA.nnn(int c, int d);
1019}
1020@AAA!1
1021main() {
Brian Wilkerson908708d2015-08-05 08:13:28 -07001022}''',
1023 <String>[
1024 "1+AAA" /*":" + ProposalKind.CONSTRUCTOR*/,
1025 "1+AAA.nnn" /*":" + ProposalKind.CONSTRUCTOR*/
1026 ],
1027 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001028
Brian Wilkerson908708d2015-08-05 08:13:28 -07001029 buildTests(
1030 'testCompletion_annotation_type_inClass_withoutMember',
1031 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001032class AAA {
1033 const AAA();
1034}
1035
1036class C {
1037 @A!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001038}''',
1039 <String>["1+AAA" /*":" + ProposalKind.CONSTRUCTOR*/]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001040
Brian Wilkerson908708d2015-08-05 08:13:28 -07001041 buildTests(
1042 'testCompletion_argument_typeName',
1043 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001044class Enum {
1045 static Enum FOO = new Enum();
1046}
1047f(Enum e) {}
1048main() {
1049 f(En!1);
Brian Wilkerson908708d2015-08-05 08:13:28 -07001050}''',
1051 <String>["1+Enum"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001052
Brian Wilkerson908708d2015-08-05 08:13:28 -07001053 buildTests(
1054 'testCompletion_arguments_ignoreEmpty',
1055 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001056class A {
1057 test() {}
1058}
1059main(A a) {
1060 a.test(!1);
Brian Wilkerson908708d2015-08-05 08:13:28 -07001061}''',
1062 <String>["1-test"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001063
Brian Wilkerson908708d2015-08-05 08:13:28 -07001064 buildTests(
1065 'testCompletion_as_asIdentifierPrefix',
1066 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001067main(p) {
1068 var asVisible;
1069 var v = as!1;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001070}''',
1071 <String>["1+asVisible"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001072
Brian Wilkerson908708d2015-08-05 08:13:28 -07001073 buildTests(
1074 'testCompletion_as_asPrefixedIdentifierStart',
1075 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001076class A {
1077 var asVisible;
1078}
1079
1080main(A p) {
1081 var v = p.as!1;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001082}''',
1083 <String>["1+asVisible"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001084
Brian Wilkerson908708d2015-08-05 08:13:28 -07001085 buildTests(
1086 'testCompletion_as_incompleteStatement',
1087 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001088class MyClass {}
1089main(p) {
1090 var justSomeVar;
1091 var v = p as !1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001092}''',
1093 <String>["1+MyClass", "1-justSomeVar"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001094
Brian Wilkerson908708d2015-08-05 08:13:28 -07001095 buildTests(
1096 'testCompletion_cascade',
1097 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001098class A {
1099 aaa() {}
1100}
1101
1102
1103main(A a) {
1104 a..!1 aaa();
Brian Wilkerson908708d2015-08-05 08:13:28 -07001105}''',
1106 <String>["1+aaa", "1-main"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001107
Brian Wilkerson908708d2015-08-05 08:13:28 -07001108 buildTests(
1109 'testCompletion_combinator_afterComma',
1110 '''
danrubel372cb6b2015-12-06 15:34:19 -05001111import 'dart:math' show cos, !1;''',
1112 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001113
Brian Wilkerson908708d2015-08-05 08:13:28 -07001114 buildTests(
1115 'testCompletion_combinator_ended',
1116 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001117import 'dart:math' show !1;"''',
danrubel372cb6b2015-12-06 15:34:19 -05001118 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001119
Brian Wilkerson908708d2015-08-05 08:13:28 -07001120 buildTests(
1121 'testCompletion_combinator_export',
1122 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001123export 'dart:math' show !1;"''',
danrubel372cb6b2015-12-06 15:34:19 -05001124 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001125
Brian Wilkerson908708d2015-08-05 08:13:28 -07001126 buildTests(
1127 'testCompletion_combinator_hide',
1128 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001129import 'dart:math' hide !1;"''',
danrubel372cb6b2015-12-06 15:34:19 -05001130 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001131
Brian Wilkerson908708d2015-08-05 08:13:28 -07001132 buildTests(
1133 'testCompletion_combinator_notEnded',
1134 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001135import 'dart:math' show !1"''',
danrubel372cb6b2015-12-06 15:34:19 -05001136 <String>["1+PI", "1+sin", "1+Random", "1-String"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001137
Brian Wilkerson908708d2015-08-05 08:13:28 -07001138 buildTests(
1139 'testCompletion_combinator_usePrefix',
1140 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001141import 'dart:math' show s!1"''',
danrubel372cb6b2015-12-06 15:34:19 -05001142 <String>["1+sin", "1+sqrt", "1-cos", "1-String"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001143
Brian Wilkerson908708d2015-08-05 08:13:28 -07001144 buildTests(
1145 'testCompletion_constructor_field',
1146 '''
1147class X { X(this.field); int f!1ield;}''',
1148 <String>["1+field"],
danrubel@google.comddc3cae2014-12-16 16:53:24 +00001149 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001150
Brian Wilkerson908708d2015-08-05 08:13:28 -07001151 buildTests(
1152 'testCompletion_constructorArguments_showOnlyCurrent',
1153 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001154class A {
1155 A.first(int p);
1156 A.second(double p);
1157}
1158main() {
1159 new A.first(!1);
Brian Wilkerson908708d2015-08-05 08:13:28 -07001160}''',
1161 <String>["1+A.first", "1-A.second"],
1162 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001163
Brian Wilkerson908708d2015-08-05 08:13:28 -07001164 buildTests(
1165 'testCompletion_constructorArguments_whenPrefixedType',
1166 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001167import 'dart:math' as m;
1168main() {
1169 new m.Random(!1);
Brian Wilkerson908708d2015-08-05 08:13:28 -07001170}''',
1171 <String>["1+Random:ARGUMENT_LIST"],
1172 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001173
Brian Wilkerson908708d2015-08-05 08:13:28 -07001174 buildTests(
1175 'testCompletion_dartDoc_reference_forClass',
1176 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001177/**
1178 * [int!1]
1179 * [method!2]
1180 */
1181class AAA {
1182 methodA() {}
Brian Wilkerson908708d2015-08-05 08:13:28 -07001183}''',
1184 <String>["1+int", "1-method", "2+methodA", "2-int"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001185
Brian Wilkerson908708d2015-08-05 08:13:28 -07001186 buildTests(
1187 'testCompletion_dartDoc_reference_forConstructor',
1188 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001189class A {
1190 /**
1191 * [aa!1]
1192 * [int!2]
1193 * [method!3]
1194 */
1195 A.named(aaa, bbb) {}
1196 methodA() {}
Brian Wilkerson908708d2015-08-05 08:13:28 -07001197}''',
1198 <String>["1+aaa", "1-bbb", "2+int", "2-double", "3+methodA"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001199
Brian Wilkerson908708d2015-08-05 08:13:28 -07001200 buildTests(
1201 'testCompletion_dartDoc_reference_forFunction',
1202 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001203/**
1204 * [aa!1]
1205 * [int!2]
1206 * [function!3]
1207 */
1208functionA(aaa, bbb) {}
Brian Wilkerson908708d2015-08-05 08:13:28 -07001209functionB() {}''',
1210 <String>[
1211 "1+aaa",
1212 "1-bbb",
1213 "2+int",
1214 "2-double",
1215 "3+functionA",
1216 "3+functionB",
1217 "3-int"
1218 ],
1219 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001220
Brian Wilkerson908708d2015-08-05 08:13:28 -07001221 buildTests(
1222 'testCompletion_dartDoc_reference_forFunctionTypeAlias',
1223 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001224/**
1225 * [aa!1]
1226 * [int!2]
1227 * [Function!3]
1228 */
1229typedef FunctionA(aaa, bbb) {}
Brian Wilkerson908708d2015-08-05 08:13:28 -07001230typedef FunctionB() {}''',
1231 <String>[
1232 "1+aaa",
1233 "1-bbb",
1234 "2+int",
1235 "2-double",
1236 "3+FunctionA",
1237 "3+FunctionB",
1238 "3-int"
1239 ],
1240 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001241
Brian Wilkerson908708d2015-08-05 08:13:28 -07001242 buildTests(
1243 'testCompletion_dartDoc_reference_forMethod',
1244 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001245class A {
1246 /**
1247 * [aa!1]
1248 * [int!2]
1249 * [method!3]
1250 */
1251 methodA(aaa, bbb) {}
1252 methodB() {}
Brian Wilkerson908708d2015-08-05 08:13:28 -07001253}''',
1254 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -07001255 "1+aaa",
1256 "1-bbb",
1257 "2+int",
1258 "2-double",
1259 "3+methodA",
1260 "3+methodB",
1261 "3-int"
1262 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001263
Brian Wilkerson908708d2015-08-05 08:13:28 -07001264 buildTests(
1265 'testCompletion_dartDoc_reference_incomplete',
1266 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001267/**
1268 * [doubl!1 some text
1269 * other text
1270 */
1271class A {}
1272/**
1273 * [!2 some text
1274 * other text
1275 */
1276class B {}
1277/**
1278 * [!3] some text
1279 */
Brian Wilkerson908708d2015-08-05 08:13:28 -07001280class C {}''',
1281 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -07001282 "1+double",
1283 "1-int",
1284 "2+int",
1285 "2+String",
1286 "3+int",
1287 "3+String"
1288 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001289
Brian Wilkerson908708d2015-08-05 08:13:28 -07001290 buildTests(
1291 'testCompletion_double_inFractionPart',
1292 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001293main() {
1294 1.0!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001295}''',
1296 <String>["1-abs", "1-main"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001297
Brian Wilkerson908708d2015-08-05 08:13:28 -07001298 buildTests(
1299 'testCompletion_enum',
1300 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001301enum MyEnum {A, B, C}
1302main() {
1303 MyEnum.!1;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001304}''',
1305 <String>["1+values", "1+A", "1+B", "1+C"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001306
Brian Wilkerson908708d2015-08-05 08:13:28 -07001307 buildTests(
1308 'testCompletion_exactPrefix_hasHigherRelevance',
1309 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001310var STR;
1311main(p) {
1312 var str;
1313 str!1;
1314 STR!2;
1315 Str!3;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001316}''',
1317 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -07001318 "1+str" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 1)*/,
1319 "1+STR" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 0)*/,
1320 "2+STR" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 1)*/,
1321 "2+str" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 0)*/,
1322 "3+String" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 1)*/,
1323 "3+STR" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 0)*/,
1324 "3+str" /*",rel=" + (CompletionProposal.RELEVANCE_DEFAULT + 0)*/
1325 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001326
Brian Wilkerson908708d2015-08-05 08:13:28 -07001327 buildTests(
1328 'testCompletion_export_dart',
1329 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001330import 'dart:math
1331import 'dart:_chrome
1332import 'dart:_collection.dev
Brian Wilkerson908708d2015-08-05 08:13:28 -07001333export 'dart:!1''',
1334 <String>[
1335 "1+dart:core",
1336 "1+dart:math",
1337 "1-dart:_chrome",
1338 "1-dart:_collection.dev"
Dan Rubel02329592016-09-14 11:22:25 -04001339 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001340
Brian Wilkerson908708d2015-08-05 08:13:28 -07001341 buildTests(
1342 'testCompletion_export_noStringLiteral_noSemicolon',
1343 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001344import !1
1345
Brian Wilkerson908708d2015-08-05 08:13:28 -07001346class A {}''',
1347 <String>["1+'dart:!';", "1+'package:!';"],
1348 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001349
Brian Wilkerson908708d2015-08-05 08:13:28 -07001350 buildTests(
1351 'testCompletion_forStmt_vars',
1352 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001353class int{}class Foo { mth() { for (in!1t i = 0; i!2 < 5; i!3++); }}''',
danrubel@google.com676e0272015-03-12 21:40:55 +00001354 <String>["1+int", "2+i", "3+i"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001355
Brian Wilkerson908708d2015-08-05 08:13:28 -07001356 buildTests(
1357 'testCompletion_function',
1358 '''
danrubel@google.comddc3cae2014-12-16 16:53:24 +00001359class Foo { int boo = 7; mth() { PNGS.sort((String a, Str!1) => a.compareTo(b)); }}''',
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001360 <String>["1+String"]);
1361
Brian Wilkerson908708d2015-08-05 08:13:28 -07001362 buildTests(
1363 'testCompletion_function_partial',
1364 '''
danrubel@google.comddc3cae2014-12-16 16:53:24 +00001365class Foo { int boo = 7; mth() { PNGS.sort((String a, Str!1)); }}''',
1366 <String>["1+String"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001367
Brian Wilkerson908708d2015-08-05 08:13:28 -07001368 buildTests(
1369 'testCompletion_functionTypeParameter_namedArgument',
1370 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001371typedef FFF(a, b, {x1, x2, y});
1372main(FFF fff) {
1373 fff(1, 2, !1)!2;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001374}''',
1375 <String>["1+x1", "2-x2"],
1376 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001377
Brian Wilkerson908708d2015-08-05 08:13:28 -07001378 buildTests(
1379 'testCompletion_ifStmt_field1',
1380 '''
1381class Foo { int myField = 7; mth() { if (!1) {}}}''',
1382 <String>["1+myField"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001383
Brian Wilkerson908708d2015-08-05 08:13:28 -07001384 buildTests(
1385 'testCompletion_ifStmt_field1a',
1386 '''
1387class Foo { int myField = 7; mth() { if (!1) }}''',
1388 <String>["1+myField"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001389
Brian Wilkerson908708d2015-08-05 08:13:28 -07001390 buildTests(
1391 'testCompletion_ifStmt_field2',
1392 '''
1393class Foo { int myField = 7; mth() { if (m!1) {}}}''',
1394 <String>["1+myField"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001395
Brian Wilkerson908708d2015-08-05 08:13:28 -07001396 buildTests(
1397 'testCompletion_ifStmt_field2a',
1398 '''
1399class Foo { int myField = 7; mth() { if (m!1) }}''',
1400 <String>["1+myField"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001401
Brian Wilkerson908708d2015-08-05 08:13:28 -07001402 buildTests(
1403 'testCompletion_ifStmt_field2b',
1404 '''
1405class Foo { myField = 7; mth() { if (m!1) {}}}''',
1406 <String>["1+myField"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001407
Brian Wilkerson908708d2015-08-05 08:13:28 -07001408 buildTests(
1409 'testCompletion_ifStmt_localVar',
1410 '''
1411class Foo { mth() { int value = 7; if (v!1) {}}}''',
1412 <String>["1+value"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001413
Brian Wilkerson908708d2015-08-05 08:13:28 -07001414 buildTests(
1415 'testCompletion_ifStmt_localVara',
1416 '''
1417class Foo { mth() { value = 7; if (v!1) {}}}''',
1418 <String>["1-value"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001419
Brian Wilkerson908708d2015-08-05 08:13:28 -07001420 buildTests(
1421 'testCompletion_ifStmt_topLevelVar',
1422 '''
1423int topValue = 7; class Foo { mth() { if (t!1) {}}}''',
1424 <String>["1+topValue"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001425
Brian Wilkerson908708d2015-08-05 08:13:28 -07001426 buildTests(
1427 'testCompletion_ifStmt_topLevelVara',
1428 '''
1429topValue = 7; class Foo { mth() { if (t!1) {}}}''',
1430 <String>["1+topValue"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001431
Brian Wilkerson908708d2015-08-05 08:13:28 -07001432 buildTests(
1433 'testCompletion_ifStmt_unionType_nonStrict',
1434 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001435class A { a() => null; x() => null}
1436class B { a() => null; y() => null}
1437void main() {
1438 var x;
1439 var c;
1440 if(c) {
1441 x = new A();
1442 } else {
1443 x = new B();
1444 }
1445 x.!1;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001446}''',
1447 <String>["1+a", "1+x", "1+y"],
1448 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001449
Brian Wilkerson908708d2015-08-05 08:13:28 -07001450 buildTests(
1451 'testCompletion_ifStmt_unionType_strict',
1452 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001453class A { a() => null; x() => null}
1454class B { a() => null; y() => null}
1455void main() {
1456 var x;
1457 var c;
1458 if(c) {
1459 x = new A();
1460 } else {
1461 x = new B();
1462 }
1463 x.!1;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001464}''',
1465 <String>["1+a", "1-x", "1-y"],
1466 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001467
Brian Wilkerson908708d2015-08-05 08:13:28 -07001468 buildTests(
1469 'testCompletion_import',
1470 '''
1471import '!1';''',
1472 <String>["1+dart:!", "1+package:!"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001473
Brian Wilkerson908708d2015-08-05 08:13:28 -07001474 buildTests(
1475 'testCompletion_import_dart',
1476 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001477import 'dart:math
1478import 'dart:_chrome
1479import 'dart:_collection.dev
Brian Wilkerson908708d2015-08-05 08:13:28 -07001480import 'dart:!1''',
1481 <String>[
1482 "1+dart:core",
1483 "1+dart:math",
1484 "1-dart:_chrome",
1485 "1-dart:_collection.dev"
Dan Rubel02329592016-09-14 11:22:25 -04001486 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001487
Brian Wilkerson908708d2015-08-05 08:13:28 -07001488 buildTests(
1489 'testCompletion_import_hasStringLiteral_noSemicolon',
1490 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001491import '!1'
1492
Brian Wilkerson908708d2015-08-05 08:13:28 -07001493class A {}''',
1494 <String>["1+dart:!", "1+package:!"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001495
Brian Wilkerson908708d2015-08-05 08:13:28 -07001496 buildTests(
1497 'testCompletion_import_noSpace',
1498 '''
1499import!1''',
1500 <String>["1+ 'dart:!';", "1+ 'package:!';"],
1501 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001502
Brian Wilkerson908708d2015-08-05 08:13:28 -07001503 buildTests(
1504 'testCompletion_import_noStringLiteral',
1505 '''
1506import !1;''',
1507 <String>["1+'dart:!'", "1+'package:!'"],
1508 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001509
Brian Wilkerson908708d2015-08-05 08:13:28 -07001510 buildTests(
1511 'testCompletion_import_noStringLiteral_noSemicolon',
1512 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001513import !1
1514
Brian Wilkerson908708d2015-08-05 08:13:28 -07001515class A {}''',
1516 <String>["1+'dart:!';", "1+'package:!';"],
1517 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001518
Brian Wilkerson908708d2015-08-05 08:13:28 -07001519 buildTests(
1520 'testCompletion_incompleteClassMember',
1521 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001522class A {
1523 Str!1
1524 final f = null;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001525}''',
1526 <String>["1+String", "1-bool"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001527
Brian Wilkerson908708d2015-08-05 08:13:28 -07001528 buildTests(
1529 'testCompletion_incompleteClosure_parameterType',
1530 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001531f1(cb(String s)) {}
1532f2(String s) {}
1533main() {
1534 f1((Str!1));
1535 f2((Str!2));
Brian Wilkerson908708d2015-08-05 08:13:28 -07001536}''',
1537 <String>["1+String", "1-bool", "2+String", "2-bool"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001538
Brian Wilkerson908708d2015-08-05 08:13:28 -07001539 buildTests(
1540 'testCompletion_inPeriodPeriod',
1541 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001542main(String str) {
1543 1 < str.!1.length;
1544 1 + str.!2.length;
1545 1 + 2 * str.!3.length;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001546}''',
1547 <String>["1+codeUnits", "2+codeUnits", "3+codeUnits"],
paulberry@google.com24611252014-12-09 16:44:12 +00001548 failingTests: '123');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001549
1550 // no checks, but no exceptions
Brian Wilkerson908708d2015-08-05 08:13:28 -07001551 buildTests(
1552 'testCompletion_instanceCreation_unresolved',
1553 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001554class A {
1555}
1556main() {
1557 new NoSuchClass(!1);
1558 new A.noSuchConstructor(!2);
Brian Wilkerson908708d2015-08-05 08:13:28 -07001559}''',
1560 <String>["1+int", "2+int"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001561
Brian Wilkerson908708d2015-08-05 08:13:28 -07001562 buildTests(
1563 'testCompletion_import_lib',
1564 '''
1565import '!1''',
1566 <String>["1+my_lib.dart"],
1567 extraFiles: <String, String>{"/my_lib.dart": ""},
1568 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001569
Brian Wilkerson908708d2015-08-05 08:13:28 -07001570 buildTests(
1571 'testCompletion_is',
1572 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001573class MyClass {}
1574main(p) {
1575 var isVariable;
1576 if (p is MyCla!1) {}
1577 var v1 = p is MyCla!2;
1578 var v2 = p is !3;
1579 var v2 = p is!4;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001580}''',
1581 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -07001582 "1+MyClass",
1583 "2+MyClass",
1584 "3+MyClass",
1585 "3-v1",
1586 "4+is",
1587 "4-isVariable"
1588 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001589
Brian Wilkerson908708d2015-08-05 08:13:28 -07001590 buildTests(
1591 'testCompletion_is_asIdentifierStart',
1592 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001593main(p) {
1594 var isVisible;
1595 var v1 = is!1;
1596 var v2 = is!2
Brian Wilkerson908708d2015-08-05 08:13:28 -07001597}''',
1598 <String>["1+isVisible", "2+isVisible"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001599
Brian Wilkerson908708d2015-08-05 08:13:28 -07001600 buildTests(
1601 'testCompletion_is_asPrefixedIdentifierStart',
1602 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001603class A {
1604 var isVisible;
1605}
1606
1607main(A p) {
1608 var v1 = p.is!1;
1609 var v2 = p.is!2
Brian Wilkerson908708d2015-08-05 08:13:28 -07001610}''',
1611 <String>["1+isVisible", "2+isVisible"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001612
Brian Wilkerson908708d2015-08-05 08:13:28 -07001613 buildTests(
1614 'testCompletion_is_incompleteStatement1',
1615 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001616class MyClass {}
1617main(p) {
1618 var justSomeVar;
1619 var v = p is !1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001620}''',
1621 <String>["1+MyClass", "1-justSomeVar"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001622
Brian Wilkerson908708d2015-08-05 08:13:28 -07001623 buildTests(
1624 'testCompletion_is_incompleteStatement2',
1625 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001626class MyClass {}
1627main(p) {
1628 var isVariable;
1629 var v = p is!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001630}''',
Dan Rubelbd95b132015-08-26 17:34:57 -04001631 <String>["1+is", "1-isVariable"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001632
Brian Wilkerson908708d2015-08-05 08:13:28 -07001633 buildTests(
1634 'testCompletion_keyword_in',
1635 '''
1636class Foo { int input = 7; mth() { if (in!1) {}}}''',
1637 <String>["1+input"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001638
Brian Wilkerson908708d2015-08-05 08:13:28 -07001639 buildTests(
1640 'testCompletion_keyword_syntheticIdentifier',
1641 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001642main() {
1643 var caseVar;
1644 var otherVar;
1645 var v = case!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001646}''',
1647 <String>["1+caseVar", "1-otherVar"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001648
Brian Wilkerson908708d2015-08-05 08:13:28 -07001649 buildTests(
1650 'testCompletion_libraryIdentifier_atEOF',
1651 '''
1652library int.!1''',
1653 <String>["1-parse", "1-bool"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001654
Brian Wilkerson908708d2015-08-05 08:13:28 -07001655 buildTests(
1656 'testCompletion_libraryIdentifier_notEOF',
1657 '''
1658library int.!1''',
1659 <String>["1-parse", "1-bool"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001660
Brian Wilkerson908708d2015-08-05 08:13:28 -07001661 buildTests(
1662 'testCompletion_methodRef_asArg_incompatibleFunctionType',
1663 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001664foo( f(int p) ) {}
1665class Functions {
1666 static myFuncInt(int p) {}
1667 static myFuncDouble(double p) {}
1668}
1669bar(p) {}
1670main(p) {
1671 foo( Functions.!1; );
Brian Wilkerson908708d2015-08-05 08:13:28 -07001672}''',
1673 <String>[
1674 "1+myFuncInt" /*":" + ProposalKind.METHOD_NAME*/,
1675 "1-myFuncDouble" /*":" + ProposalKind.METHOD_NAME*/
1676 ],
1677 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001678
Brian Wilkerson908708d2015-08-05 08:13:28 -07001679 buildTests(
1680 'testCompletion_methodRef_asArg_notFunctionType',
1681 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001682foo( f(int p) ) {}
1683class Functions {
1684 static myFunc(int p) {}
1685}
1686bar(p) {}
1687main(p) {
1688 foo( (int p) => Functions.!1; );
Brian Wilkerson908708d2015-08-05 08:13:28 -07001689}''',
1690 <String>[
1691 "1+myFunc" /*":" + ProposalKind.METHOD*/,
1692 "1-myFunc" /*":" + ProposalKind.METHOD_NAME*/
1693 ],
1694 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001695
Brian Wilkerson908708d2015-08-05 08:13:28 -07001696 buildTests(
1697 'testCompletion_methodRef_asArg_ofFunctionType',
1698 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001699foo( f(int p) ) {}
1700class Functions {
1701 static int myFunc(int p) {}
1702}
1703main(p) {
1704 foo(Functions.!1);
Brian Wilkerson908708d2015-08-05 08:13:28 -07001705}''',
1706 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -07001707 "1+myFunc" /*":" + ProposalKind.METHOD*/,
1708 "1+myFunc" /*":" + ProposalKind.METHOD_NAME*/
1709 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001710
Brian Wilkerson908708d2015-08-05 08:13:28 -07001711 buildTests(
1712 'testCompletion_namedArgument_alreadyUsed',
1713 '''
1714func({foo}) {} main() { func(foo: 0, fo!1); }''',
1715 <String>["1-foo"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001716
Brian Wilkerson908708d2015-08-05 08:13:28 -07001717 buildTests(
1718 'testCompletion_namedArgument_constructor',
1719 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001720class A {A({foo, bar}) {}} main() { new A(fo!1); }''',
Brian Wilkerson908708d2015-08-05 08:13:28 -07001721 <String>["1+foo", "1-bar"],
1722 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001723
Brian Wilkerson908708d2015-08-05 08:13:28 -07001724 buildTests(
1725 'testCompletion_namedArgument_empty',
1726 '''
1727func({foo, bar}) {} main() { func(!1); }''',
1728 <String>[
1729 "1+foo" /*":" + ProposalKind.NAMED_ARGUMENT*/,
1730 "1-foo" /*":" + ProposalKind.OPTIONAL_ARGUMENT*/
1731 ],
1732 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001733
Brian Wilkerson908708d2015-08-05 08:13:28 -07001734 buildTests(
1735 'testCompletion_namedArgument_function',
1736 '''
danrubel@google.com7c9de022015-03-03 16:51:18 +00001737func({foo, bar}) {} main() { func(fo!1); }''',
Brian Wilkerson908708d2015-08-05 08:13:28 -07001738 <String>["1+foo", "1-bar"],
1739 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001740
Brian Wilkerson908708d2015-08-05 08:13:28 -07001741 buildTests(
1742 'testCompletion_namedArgument_notNamed',
1743 '''
1744func([foo]) {} main() { func(fo!1); }''',
1745 <String>["1-foo"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001746
Brian Wilkerson908708d2015-08-05 08:13:28 -07001747 buildTests(
1748 'testCompletion_namedArgument_unresolvedFunction',
1749 '''
1750main() { func(fo!1); }''',
1751 <String>["1-foo"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001752
Brian Wilkerson908708d2015-08-05 08:13:28 -07001753 buildTests(
1754 'testCompletion_newMemberType1',
1755 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001756class Collection{}class List extends Collection{}class Foo { !1 }''',
danrubel@google.com676e0272015-03-12 21:40:55 +00001757 <String>["1+Collection", "1+List"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001758
Brian Wilkerson908708d2015-08-05 08:13:28 -07001759 buildTests(
1760 'testCompletion_newMemberType2',
1761 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001762class Collection{}class List extends Collection{}class Foo {!1}''',
danrubel@google.com676e0272015-03-12 21:40:55 +00001763 <String>["1+Collection", "1+List"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001764
Brian Wilkerson908708d2015-08-05 08:13:28 -07001765 buildTests(
1766 'testCompletion_newMemberType3',
1767 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001768class Collection{}class List extends Collection{}class Foo {L!1}''',
danrubel@google.com676e0272015-03-12 21:40:55 +00001769 <String>["1-Collection", "1+List"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001770
Brian Wilkerson908708d2015-08-05 08:13:28 -07001771 buildTests(
1772 'testCompletion_newMemberType4',
1773 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001774class Collection{}class List extends Collection{}class Foo {C!1}''',
1775 <String>["1+Collection", "1-List"]);
1776
Brian Wilkerson908708d2015-08-05 08:13:28 -07001777 buildTests(
1778 'testCompletion_positionalArgument_constructor',
1779 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001780class A {
1781 A([foo, bar]);
1782}
1783main() {
1784 new A(!1);
1785 new A(0, !2);
Brian Wilkerson908708d2015-08-05 08:13:28 -07001786}''',
1787 <String>[
1788 "1+foo" /*":" + ProposalKind.OPTIONAL_ARGUMENT*/,
1789 "1-bar",
1790 "2-foo",
1791 "2+bar" /*":"
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00001792 + ProposalKind.OPTIONAL_ARGUMENT*/
Brian Wilkerson908708d2015-08-05 08:13:28 -07001793 ],
1794 failingTests: '12');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001795
Brian Wilkerson908708d2015-08-05 08:13:28 -07001796 buildTests(
1797 'testCompletion_positionalArgument_function',
1798 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001799func([foo, bar]) {}
1800main() {
1801 func(!1);
1802 func(0, !2);
Brian Wilkerson908708d2015-08-05 08:13:28 -07001803}''',
1804 <String>[
1805 "1+foo" /*":" + ProposalKind.OPTIONAL_ARGUMENT*/,
1806 "1-bar",
1807 "2-foo",
1808 "2+bar" /*":"
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00001809 + ProposalKind.OPTIONAL_ARGUMENT*/
Brian Wilkerson908708d2015-08-05 08:13:28 -07001810 ],
1811 failingTests: '12');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001812
Brian Wilkerson908708d2015-08-05 08:13:28 -07001813 buildTests(
1814 'testCompletion_preferStaticType',
1815 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001816class A {
1817 foo() {}
1818}
1819class B extends A {
1820 bar() {}
1821}
1822main() {
1823 A v = new B();
1824 v.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001825}''',
1826 <String>[
1827 "1+foo",
1828 "1-bar,potential=false,declaringType=B",
1829 "1+bar,potential=true,declaringType=B"
1830 ],
1831 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001832
Brian Wilkerson908708d2015-08-05 08:13:28 -07001833 buildTests(
1834 'testCompletion_privateElement_sameLibrary_constructor',
1835 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001836class A {
1837 A._c();
1838 A.c();
1839}
1840main() {
1841 new A.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001842}''',
1843 <String>["1+_c", "1+c"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001844
Brian Wilkerson908708d2015-08-05 08:13:28 -07001845 buildTests(
1846 'testCompletion_privateElement_sameLibrary_member',
1847 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001848class A {
1849 _m() {}
1850 m() {}
1851}
1852main(A a) {
1853 a.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001854}''',
1855 <String>["1+_m", "1+m"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001856
Brian Wilkerson908708d2015-08-05 08:13:28 -07001857 buildTests(
1858 'testCompletion_propertyAccess_whenClassTarget',
1859 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001860class A {
1861 static int FIELD;
1862 int field;
1863}
1864main() {
1865 A.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001866}''',
1867 <String>["1+FIELD", "1-field"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001868
Brian Wilkerson908708d2015-08-05 08:13:28 -07001869 buildTests(
1870 'testCompletion_propertyAccess_whenClassTarget_excludeSuper',
1871 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001872class A {
1873 static int FIELD_A;
1874 static int methodA() {}
1875}
1876class B extends A {
1877 static int FIELD_B;
1878 static int methodB() {}
1879}
1880main() {
1881 B.!1;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001882}''',
Dan Rubel824a0122015-12-09 14:37:03 -05001883 <String>["1+FIELD_B", "1-FIELD_A", "1+methodB", "1-methodA"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001884
Brian Wilkerson908708d2015-08-05 08:13:28 -07001885 buildTests(
1886 'testCompletion_propertyAccess_whenInstanceTarget',
1887 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001888class A {
1889 static int FIELD;
1890 int fieldA;
1891}
1892class B {
1893 A a;
1894}
1895class C extends A {
1896 int fieldC;
1897}
1898main(B b, C c) {
1899 b.a.!1;
1900 c.!2;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001901}''',
1902 <String>["1-FIELD", "1+fieldA", "2+fieldC", "2+fieldA"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001903
Brian Wilkerson908708d2015-08-05 08:13:28 -07001904 buildTests(
1905 'testCompletion_return_withIdentifierPrefix',
1906 '''
1907f() { var vvv = 42; return v!1 }''',
1908 <String>["1+vvv"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001909
Brian Wilkerson908708d2015-08-05 08:13:28 -07001910 buildTests(
1911 'testCompletion_return_withoutExpression',
1912 '''
1913f() { var vvv = 42; return !1 }''',
1914 <String>["1+vvv"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001915
Brian Wilkerson908708d2015-08-05 08:13:28 -07001916 buildTests(
1917 'testCompletion_staticField1',
1918 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001919class num{}class Sunflower {static final n!2um MAX_D = 300;nu!3m xc, yc;Sun!4flower() {x!Xc = y!Yc = MA!1 }}''',
danrubel@google.com25c6bba2015-04-20 15:29:28 +00001920 <String>["1+MAX_D", "X+xc", "Y+yc", "2+num", "3+num", "4+Sunflower"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001921
Brian Wilkerson908708d2015-08-05 08:13:28 -07001922 buildTests(
1923 'testCompletion_super_superType',
1924 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001925class A {
1926 var fa;
1927 ma() {}
1928}
1929class B extends A {
1930 var fb;
1931 mb() {}
1932 main() {
1933 super.!1
1934 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07001935}''',
1936 <String>["1+fa", "1-fb", "1+ma", "1-mb"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001937
Brian Wilkerson908708d2015-08-05 08:13:28 -07001938 buildTests(
1939 'testCompletion_superConstructorInvocation_noNamePrefix',
1940 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001941class A {
1942 A.fooA();
1943 A.fooB();
1944 A.bar();
1945}
1946class B extends A {
1947 B() : super.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001948}''',
1949 <String>["1+fooA", "1+fooB", "1+bar"],
1950 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001951
Brian Wilkerson908708d2015-08-05 08:13:28 -07001952 buildTests(
1953 'testCompletion_superConstructorInvocation_withNamePrefix',
1954 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001955class A {
1956 A.fooA();
1957 A.fooB();
1958 A.bar();
1959}
1960class B extends A {
1961 B() : super.f!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07001962}''',
1963 <String>["1+fooA", "1+fooB", "1-bar"],
1964 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001965
Brian Wilkerson908708d2015-08-05 08:13:28 -07001966 buildTests(
1967 'testCompletion_this_bad_inConstructorInitializer',
1968 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001969class A {
1970 var f;
1971 A() : f = this.!1;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001972}''',
1973 <String>["1-toString"],
1974 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001975
Brian Wilkerson908708d2015-08-05 08:13:28 -07001976 buildTests(
1977 'testCompletion_this_bad_inFieldDeclaration',
1978 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001979class A {
1980 var f = this.!1;
Brian Wilkerson908708d2015-08-05 08:13:28 -07001981}''',
1982 <String>["1-toString"],
1983 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001984
Brian Wilkerson908708d2015-08-05 08:13:28 -07001985 buildTests(
1986 'testCompletion_this_bad_inStaticMethod',
1987 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001988class A {
1989 static m() {
1990 this.!1;
1991 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07001992}''',
1993 <String>["1-toString"],
1994 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001995
Brian Wilkerson908708d2015-08-05 08:13:28 -07001996 buildTests(
1997 'testCompletion_this_bad_inTopLevelFunction',
1998 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00001999main() {
2000 this.!1;
Brian Wilkerson908708d2015-08-05 08:13:28 -07002001}''',
2002 <String>["1-toString"],
2003 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002004
Brian Wilkerson908708d2015-08-05 08:13:28 -07002005 buildTests(
2006 'testCompletion_this_bad_inTopLevelVariableDeclaration',
2007 '''
2008var v = this.!1;''',
2009 <String>["1-toString"],
2010 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002011
Brian Wilkerson908708d2015-08-05 08:13:28 -07002012 buildTests(
2013 'testCompletion_this_OK_inConstructorBody',
2014 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002015class A {
2016 var f;
2017 m() {}
2018 A() {
2019 this.!1;
2020 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002021}''',
2022 <String>["1+f", "1+m"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002023
Brian Wilkerson908708d2015-08-05 08:13:28 -07002024 buildTests(
2025 'testCompletion_this_OK_localAndSuper',
2026 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002027class A {
2028 var fa;
2029 ma() {}
2030}
2031class B extends A {
2032 var fb;
2033 mb() {}
2034 main() {
2035 this.!1
2036 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002037}''',
2038 <String>["1+fa", "1+fb", "1+ma", "1+mb"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002039
Brian Wilkerson908708d2015-08-05 08:13:28 -07002040 buildTests(
2041 'testCompletion_topLevelField_init2',
2042 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002043class DateTime{static var JUN;}final num M = Dat!1eTime.JUN;''',
danrubel@google.com676e0272015-03-12 21:40:55 +00002044 <String>["1+DateTime", "1-void"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002045
Brian Wilkerson908708d2015-08-05 08:13:28 -07002046 buildTests(
2047 'testCompletion_while',
2048 '''
2049class Foo { int boo = 7; mth() { while (b!1) {} }}''',
2050 <String>["1+boo"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002051 }
2052
2053 void buildLibraryTests() {
2054 Map<String, String> sources = new HashMap<String, String>();
2055
Brian Wilkerson908708d2015-08-05 08:13:28 -07002056 buildTests(
2057 'test_export_ignoreIfThisLibraryExports',
2058 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002059export 'dart:math';
2060libFunction() {};
2061main() {
2062 !1
Brian Wilkerson908708d2015-08-05 08:13:28 -07002063}''',
2064 <String>["1-cos", "1+libFunction"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002065
2066 sources.clear();
2067 sources["/lib.dart"] = '''
2068library lib;
2069export 'dart:math' hide sin;
2070libFunction() {};''';
Brian Wilkerson908708d2015-08-05 08:13:28 -07002071 buildTests(
2072 'test_export_showIfImportLibraryWithExport',
2073 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002074import 'lib.dart' as p;
2075main() {
2076 p.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07002077}''',
2078 <String>["1+cos", "1-sin", "1+libFunction"],
2079 extraFiles: sources,
2080 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002081
Brian Wilkerson908708d2015-08-05 08:13:28 -07002082 buildTests(
2083 'test_importPrefix_hideCombinator',
2084 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002085import 'dart:math' as math hide PI;
2086main() {
2087 math.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07002088}''',
2089 <String>["1-PI", "1+LN10"],
2090 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002091
Brian Wilkerson908708d2015-08-05 08:13:28 -07002092 buildTests(
2093 'test_importPrefix_showCombinator',
2094 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002095import 'dart:math' as math show PI;
2096main() {
2097 math.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07002098}''',
2099 <String>["1+PI", "1-LN10"],
2100 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002101
2102 sources.clear();
2103 sources["/lib.dart"] = '''
2104library lib
danrubel85334be2015-11-23 11:15:22 -05002105class _A
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002106 foo() {}
2107
2108class A extends _A {
2109}''';
Brian Wilkerson908708d2015-08-05 08:13:28 -07002110 buildTests(
2111 'test_memberOfPrivateClass_otherLibrary',
2112 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002113import 'lib.dart';
2114main(A a) {
2115 a.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07002116}''',
2117 <String>["1+foo"],
2118 extraFiles: sources,
2119 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002120
2121 sources.clear();
2122 sources["/lib.dart"] = '''
2123library lib;
2124class A {
2125 A.c();
2126 A._c();
2127}''';
Brian Wilkerson908708d2015-08-05 08:13:28 -07002128 buildTests(
2129 'test_noPrivateElement_otherLibrary_constructor',
2130 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002131import 'lib.dart';
2132main() {
2133 new A.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07002134}''',
2135 <String>["1-_c", "1+c"],
2136 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002137
2138 sources.clear();
2139 sources["/lib.dart"] = '''
2140library lib;
2141class A {
2142 var f;
2143 var _f;
2144}''';
Brian Wilkerson908708d2015-08-05 08:13:28 -07002145 buildTests(
2146 'test_noPrivateElement_otherLibrary_member',
2147 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002148 import 'lib.dart';
2149 main(A a) {
2150 a.!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07002151 }''',
2152 <String>["1-_f", "1+f"],
2153 extraFiles: sources,
2154 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002155
2156 sources.clear();
2157 sources["/firth.dart"] = '''
2158library firth;
2159class SerializationException {
2160 const SerializationException();
2161}''';
Brian Wilkerson908708d2015-08-05 08:13:28 -07002162 buildTests(
2163 'testLibrary001',
2164 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002165import 'firth.dart';
2166main() {
Brian Wilkerson908708d2015-08-05 08:13:28 -07002167throw new Seria!1lizationException();}''',
2168 <String>["1+SerializationException"],
2169 extraFiles: sources,
2170 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002171
2172 // Type propagation.
2173 // TODO Include corelib analysis (this works in the editor)
Brian Wilkerson908708d2015-08-05 08:13:28 -07002174 buildTests(
2175 'testLibrary002',
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002176 '''t2() {var q=[0],z=q.!1length;q.!2clear();}''',
Brian Wilkerson908708d2015-08-05 08:13:28 -07002177 <String>["1+length", "1+isEmpty", "2+clear"],
2178 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002179
2180 // TODO Include corelib analysis
Brian Wilkerson908708d2015-08-05 08:13:28 -07002181 buildTests('testLibrary003', '''class X{var q; f() {q.!1a!2}}''',
2182 <String>["1+end", "2+abs", "2-end"],
2183 failingTests: '12');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002184
2185 // TODO Include corelib analysis
2186 // Resolving dart:html takes between 2.5s and 30s; json, about 0.12s
Brian Wilkerson908708d2015-08-05 08:13:28 -07002187 buildTests(
2188 'testLibrary004',
2189 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002190 library foo;
2191 import 'dart:convert' as json;
paulberry@google.comdfb35c02014-12-19 17:02:18 +00002192 class JsonDecoderX{}
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002193 f1() {var x=new json.!1}
paulberry@google.comdfb35c02014-12-19 17:02:18 +00002194 f2() {var x=new json.JsonDe!2}
Brian Wilkerson908708d2015-08-05 08:13:28 -07002195 f3() {var x=new json.JsonDecoder!3}''',
2196 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -07002197 "1+JsonDecoder",
2198 "1-JsonDecoderX",
2199 "2+JsonDecoder",
2200 "2-JsonDecoderX",
2201 "3+JsonDecoder",
2202 "3-JsonDecoderX"
2203 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002204
2205 // TODO Enable after type propagation is implemented. Not yet.
2206 // TODO Include corelib analysis
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002207 buildTests('testLibrary005',
Brian Wilkerson908708d2015-08-05 08:13:28 -07002208 '''var PHI;main(){PHI=5.3;PHI.abs().!1 Object x;}''', <String>["1+abs"],
2209 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002210
2211 // Exercise import and export handling.
2212 // Libraries are defined in partial order of increasing dependency.
2213 sources.clear();
2214 sources["/exp2a.dart"] = '''
2215library exp2a;
2216e2a() {}''';
2217 sources["/exp1b.dart"] = '''
2218library exp1b;",
2219e1b() {}''';
2220 sources["/exp1a.dart"] = '''
2221library exp1a;",
2222export 'exp1b.dart';",
2223e1a() {}''';
2224 sources["/imp1.dart"] = '''
2225library imp1;
2226export 'exp1a.dart';
2227i1() {}''';
2228 sources["/imp2.dart"] = '''
2229library imp2;
2230export 'exp2a.dart';
2231i2() {}''';
Brian Wilkerson908708d2015-08-05 08:13:28 -07002232 buildTests(
2233 'testLibrary006',
2234 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002235import 'imp1.dart';
2236import 'imp2.dart';
2237main() {!1
2238 i1();
2239 i2();
2240 e1a();
2241 e1b();
2242 e2a();
Brian Wilkerson908708d2015-08-05 08:13:28 -07002243}''',
2244 <String>["1+i1", "1+i2", "1+e1a", "1+e2a", "1+e1b"],
2245 extraFiles: sources,
2246 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002247
2248 // Exercise import and export handling.
2249 // Libraries are defined in partial order of increasing dependency.
2250 sources.clear();
2251 sources["/l1.dart"] = '''
2252library l1;
2253var _l1t; var l1t;''';
Brian Wilkerson908708d2015-08-05 08:13:28 -07002254 buildTests(
2255 'testLibrary007',
2256 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002257import 'l1.dart';
2258main() {
2259 var x = l!1
2260 var y = _!2
Brian Wilkerson908708d2015-08-05 08:13:28 -07002261}''',
2262 <String>["1+l1t", "1-_l1t", "2-_l1t"],
2263 extraFiles: sources,
2264 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002265
2266 // Check private library exclusion
2267 sources.clear();
2268 sources["/public.dart"] = '''
2269library public;
2270class NonPrivate {
2271 void publicMethod() {
2272 }
2273}''';
2274 sources["/private.dart"] = '''
2275library _private;
2276import 'public.dart';
2277class Private extends NonPrivate {
2278 void privateMethod() {
2279 }
2280}''';
Brian Wilkerson908708d2015-08-05 08:13:28 -07002281 buildTests(
2282 'testLibrary008',
2283 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002284import 'private.dart';
2285import 'public.dart';
2286class Test {
2287 void test() {
2288 NonPrivate x = new NonPrivate();
2289 x.!1 //publicMethod but not privateMethod should appear
2290 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002291}''',
2292 <String>["1-privateMethod", "1+publicMethod"],
2293 extraFiles: sources,
2294 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002295
2296 // Exercise library prefixes.
2297 sources.clear();
2298 sources["/lib.dart"] = '''
2299library lib;
2300int X = 1;
2301void m(){}
2302class Y {}''';
Brian Wilkerson908708d2015-08-05 08:13:28 -07002303 buildTests(
2304 'testLibrary009',
2305 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002306import 'lib.dart' as Q;
2307void a() {
2308 var x = Q.!1
2309}
2310void b() {
2311 var x = [Q.!2]
2312}
2313void c() {
2314 var x = new List([Q.!3])
2315}
2316void d() {
2317 new Q.!4
Brian Wilkerson908708d2015-08-05 08:13:28 -07002318}''',
2319 <String>[
2320 "1+X",
2321 "1+m",
2322 "1+Y",
2323 "2+X",
2324 "2+m",
2325 "2+Y",
2326 "3+X",
2327 "3+m",
2328 "3+Y",
2329 "4+Y",
2330 "4-m",
2331 "4-X"
2332 ],
2333 extraFiles: sources,
2334 failingTests: '1234');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002335 }
2336
2337 void buildNumberedTests() {
Brian Wilkerson908708d2015-08-05 08:13:28 -07002338 buildTests(
2339 'test001',
2340 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002341void r1(var v) {
2342 v.!1toString!2().!3hash!4Code
Brian Wilkerson908708d2015-08-05 08:13:28 -07002343}''',
2344 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -07002345 "1+toString",
2346 "1-==",
2347 "2+toString",
2348 "3+hashCode",
2349 "3+toString",
2350 "4+hashCode",
2351 "4-toString"
2352 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002353
Brian Wilkerson908708d2015-08-05 08:13:28 -07002354 buildTests(
2355 'test002',
2356 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002357void r2(var vim) {
2358 v!1.toString()
Brian Wilkerson908708d2015-08-05 08:13:28 -07002359}''',
2360 <String>["1+vim"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002361
Brian Wilkerson908708d2015-08-05 08:13:28 -07002362 buildTests(
2363 'test003',
2364 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002365class A {
2366 int a() => 3;
2367 int b() => this.!1a();
Brian Wilkerson908708d2015-08-05 08:13:28 -07002368}''',
2369 <String>["1+a"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002370
Brian Wilkerson908708d2015-08-05 08:13:28 -07002371 buildTests(
2372 'test004',
2373 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002374class A {
2375 int x;
2376 A() : this.!1x = 1;
2377 A.b() : this();
2378 A.c() : this.!2b();
2379 g() => new A.!3c();
Brian Wilkerson908708d2015-08-05 08:13:28 -07002380}''',
2381 <String>["1+x", "2+b", "3+c"],
2382 failingTests: '12');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002383
Brian Wilkerson908708d2015-08-05 08:13:28 -07002384 buildTests(
2385 'test005',
2386 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002387class A {}
2388void rr(var vim) {
2389 var !1vq = v!2.toString();
2390 var vf;
2391 v!3.toString();
Brian Wilkerson908708d2015-08-05 08:13:28 -07002392}''',
2393 <String>[
2394 "1-A",
2395 "1-vim",
2396 "1+vq",
2397 "1-vf",
2398 "1-this",
2399 "1-void",
2400 "1-null",
2401 "1-false",
2402 "2-A",
2403 "2+vim",
2404 "2-vf",
2405 "2-vq",
2406 "2-this",
2407 "2-void",
2408 "2-null",
2409 "2-false",
2410 "3+vf",
2411 "3+vq",
2412 "3+vim",
2413 "3-A"
2414 ],
2415 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002416
Brian Wilkerson908708d2015-08-05 08:13:28 -07002417 buildTests(
2418 'test006',
2419 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002420void r2(var vim, {va: 2, b: 3}) {
2421 v!1.toString()
Brian Wilkerson908708d2015-08-05 08:13:28 -07002422}''',
2423 <String>["1+va", "1-b"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002424
Brian Wilkerson908708d2015-08-05 08:13:28 -07002425 buildTests(
2426 'test007',
2427 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002428void r2(var vim, [va: 2, b: 3]) {
2429 v!1.toString()
Brian Wilkerson908708d2015-08-05 08:13:28 -07002430}''',
2431 <String>["1+va", "1-b"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002432
2433 // keywords
Brian Wilkerson908708d2015-08-05 08:13:28 -07002434 buildTests(
2435 'test008',
2436 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002437!1class Aclass {}
2438class Bclass !2extends!3 !4Aclass {}
2439!5typedef Ctype = !6Bclass with !7Aclass;
2440class Dclass extends !8Ctype {}
2441!9abstract class Eclass implements Dclass,!C Ctype, Bclass {}
Brian Wilkerson908708d2015-08-05 08:13:28 -07002442class Fclass extends Bclass !Awith !B Eclass {}''',
2443 <String>[
2444 "1+class",
2445 "1-implements",
2446 "1-extends",
2447 "1-with",
2448 "2+extends",
2449 "3+extends",
2450 "4+Aclass",
2451 "4-Bclass",
2452 "5+typedef",
2453 "6+Bclass",
2454 "6-Ctype",
2455 "7+Aclass",
2456 "7-Bclass",
2457 "8+Ctype",
2458 "9+abstract",
2459 "A+with",
2460 "B+Eclass",
2461 "B-Dclass",
2462 "B-Ctype",
2463 "C+Bclass",
2464 "C-Eclass"
2465 ],
2466 failingTests: '23467ABC');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002467
2468 // keywords
Brian Wilkerson908708d2015-08-05 08:13:28 -07002469 buildTests(
2470 'test009',
2471 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002472typedef !1dy!2namic TestFn1();
2473typedef !3vo!4id TestFn2();
Brian Wilkerson908708d2015-08-05 08:13:28 -07002474typ!7edef !5n!6''',
2475 <String>[
2476 "1+void",
2477 "1+TestFn2",
2478 "2+dynamic",
2479 "2-void",
2480 "3+dynamic",
2481 "4+void",
2482 "4-dynamic",
2483 "5+TestFn2",
2484 "6+num",
2485 "7+typedef"
2486 ],
2487 failingTests: '1234');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002488
Brian Wilkerson908708d2015-08-05 08:13:28 -07002489 buildTests(
2490 'test010',
2491 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002492class test !8<!1t !2 !3extends String,!4 List,!5 !6>!7 {}
Brian Wilkerson908708d2015-08-05 08:13:28 -07002493class tezetst !9<!BString,!C !DList>!A {}''',
2494 <String>[
2495 "1-String",
2496 "1-List",
2497 "1-test",
2498 "2-String",
2499 "2-test",
2500 "3+extends",
2501 "4-tezetst",
2502 "4-test",
2503 "5-String",
2504 "6-List",
2505 "7-List",
2506 "8-List",
2507 "9-String",
2508 "A-String",
2509 "B-String",
2510 "C-List",
2511 "C-tezetst",
2512 "D-List",
2513 "D-test"
2514 ],
2515 failingTests: '23');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002516
2517 // name generation with conflicts
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002518 buildTests('test011', '''r2(var object, Object object1, Object !1);''',
Brian Wilkerson908708d2015-08-05 08:13:28 -07002519 <String>["1+object2"],
2520 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002521
2522 // reserved words
Brian Wilkerson908708d2015-08-05 08:13:28 -07002523 buildTests(
2524 'test012',
2525 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002526class X {
2527 f() {
2528 g(!1var!2 z) {!3true.!4toString();};
2529 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002530}''',
2531 <String>[
2532 "1+var",
2533 "1+dynamic",
2534 "1-f",
2535 "2+var",
2536 "2-dynamic",
2537 "3+false",
2538 "3+true",
2539 "4+toString"
2540 ],
2541 failingTests: '123');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002542
2543 // conditions & operators
Brian Wilkerson908708d2015-08-05 08:13:28 -07002544 buildTests(
2545 'test013',
2546 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002547class Q {
2548 bool x;
2549 List zs;
2550 int k;
2551 var a;
2552 mth() {
2553 while (!1x !9);
2554 do{} while(!2x !8);
2555 for(z in !3zs) {}
2556 switch(!4k) {case 1:{!0}}
2557 try {
2558 } on !5Object catch(a){}
2559 if (!7x !6) {} else {};
2560 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002561}''',
2562 <String>[
2563 "1+x",
2564 "2+x",
2565 "3+zs",
2566 "4+k",
2567 "5+Q",
2568 "5-a",
2569 "6+==",
2570 "7+x",
2571 "8+==",
2572 "9+==",
2573 "0+k"
2574 ],
2575 failingTests: '689');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002576
2577 // keywords
Brian Wilkerson908708d2015-08-05 08:13:28 -07002578 buildTests(
2579 'test014',
2580 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002581class Q {
2582 bool x;
2583 List zs;
2584 int k;
2585 !Dvar a;
2586 !Evoid mth() {
2587 !1while (z) { !Gcontinue; };
2588 !2do{ !Hbreak; } !3while(x);
2589 !4for(z !5in zs) {}
2590 !6for (int i; i < 3; i++);
2591 !7switch(k) {!8case 1:{} !9default:{}}
2592 !Atry {
2593 } !Bon Object !Ccatch(a){}
2594 !Fassert true;
2595 !Jif (x) {} !Kelse {};
2596 !Lreturn;
2597 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002598}''',
2599 <String>[
2600 "1+while",
2601 "2+do",
2602 "3+while",
danrubelf79d02d2015-08-10 10:09:18 -04002603 "4+for",
Brian Wilkerson908708d2015-08-05 08:13:28 -07002604 "5+in",
danrubelf79d02d2015-08-10 10:09:18 -04002605 "6+for",
Brian Wilkerson908708d2015-08-05 08:13:28 -07002606 "7+switch",
2607 "8+case",
2608 "9+default",
2609 "A+try",
2610 "B+on",
2611 "C+catch",
2612 "D+var",
2613 "E+void",
2614 "F+assert",
2615 "G+continue",
2616 "H+break",
2617 "J+if",
2618 "K+else",
2619 "L+return"
2620 ],
Dan Rubelbd95b132015-08-26 17:34:57 -04002621 failingTests: '3BCK');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002622
2623 // operators in function
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002624 buildTests('test015', '''f(a,b,c) => a + b * c !1;''', <String>["1+=="],
paulberry@google.com24611252014-12-09 16:44:12 +00002625 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002626
2627 // operators in return
Brian Wilkerson908708d2015-08-05 08:13:28 -07002628 buildTests(
2629 'test016',
2630 '''class X {dynamic f(a,b,c) {return a + b * c !1;}}''',
2631 <String>["1+=="],
2632 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002633
2634 // keywords
Brian Wilkerson908708d2015-08-05 08:13:28 -07002635 buildTests(
2636 'test017',
2637 '''
danrubel@google.com63685142015-05-04 18:02:23 +00002638!1!2import 'x' !5as r;
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002639!3export '!8uri' !6hide Q !7show X;
Brian Wilkerson908708d2015-08-05 08:13:28 -07002640!4part 'x';''',
2641 <String>[
2642 "1+library",
Jaime Wren04a14d02016-04-06 14:26:18 -07002643 "2+import \'\';",
2644 "3+export \'\';",
2645 "4+part \'\';",
Brian Wilkerson908708d2015-08-05 08:13:28 -07002646 "5+as",
2647 "6+hide",
2648 "7+show",
2649 "8-null"
2650 ],
Jaime Wren04a14d02016-04-06 14:26:18 -07002651 failingTests: '234567'); //TODO(jwren) 234 failing as correct selection
Brian Wilkerson6ccbef92016-08-29 08:11:53 -07002652 // offset assertions can't be passed into buildTests(..)
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002653
paulberry@google.com0b9ed182014-12-12 18:22:34 +00002654 // keywords
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002655 buildTests('test018', '''!1part !2of foo;''', <String>["1+part", "2+of"],
Jaime Wren04a14d02016-04-06 14:26:18 -07002656 failingTests: '12');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002657
Brian Wilkerson908708d2015-08-05 08:13:28 -07002658 buildTests(
2659 'test019',
2660 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002661var truefalse = 0;
2662var falsetrue = 1;
2663main() {
2664 var foo = true!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07002665}''',
2666 <String>["1+true", "1+truefalse", "1-falsetrue"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002667
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002668 buildTests('test020', '''var x = null.!1''', <String>["1+toString"],
paulberry@google.com24611252014-12-09 16:44:12 +00002669 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002670
danrubel@google.com4e903a62015-04-03 20:38:50 +00002671 buildTests('test021', '''var x = .!1''', <String>["1-toString"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002672
danrubel@google.com4e903a62015-04-03 20:38:50 +00002673 buildTests('test022', '''var x = .!1;''', <String>["1-toString"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002674
Brian Wilkerson908708d2015-08-05 08:13:28 -07002675 buildTests(
2676 'test023',
2677 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002678class Map{getKeys(){}}
2679class X {
2680 static x1(Map m) {
2681 m.!1getKeys;
2682 }
2683 x2(Map m) {
2684 m.!2getKeys;
2685 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002686}''',
2687 <String>["1+getKeys", "2+getKeys"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002688
2689// Note lack of semicolon following completion location
Brian Wilkerson908708d2015-08-05 08:13:28 -07002690 buildTests(
2691 'test024',
2692 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002693class List{factory List.from(Iterable other) {}}
2694class F {
2695 f() {
2696 new List.!1
2697 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002698}''',
2699 <String>["1+from"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002700
Brian Wilkerson908708d2015-08-05 08:13:28 -07002701 buildTests(
2702 'test025',
2703 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002704class R {
2705 static R _m;
2706 static R m;
2707 f() {
2708 var a = !1m;
2709 var b = _!2m;
2710 var c = !3g();
2711 }
2712 static g() {
2713 var a = !4m;
2714 var b = _!5m;
2715 var c = !6g();
2716 }
2717}
2718class T {
2719 f() {
2720 R x;
2721 x.!7g();
2722 x.!8m;
2723 x._!9m;
2724 }
2725 static g() {
2726 var q = R._!Am;
2727 var g = R.!Bm;
2728 var h = R.!Cg();
2729 }
2730 h() {
2731 var q = R._!Dm;
2732 var g = R.!Em;
2733 var h = R.!Fg();
2734 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002735}''',
2736 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -07002737 "1+m",
2738 "2+_m",
2739 "3+g",
2740 "4+m",
2741 "5+_m",
2742 "6+g",
2743 "7-g",
2744 "8-m",
2745 "9-_m",
2746 "A+_m",
2747 "B+m",
2748 "C+g",
2749 "D+_m",
2750 "E+m",
2751 "F+g"
2752 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002753
paulberry@google.com523dac82014-12-17 16:52:25 +00002754 buildTests('test026', '''var aBcD; var x=ab!1''', <String>["1+aBcD"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002755
paulberry@google.com523dac82014-12-17 16:52:25 +00002756 buildTests(
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002757 'test027', '''m(){try{}catch(eeee,ssss){s!1}''', <String>["1+ssss"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002758
paulberry@google.com523dac82014-12-17 16:52:25 +00002759 buildTests('test028', '''m(){var isX=3;if(is!1)''', <String>["1+isX"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002760
paulberry@google.com523dac82014-12-17 16:52:25 +00002761 buildTests('test029', '''m(){[1].forEach((x)=>!1x);}''', <String>["1+x"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002762
paulberry@google.com523dac82014-12-17 16:52:25 +00002763 buildTests('test030', '''n(){[1].forEach((x){!1});}''', <String>["1+x"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002764
Brian Wilkerson908708d2015-08-05 08:13:28 -07002765 buildTests(
2766 'test031',
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002767 '''class Caster {} m() {try {} on Cas!1ter catch (CastBlock) {!2}}''',
danrubel@google.comcaff47a2015-04-01 19:29:57 +00002768 <String>["1+Caster", "1-CastBlock", "2+Caster", "2+CastBlock"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002769
Brian Wilkerson908708d2015-08-05 08:13:28 -07002770 buildTests(
2771 'test032',
2772 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002773const ONE = 1;
2774const ICHI = 10;
2775const UKSI = 100;
2776const EIN = 1000;
2777m() {
2778 int x;
2779 switch (x) {
2780 case !3ICHI:
2781 case UKSI:
2782 case EIN!2:
2783 case ONE!1: return;
2784 default: return;
2785 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002786}''',
2787 <String>[
Brian Wilkerson8c22a5f2016-03-29 08:27:14 -07002788 "1+ONE",
2789 "1-UKSI",
2790 "2+EIN",
2791 "2-ICHI",
2792 "3+ICHI",
2793 "3+UKSI",
2794 "3+EIN",
2795 "3+ONE"
2796 ]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002797
Brian Wilkerson908708d2015-08-05 08:13:28 -07002798 buildTests(
2799 'test033',
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002800 '''class A{}class B extends A{b(){}}class C implements A {c(){}}class X{x(){A f;f.!1}}''',
Brian Wilkerson908708d2015-08-05 08:13:28 -07002801 <String>["1+b", "1-c"],
2802 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002803
2804 // TODO(scheglov) decide what to do with Type for untyped field (not
2805 // supported by the new store)
2806 // test analysis of untyped fields and top-level vars
Brian Wilkerson908708d2015-08-05 08:13:28 -07002807 buildTests(
2808 'test034',
2809 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002810var topvar;
2811class Top {top(){}}
2812class Left extends Top {left(){}}
2813class Right extends Top {right(){}}
2814t1() {
2815 topvar = new Left();
2816}
2817t2() {
2818 topvar = new Right();
2819}
2820class A {
2821 var field;
2822 a() {
2823 field = new Left();
2824 }
2825 b() {
2826 field = new Right();
2827 }
2828 test() {
2829 topvar.!1top();
2830 field.!2top();
2831 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002832}''',
2833 <String>["1+top", "2+top"],
2834 failingTests: '12');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002835
2836 // test analysis of untyped fields and top-level vars
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002837 buildTests('test035', '''class Y {final x='hi';mth() {x.!1length;}}''',
Konstantin Shcheglovde4d8b32016-10-06 08:47:15 -07002838 <String>["1+length"],
2839 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002840
2841 // TODO(scheglov) decide what to do with Type for untyped field (not
2842 // supported by the new store)
2843 // test analysis of untyped fields and top-level vars
Brian Wilkerson908708d2015-08-05 08:13:28 -07002844 buildTests(
2845 'test036',
2846 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002847class A1 {
2848 var field;
2849 A1() : field = 0;
2850 q() {
2851 A1 a = new A1();
2852 a.field.!1
2853 }
2854}
2855main() {
2856 A1 a = new A1();
2857 a.field.!2
Brian Wilkerson908708d2015-08-05 08:13:28 -07002858}''',
2859 <String>["1+round", "2+round"],
2860 failingTests: '12');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002861
Brian Wilkerson908708d2015-08-05 08:13:28 -07002862 buildTests(
2863 'test037',
2864 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002865class HttpServer{}
2866class HttpClient{}
2867main() {
2868 new HtS!1
Brian Wilkerson908708d2015-08-05 08:13:28 -07002869}''',
2870 <String>["1+HttpServer", "1-HttpClient"],
2871 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002872
Brian Wilkerson908708d2015-08-05 08:13:28 -07002873 buildTests(
2874 'test038',
2875 '''
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002876class X {
2877 x(){}
2878}
2879class Y {
2880 y(){}
2881}
2882class A<Z extends X> {
2883 Y ay;
2884 Z az;
2885 A(this.ay, this.az) {
2886 ay.!1y;
2887 az.!2x;
2888 }
Brian Wilkerson908708d2015-08-05 08:13:28 -07002889}''',
2890 <String>["1+y", "1-x", "2+x", "2-y"],
2891 failingTests: '2');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002892
2893 // test analysis of untyped fields and top-level vars
Brian Wilkerson6ccbef92016-08-29 08:11:53 -07002894 buildTests(
2895 'test039', '''class X{}var x = null as !1X;''', <String>["1-void"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002896
2897 // test arg lists with named params
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002898 buildTests('test040', '''m(){f(a, b, {x1, x2, y}) {};f(1, 2, !1)!2;}''',
Brian Wilkerson908708d2015-08-05 08:13:28 -07002899 <String>["1+x1", "2-x2"],
2900 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002901
2902 // test arg lists with named params
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002903 buildTests('test041', '''m(){f(a, b, {x1, x2, y}) {};f(1, 2, !1''',
Brian Wilkerson908708d2015-08-05 08:13:28 -07002904 <String>["1+x1", "1+x2", "1+y"],
2905 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002906
2907 // test arg lists with named params
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002908 buildTests('test042', '''m(){f(a, b, {x1, x2, y}) {};f(1, 2, !1;!2''',
Brian Wilkerson908708d2015-08-05 08:13:28 -07002909 <String>["1+x1", "1+x2", "2-y"],
2910 failingTests: '1');
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002911 }
2912
2913 void buildOtherTests() {
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002914 buildTests('test_classMembers_inGetter',
2915 '''class A { var fff; get z {ff!1}}''', <String>["1+fff"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002916
Brian Wilkerson908708d2015-08-05 08:13:28 -07002917 buildTests(
2918 'testSingle',
2919 '''class A {int x; !2mth() {int y = this.x;}}class B{}''',
2920 <String>["2+B"]);
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002921 }
paulberry@google.com523dac82014-12-17 16:52:25 +00002922
2923 /**
2924 * Generate a set of completion tests based on the given [originalSource].
2925 *
2926 * The source string has completion points embedded in it, which are
2927 * identified by '!X' where X is a single character. Each X is matched to
2928 * positive or negative results in the array of [validationStrings].
2929 * Validation strings contain the name of a prediction with a two character
2930 * prefix. The first character of the prefix corresponds to an X in the
2931 * [originalSource]. The second character is either a '+' or a '-' indicating
2932 * whether the string is a positive or negative result.
2933 *
2934 * The [originalSource] is the source for a completion test that contains
2935 * completion points. The [validationStrings] are the positive and negative
2936 * predictions.
2937 *
2938 * Optional argument [failingTests], if given, is a string, each character of
2939 * which corresponds to an X in the [originalSource] for which the test is
2940 * expected to fail. This sould be used to mark known completion bugs that
2941 * have not yet been fixed.
2942 */
2943 void buildTests(String baseName, String originalSource, List<String> results,
2944 {Map<String, String> extraFiles, String failingTests: ''}) {
2945 List<LocationSpec> completionTests =
2946 LocationSpec.from(originalSource, results);
2947 completionTests.sort((LocationSpec first, LocationSpec second) {
2948 return first.id.compareTo(second.id);
2949 });
2950 if (completionTests.isEmpty) {
2951 test(baseName, () {
brianwilkerson@google.comcd58e292015-03-02 22:43:12 +00002952 fail("Expected exclamation point ('!') within the source denoting the"
2953 "position at which code completion should occur");
paulberry@google.com523dac82014-12-17 16:52:25 +00002954 });
2955 }
2956 Set<String> allSpecIds =
2957 completionTests.map((LocationSpec spec) => spec.id).toSet();
2958 for (String id in failingTests.split('')) {
2959 if (!allSpecIds.contains(id)) {
2960 test("$baseName-$id", () {
2961 fail(
2962 "Test case '$id' included in failingTests, but this id does not exist.");
2963 });
2964 }
2965 }
2966 for (LocationSpec spec in completionTests) {
paulberry@google.com6d7155d2014-12-20 15:47:25 +00002967 String testName = '$baseName-${spec.id}';
paulberry@google.com523dac82014-12-17 16:52:25 +00002968 if (failingTests.contains(spec.id)) {
2969 ++expectedFailCount;
Konstantin Shcheglovde4d8b32016-10-06 08:47:15 -07002970 test("$testName (expected failure $expectedFailCount)", () {
paulberry@google.com523dac82014-12-17 16:52:25 +00002971 CompletionTestCase test = new CompletionTestCase();
2972 return new Future(() => test.runTest(spec, extraFiles)).then((_) {
2973 fail('Test passed - expected to fail.');
2974 }, onError: (_) {});
2975 });
2976 } else {
2977 ++expectedPassCount;
Konstantin Shcheglovde4d8b32016-10-06 08:47:15 -07002978 test(testName, () {
paulberry@google.com523dac82014-12-17 16:52:25 +00002979 CompletionTestCase test = new CompletionTestCase();
2980 return test.runTest(spec, extraFiles);
2981 });
2982 }
2983 }
2984 }
brianwilkerson@google.comd05b8152014-12-08 20:00:24 +00002985}