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

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

Issue 634653002: add named constructor, cascade selector suggestions and more tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.services.completion.invocation; 5 library test.services.completion.invocation;
6 6
7 7
8 import 'package:analysis_server/src/protocol.dart'; 8 import 'package:analysis_server/src/protocol.dart';
9 import 'package:analysis_server/src/services/completion/invocation_computer.dart '; 9 import 'package:analysis_server/src/services/completion/invocation_computer.dart ';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
11 11
12 import '../../reflective_tests.dart'; 12 import '../../reflective_tests.dart';
13 import 'completion_test_util.dart'; 13 import 'completion_test_util.dart';
14 14
15 main() { 15 main() {
16 groupSep = ' | '; 16 groupSep = ' | ';
17 runReflectiveTests(InvocationComputerTest); 17 runReflectiveTests(InvocationComputerTest);
18 } 18 }
19 19
20 @ReflectiveTestCase() 20 @ReflectiveTestCase()
21 class InvocationComputerTest extends AbstractCompletionTest { 21 class InvocationComputerTest extends AbstractCompletionTest {
22 22
23 @override 23 @override
24 void setUp() { 24 void setUp() {
25 super.setUp(); 25 super.setUp();
26 computer = new InvocationComputer(); 26 computer = new InvocationComputer();
27 } 27 }
28 28
29 test_CascadeExpression_selector1() {
30 // PropertyAccess CascadeExpression ExpressionStatement
31 addTestSource('''
32 class A {var b; X _c;}
33 class X{}
34 // looks like a cascade to the parser
35 // but the user is trying to get completions for a non-cascade
36 main() {A a; a.^.b}''');
37 return computeFull(true).then((_) {
38 assertSuggestGetter('b', null);
39 assertSuggestGetter('_c', 'X');
40 });
41 }
42
43 test_CascadeExpression_selector2() {
44 // PropertyAccess CascadeExpression ExpressionStatement
45 addTestSource('''
46 class A {var b; X _c;}
47 class X{}
48 main() {A a; a..^b}''');
49 return computeFull().then((_) {
50 assertSuggestGetter('b', null);
51 assertSuggestGetter('_c', 'X');
52 });
53 }
54
55 test_CascadeExpression_target() {
56 // PropertyAccess CascadeExpression ExpressionStatement
57 addTestSource('''
58 class A {var b; X _c;}
59 class X{}
60 main() {A a; a^..b}''');
61 return computeFull().then((_) {
62 assertNotSuggested('b');
63 assertNotSuggested('_c');
64 });
65 }
66
67 test_ConstructorName_importedClass() {
68 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
69 // InstanceCreationExpression
70 addSource('/testB.dart', '''
71 lib B;
72 class X {X.c(); X._d(); z() {}}''');
73 addTestSource('''
74 import "/testB.dart";
75 var m;
76 main() {new X.^}''');
77 return computeFull().then((_) {
78 assertSuggest(CompletionSuggestionKind.CONSTRUCTOR, 'c');
79 assertNotSuggested('_d');
80 assertNotSuggested('z');
81 assertNotSuggested('m');
82 });
83 }
84
85 test_ConstructorName_localClass() {
86 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
87 // InstanceCreationExpression
88 addTestSource('''
89 var m;
90 class X {X.c(); X._d(); z() {}}
91 main() {new X.^}''');
92 return computeFull().then((_) {
93 assertSuggest(CompletionSuggestionKind.CONSTRUCTOR, 'c');
94 assertSuggest(CompletionSuggestionKind.CONSTRUCTOR, '_d');
95 assertNotSuggested('z');
96 assertNotSuggested('m');
97 });
98 }
99
29 test_PrefixedIdentifier_field() { 100 test_PrefixedIdentifier_field() {
30 // SimpleIdentifier PrefixedIdentifier ExpressionStatement 101 // SimpleIdentifier PrefixedIdentifier ExpressionStatement
31 addTestSource(''' 102 addTestSource('''
32 class A {var b; X _c;} 103 class A {var b; X _c;}
33 class X{} 104 class X{}
34 main() {A a; a.^}'''); 105 main() {A a; a.^}''');
35 return computeFull().then((_) { 106 return computeFull().then((_) {
36 assertSuggestGetter('b', null); 107 assertSuggestGetter('b', null);
37 assertSuggestGetter('_c', 'X'); 108 assertSuggestGetter('_c', 'X');
38 }); 109 });
39 } 110 }
40 111
41 test_PrefixedIdentifier_field_imported() { 112 test_PrefixedIdentifier_field_imported() {
42 // SimpleIdentifier PrefixedIdentifier ExpressionStatement 113 // SimpleIdentifier PrefixedIdentifier ExpressionStatement
43 addSource('/testB.dart', ''' 114 addSource('/testB.dart', '''
44 lib B; 115 lib B;
45 class X{} 116 class X{}
46 class A {var b; X _c;}'''); 117 class A {var b; X _c;}''');
47 addTestSource(''' 118 addTestSource('''
48 import "/testB.dart"; 119 import "/testB.dart";
49 main() {A a; a.^}'''); 120 main() {A a; a.^}''');
50 return computeFull().then((_) { 121 return computeFull().then((_) {
51 assertSuggestGetter('b', null); 122 assertSuggestGetter('b', null);
52 assertNotSuggested('_c'); 123 assertNotSuggested('_c');
53 }); 124 });
54 } 125 }
55 126
56 // TODO (danrubel) implement
57 test_PrefixedIdentifier_getter() { 127 test_PrefixedIdentifier_getter() {
58 // SimpleIdentifier PrefixedIdentifier ExpressionStatement 128 // SimpleIdentifier PrefixedIdentifier ExpressionStatement
59 addTestSource(''' 129 addTestSource('''
60 class A {X get b => new A();get _c => new A();} 130 class A {X get b => new A();get _c => new A();}
61 class X{} 131 class X{}
62 main() {A a; a.^}'''); 132 main() {A a; a.^}''');
63 return computeFull().then((_) { 133 return computeFull().then((_) {
64 assertSuggestGetter('b', 'X'); 134 assertSuggestGetter('b', 'X');
65 assertSuggestGetter('_c', null); 135 assertSuggestGetter('_c', null);
66 }); 136 });
(...skipping 17 matching lines...) Expand all
84 addTestSource(''' 154 addTestSource('''
85 class A {S get b => new A();A get _c => new A();} 155 class A {S get b => new A();A get _c => new A();}
86 class B implements A {S get b => new A();} class S{} 156 class B implements A {S get b => new A();} class S{}
87 main() {B b; b.^}'''); 157 main() {B b; b.^}''');
88 return computeFull().then((_) { 158 return computeFull().then((_) {
89 assertSuggestGetter('b', 'S'); 159 assertSuggestGetter('b', 'S');
90 assertSuggestGetter('_c', 'A'); 160 assertSuggestGetter('_c', 'A');
91 }); 161 });
92 } 162 }
93 163
164 test_PrefixedIdentifier_interpolation() {
165 // SimpleIdentifier PrefixedIdentifier InterpolationExpression
166 addTestSource('main() {String name; print("hello \${name.^}");}');
167 return computeFull().then((_) {
168 assertSuggestGetter('length', 'int');
169 });
170 }
171
94 test_PrefixedIdentifier_library() { 172 test_PrefixedIdentifier_library() {
95 // SimpleIdentifier PrefixedIdentifier ExpressionStatement 173 // SimpleIdentifier PrefixedIdentifier ExpressionStatement
96 addSource('/testB.dart', ''' 174 addSource('/testB.dart', '''
97 lib B; 175 lib B;
98 class X { } 176 class X { }
99 class Y { }'''); 177 class Y { }''');
100 addTestSource(''' 178 addTestSource('''
101 import "/testB.dart" as b; 179 import "/testB.dart" as b;
102 main() {b.^}'''); 180 main() {b.^}''');
103 return computeFull().then((_) { 181 return computeFull().then((_) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 class M{}'''); 234 class M{}''');
157 addTestSource(''' 235 addTestSource('''
158 import "/testB.dart"; 236 import "/testB.dart";
159 foo(X x) {x.^}'''); 237 foo(X x) {x.^}''');
160 return computeFull().then((_) { 238 return computeFull().then((_) {
161 assertSuggestGetter('y', 'M'); 239 assertSuggestGetter('y', 'M');
162 assertNotSuggested('_z'); 240 assertNotSuggested('_z');
163 }); 241 });
164 } 242 }
165 243
244 test_PrefixedIdentifier_prefix() {
245 // SimpleIdentifier PrefixedIdentifier InterpolationExpression
246 addTestSource('main() {String name; print("hello \${nam^e.length}");}');
247 return computeFull().then((_) {
248 // LocalComputer generates suggestions for prefix
249 assertNotSuggested('name');
250 assertNotSuggested('length');
251 });
252 }
253
166 test_PrefixedIdentifier_setter() { 254 test_PrefixedIdentifier_setter() {
167 // SimpleIdentifier PrefixedIdentifier ExpressionStatement 255 // SimpleIdentifier PrefixedIdentifier ExpressionStatement
168 addTestSource(''' 256 addTestSource('''
169 class A {set b(X x) {} set _c(X x) {}} 257 class A {set b(X x) {} set _c(X x) {}}
170 main() {A a; a.^}'''); 258 main() {A a; a.^}''');
171 return computeFull().then((_) { 259 return computeFull().then((_) {
172 assertSuggestSetter('b'); 260 assertSuggestSetter('b');
173 assertSuggestSetter('_c'); 261 assertSuggestSetter('_c');
174 }); 262 });
175 } 263 }
176 264
177 test_PrefixedIdentifier_setter_imported() { 265 test_PrefixedIdentifier_setter_imported() {
178 // SimpleIdentifier PrefixedIdentifier ExpressionStatement 266 // SimpleIdentifier PrefixedIdentifier ExpressionStatement
179 addSource('/testB.dart', ''' 267 addSource('/testB.dart', '''
180 lib B; 268 lib B;
181 class X {set y(X x) {} set _z(X x) {}}'''); 269 class X {set y(X x) {} set _z(X x) {}}''');
182 addTestSource(''' 270 addTestSource('''
183 import "/testB.dart"; 271 import "/testB.dart";
184 main() {X x; x.^}'''); 272 main() {X x; x.^}''');
185 return computeFull().then((_) { 273 return computeFull().then((_) {
186 assertSuggestSetter('y'); 274 assertSuggestSetter('y');
187 assertNotSuggested('_z'); 275 assertNotSuggested('_z');
188 }); 276 });
189 } 277 }
190 278
191 xtest_ConstructorName() { 279 //TODO (danrubel) implement
192 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName 280 xtest_IsExpression() {
193 // InstanceCreationExpression 281 // SimpleIdentifier TypeName IsExpression IfStatement
194 addSource('/testB.dart', ''' 282 addSource('/testB.dart', '''
195 lib B; 283 lib B;
196 class X {X.c(); X._d(); z() {}}'''); 284 class X {X.c(); X._d(); z() {}}''');
197 addTestSource(''' 285 addTestSource('''
198 import "/testB.dart"; 286 import "/testB.dart";
199 main() {new X.^}'''); 287 main() {var x; if (x is ^) { }}''');
200 return computeFull().then((_) { 288 return computeFull().then((_) {
201 assertSuggest(CompletionSuggestionKind.CONSTRUCTOR, 'c'); 289 assertNoSuggestions();
202 assertNotSuggested('_d');
203 assertNotSuggested('z');
204 }); 290 });
205 } 291 }
206 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698