| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.services.completion.dart.local; | |
| 6 | |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol | |
| 8 show Element, ElementKind; | |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart' | |
| 10 hide Element, ElementKind; | |
| 11 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | |
| 12 import 'package:analysis_server/src/services/completion/local_reference_contribu
tor.dart'; | |
| 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; | |
| 14 import 'package:unittest/unittest.dart'; | |
| 15 | |
| 16 import '../../utils.dart'; | |
| 17 import 'completion_test_util.dart'; | |
| 18 | |
| 19 main() { | |
| 20 initializeTestEnvironment(); | |
| 21 defineReflectiveTests(LocalReferenceContributorTest); | |
| 22 } | |
| 23 | |
| 24 @reflectiveTest | |
| 25 class LocalReferenceContributorTest extends AbstractSelectorSuggestionTest { | |
| 26 @override | |
| 27 CompletionSuggestion assertSuggestLocalClass(String name, | |
| 28 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | |
| 29 int relevance: DART_RELEVANCE_DEFAULT, | |
| 30 bool isDeprecated: false, | |
| 31 String elemFile, | |
| 32 int elemOffset}) { | |
| 33 return assertSuggestClass(name, | |
| 34 elemFile: elemFile, | |
| 35 elemOffset: elemOffset, | |
| 36 isDeprecated: isDeprecated, | |
| 37 kind: kind, | |
| 38 relevance: relevance); | |
| 39 } | |
| 40 | |
| 41 @override | |
| 42 CompletionSuggestion assertSuggestLocalClassTypeAlias(String name, | |
| 43 {int relevance: DART_RELEVANCE_DEFAULT}) { | |
| 44 return assertSuggestClassTypeAlias(name, relevance); | |
| 45 } | |
| 46 | |
| 47 @override | |
| 48 CompletionSuggestion assertSuggestLocalField(String name, String type, | |
| 49 {int relevance: DART_RELEVANCE_LOCAL_FIELD, bool deprecated: false}) { | |
| 50 return assertSuggestField(name, type, | |
| 51 relevance: relevance, isDeprecated: deprecated); | |
| 52 } | |
| 53 | |
| 54 @override | |
| 55 CompletionSuggestion assertSuggestLocalFunction( | |
| 56 String name, String returnType, | |
| 57 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | |
| 58 bool deprecated: false, | |
| 59 int relevance: DART_RELEVANCE_LOCAL_FUNCTION}) { | |
| 60 return assertSuggestFunction(name, returnType, | |
| 61 kind: kind, deprecated: deprecated, relevance: relevance); | |
| 62 } | |
| 63 | |
| 64 @override | |
| 65 CompletionSuggestion assertSuggestLocalFunctionTypeAlias( | |
| 66 String name, String returnType, | |
| 67 {bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) { | |
| 68 return assertSuggestFunctionTypeAlias( | |
| 69 name, returnType, deprecated, relevance); | |
| 70 } | |
| 71 | |
| 72 @override | |
| 73 CompletionSuggestion assertSuggestLocalGetter(String name, String returnType, | |
| 74 {int relevance: DART_RELEVANCE_LOCAL_ACCESSOR, bool deprecated: false}) { | |
| 75 return assertSuggestGetter(name, returnType, | |
| 76 relevance: relevance, isDeprecated: deprecated); | |
| 77 } | |
| 78 | |
| 79 @override | |
| 80 CompletionSuggestion assertSuggestLocalMethod( | |
| 81 String name, String declaringType, String returnType, | |
| 82 {int relevance: DART_RELEVANCE_LOCAL_METHOD, bool deprecated: false}) { | |
| 83 return assertSuggestMethod(name, declaringType, returnType, | |
| 84 relevance: relevance, isDeprecated: deprecated); | |
| 85 } | |
| 86 | |
| 87 @override | |
| 88 CompletionSuggestion assertSuggestLocalSetter(String name, | |
| 89 {int relevance: DART_RELEVANCE_LOCAL_ACCESSOR}) { | |
| 90 return assertSuggestSetter(name, relevance); | |
| 91 } | |
| 92 | |
| 93 @override | |
| 94 CompletionSuggestion assertSuggestLocalTopLevelVar( | |
| 95 String name, String returnType, | |
| 96 {int relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE}) { | |
| 97 return assertSuggestTopLevelVar(name, returnType, relevance); | |
| 98 } | |
| 99 | |
| 100 @override | |
| 101 CompletionSuggestion assertSuggestLocalVariable( | |
| 102 String name, String returnType, | |
| 103 {int relevance: DART_RELEVANCE_LOCAL_VARIABLE}) { | |
| 104 // Local variables should only be suggested by LocalReferenceContributor | |
| 105 CompletionSuggestion cs = assertSuggest(name, | |
| 106 csKind: CompletionSuggestionKind.INVOCATION, relevance: relevance); | |
| 107 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | |
| 108 protocol.Element element = cs.element; | |
| 109 expect(element, isNotNull); | |
| 110 expect(element.kind, equals(protocol.ElementKind.LOCAL_VARIABLE)); | |
| 111 expect(element.name, equals(name)); | |
| 112 expect(element.parameters, isNull); | |
| 113 expect(element.returnType, returnType != null ? returnType : 'dynamic'); | |
| 114 assertHasNoParameterInfo(cs); | |
| 115 return cs; | |
| 116 } | |
| 117 | |
| 118 CompletionSuggestion assertSuggestParameter(String name, String returnType, | |
| 119 {int relevance: DART_RELEVANCE_PARAMETER}) { | |
| 120 CompletionSuggestion cs = assertSuggest(name, | |
| 121 csKind: CompletionSuggestionKind.INVOCATION, relevance: relevance); | |
| 122 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | |
| 123 protocol.Element element = cs.element; | |
| 124 expect(element, isNotNull); | |
| 125 expect(element.kind, equals(protocol.ElementKind.PARAMETER)); | |
| 126 expect(element.name, equals(name)); | |
| 127 expect(element.parameters, isNull); | |
| 128 expect(element.returnType, | |
| 129 equals(returnType != null ? returnType : 'dynamic')); | |
| 130 return cs; | |
| 131 } | |
| 132 | |
| 133 fail_mixin_ordering() { | |
| 134 // TODO(paulberry): Duplicates aren't being removed, so we see both M1.m() | |
| 135 // and M2.m(). | |
| 136 addTestSource(''' | |
| 137 class B {} | |
| 138 class M1 { | |
| 139 void m() {} | |
| 140 } | |
| 141 class M2 { | |
| 142 void m() {} | |
| 143 } | |
| 144 class C extends B with M1, M2 { | |
| 145 void f() { | |
| 146 ^ | |
| 147 } | |
| 148 } | |
| 149 '''); | |
| 150 expect(computeFast(), isTrue); | |
| 151 assertSuggestMethod('m', 'M2', 'void'); | |
| 152 } | |
| 153 | |
| 154 @override | |
| 155 void setUpContributor() { | |
| 156 contributor = new LocalReferenceContributor(); | |
| 157 } | |
| 158 | |
| 159 test_break_ignores_outer_functions_using_closure() { | |
| 160 addTestSource(''' | |
| 161 void main() { | |
| 162 foo: while (true) { | |
| 163 var f = () { | |
| 164 bar: while (true) { break ^ } | |
| 165 }; | |
| 166 } | |
| 167 } | |
| 168 '''); | |
| 169 expect(computeFast(), isTrue); | |
| 170 // Labels in outer functions are never accessible. | |
| 171 assertNotSuggested('bar'); | |
| 172 assertNotSuggested('foo'); | |
| 173 } | |
| 174 | |
| 175 test_break_ignores_outer_functions_using_local_function() { | |
| 176 addTestSource(''' | |
| 177 void main() { | |
| 178 foo: while (true) { | |
| 179 void f() { | |
| 180 bar: while (true) { break ^ } | |
| 181 }; | |
| 182 } | |
| 183 } | |
| 184 '''); | |
| 185 expect(computeFast(), isTrue); | |
| 186 // Labels in outer functions are never accessible. | |
| 187 assertNotSuggested('bar'); | |
| 188 assertNotSuggested('foo'); | |
| 189 } | |
| 190 | |
| 191 test_break_ignores_toplevel_variables() { | |
| 192 addTestSource(''' | |
| 193 int x; | |
| 194 void main() { | |
| 195 while (true) { | |
| 196 break ^ | |
| 197 } | |
| 198 } | |
| 199 '''); | |
| 200 expect(computeFast(), isTrue); | |
| 201 assertNotSuggested('x'); | |
| 202 } | |
| 203 | |
| 204 test_break_ignores_unrelated_statements() { | |
| 205 addTestSource(''' | |
| 206 void main() { | |
| 207 foo: while (true) {} | |
| 208 while (true) { break ^ } | |
| 209 bar: while (true) {} | |
| 210 } | |
| 211 '''); | |
| 212 expect(computeFast(), isTrue); | |
| 213 // The scope of the label defined by a labeled statement is just the | |
| 214 // statement itself, so neither "foo" nor "bar" are in scope at the caret | |
| 215 // position. | |
| 216 assertNotSuggested('foo'); | |
| 217 assertNotSuggested('bar'); | |
| 218 } | |
| 219 | |
| 220 test_break_to_enclosing_loop() { | |
| 221 addTestSource(''' | |
| 222 void main() { | |
| 223 foo: while (true) { | |
| 224 bar: while (true) { | |
| 225 break ^ | |
| 226 } | |
| 227 } | |
| 228 } | |
| 229 '''); | |
| 230 expect(computeFast(), isTrue); | |
| 231 assertNotSuggested('foo'); | |
| 232 assertNotSuggested('bar'); | |
| 233 } | |
| 234 | |
| 235 test_constructor_parameters_mixed_required_and_named() { | |
| 236 addTestSource('class A {A(x, {int y}) {^}}'); | |
| 237 expect(computeFast(), isTrue); | |
| 238 assertSuggestParameter('x', null); | |
| 239 assertSuggestParameter('y', 'int'); | |
| 240 } | |
| 241 | |
| 242 test_constructor_parameters_mixed_required_and_positional() { | |
| 243 addTestSource('class A {A(x, [int y]) {^}}'); | |
| 244 expect(computeFast(), isTrue); | |
| 245 assertSuggestParameter('x', null); | |
| 246 assertSuggestParameter('y', 'int'); | |
| 247 } | |
| 248 | |
| 249 test_constructor_parameters_named() { | |
| 250 addTestSource('class A {A({x, int y}) {^}}'); | |
| 251 expect(computeFast(), isTrue); | |
| 252 assertSuggestParameter('x', null); | |
| 253 assertSuggestParameter('y', 'int'); | |
| 254 } | |
| 255 | |
| 256 test_constructor_parameters_positional() { | |
| 257 addTestSource('class A {A([x, int y]) {^}}'); | |
| 258 expect(computeFast(), isTrue); | |
| 259 assertSuggestParameter('x', null); | |
| 260 assertSuggestParameter('y', 'int'); | |
| 261 } | |
| 262 | |
| 263 test_constructor_parameters_required() { | |
| 264 addTestSource('class A {A(x, int y) {^}}'); | |
| 265 expect(computeFast(), isTrue); | |
| 266 assertSuggestParameter('x', null); | |
| 267 assertSuggestParameter('y', 'int'); | |
| 268 } | |
| 269 | |
| 270 test_continue_from_loop_to_switch() { | |
| 271 addTestSource(''' | |
| 272 void main() { | |
| 273 switch (x) { | |
| 274 foo: case 1: | |
| 275 break; | |
| 276 bar: case 2: | |
| 277 while (true) { | |
| 278 continue ^; | |
| 279 } | |
| 280 break; | |
| 281 baz: case 3: | |
| 282 break; | |
| 283 } | |
| 284 } | |
| 285 '''); | |
| 286 expect(computeFast(), isTrue); | |
| 287 assertNotSuggested('foo'); | |
| 288 assertNotSuggested('bar'); | |
| 289 assertNotSuggested('baz'); | |
| 290 } | |
| 291 | |
| 292 test_continue_from_switch_to_loop() { | |
| 293 addTestSource(''' | |
| 294 void main() { | |
| 295 foo: while (true) { | |
| 296 switch (x) { | |
| 297 case 1: | |
| 298 continue ^; | |
| 299 } | |
| 300 } | |
| 301 } | |
| 302 '''); | |
| 303 expect(computeFast(), isTrue); | |
| 304 assertNotSuggested('foo'); | |
| 305 } | |
| 306 | |
| 307 test_continue_ignores_outer_functions_using_closure_with_loop() { | |
| 308 addTestSource(''' | |
| 309 void main() { | |
| 310 foo: while (true) { | |
| 311 var f = () { | |
| 312 bar: while (true) { continue ^ } | |
| 313 }; | |
| 314 } | |
| 315 } | |
| 316 '''); | |
| 317 expect(computeFast(), isTrue); | |
| 318 // Labels in outer functions are never accessible. | |
| 319 assertNotSuggested('bar'); | |
| 320 assertNotSuggested('foo'); | |
| 321 } | |
| 322 | |
| 323 test_continue_ignores_outer_functions_using_closure_with_switch() { | |
| 324 addTestSource(''' | |
| 325 void main() { | |
| 326 switch (x) { | |
| 327 foo: case 1: | |
| 328 var f = () { | |
| 329 bar: while (true) { continue ^ } | |
| 330 }; | |
| 331 } | |
| 332 } | |
| 333 '''); | |
| 334 expect(computeFast(), isTrue); | |
| 335 // Labels in outer functions are never accessible. | |
| 336 assertNotSuggested('bar'); | |
| 337 assertNotSuggested('foo'); | |
| 338 } | |
| 339 | |
| 340 test_continue_ignores_outer_functions_using_local_function_with_loop() { | |
| 341 addTestSource(''' | |
| 342 void main() { | |
| 343 foo: while (true) { | |
| 344 void f() { | |
| 345 bar: while (true) { continue ^ } | |
| 346 }; | |
| 347 } | |
| 348 } | |
| 349 '''); | |
| 350 expect(computeFast(), isTrue); | |
| 351 // Labels in outer functions are never accessible. | |
| 352 assertNotSuggested('bar'); | |
| 353 assertNotSuggested('foo'); | |
| 354 } | |
| 355 | |
| 356 test_continue_ignores_outer_functions_using_local_function_with_switch() { | |
| 357 addTestSource(''' | |
| 358 void main() { | |
| 359 switch (x) { | |
| 360 foo: case 1: | |
| 361 void f() { | |
| 362 bar: while (true) { continue ^ } | |
| 363 }; | |
| 364 } | |
| 365 } | |
| 366 '''); | |
| 367 expect(computeFast(), isTrue); | |
| 368 // Labels in outer functions are never accessible. | |
| 369 assertNotSuggested('bar'); | |
| 370 assertNotSuggested('foo'); | |
| 371 } | |
| 372 | |
| 373 test_continue_ignores_unrelated_statements() { | |
| 374 addTestSource(''' | |
| 375 void main() { | |
| 376 foo: while (true) {} | |
| 377 while (true) { continue ^ } | |
| 378 bar: while (true) {} | |
| 379 } | |
| 380 '''); | |
| 381 expect(computeFast(), isTrue); | |
| 382 // The scope of the label defined by a labeled statement is just the | |
| 383 // statement itself, so neither "foo" nor "bar" are in scope at the caret | |
| 384 // position. | |
| 385 assertNotSuggested('foo'); | |
| 386 assertNotSuggested('bar'); | |
| 387 } | |
| 388 | |
| 389 test_continue_to_earlier_case() { | |
| 390 addTestSource(''' | |
| 391 void main() { | |
| 392 switch (x) { | |
| 393 foo: case 1: | |
| 394 break; | |
| 395 case 2: | |
| 396 continue ^; | |
| 397 case 3: | |
| 398 break; | |
| 399 '''); | |
| 400 expect(computeFast(), isTrue); | |
| 401 assertNotSuggested('foo'); | |
| 402 } | |
| 403 | |
| 404 test_continue_to_enclosing_loop() { | |
| 405 addTestSource(''' | |
| 406 void main() { | |
| 407 foo: while (true) { | |
| 408 bar: while (true) { | |
| 409 continue ^ | |
| 410 } | |
| 411 } | |
| 412 } | |
| 413 '''); | |
| 414 expect(computeFast(), isTrue); | |
| 415 assertNotSuggested('foo'); | |
| 416 assertNotSuggested('bar'); | |
| 417 } | |
| 418 | |
| 419 test_continue_to_enclosing_switch() { | |
| 420 addTestSource(''' | |
| 421 void main() { | |
| 422 switch (x) { | |
| 423 foo: case 1: | |
| 424 break; | |
| 425 bar: case 2: | |
| 426 switch (y) { | |
| 427 case 1: | |
| 428 continue ^; | |
| 429 } | |
| 430 break; | |
| 431 baz: case 3: | |
| 432 break; | |
| 433 } | |
| 434 } | |
| 435 '''); | |
| 436 expect(computeFast(), isTrue); | |
| 437 assertNotSuggested('foo'); | |
| 438 assertNotSuggested('bar'); | |
| 439 assertNotSuggested('baz'); | |
| 440 } | |
| 441 | |
| 442 test_continue_to_later_case() { | |
| 443 addTestSource(''' | |
| 444 void main() { | |
| 445 switch (x) { | |
| 446 case 1: | |
| 447 break; | |
| 448 case 2: | |
| 449 continue ^; | |
| 450 foo: case 3: | |
| 451 break; | |
| 452 '''); | |
| 453 expect(computeFast(), isTrue); | |
| 454 assertNotSuggested('foo'); | |
| 455 } | |
| 456 | |
| 457 test_continue_to_same_case() { | |
| 458 addTestSource(''' | |
| 459 void main() { | |
| 460 switch (x) { | |
| 461 case 1: | |
| 462 break; | |
| 463 foo: case 2: | |
| 464 continue ^; | |
| 465 case 3: | |
| 466 break; | |
| 467 '''); | |
| 468 expect(computeFast(), isTrue); | |
| 469 assertNotSuggested('foo'); | |
| 470 } | |
| 471 | |
| 472 test_enum() { | |
| 473 addTestSource('enum E { one, two } main() {^}'); | |
| 474 expect(computeFast(), isTrue); | |
| 475 assertSuggestEnum('E'); | |
| 476 assertNotSuggested('one'); | |
| 477 assertNotSuggested('two'); | |
| 478 } | |
| 479 | |
| 480 test_enum_deprecated() { | |
| 481 addTestSource('@deprecated enum E { one, two } main() {^}'); | |
| 482 expect(computeFast(), isTrue); | |
| 483 assertSuggestEnum('E', isDeprecated: true); | |
| 484 assertNotSuggested('one'); | |
| 485 assertNotSuggested('two'); | |
| 486 } | |
| 487 | |
| 488 test_function_parameters_mixed_required_and_named() { | |
| 489 addTestSource(''' | |
| 490 void m(x, {int y}) {} | |
| 491 class B extends A { | |
| 492 main() {^} | |
| 493 } | |
| 494 '''); | |
| 495 expect(computeFast(), isTrue); | |
| 496 CompletionSuggestion suggestion = assertSuggestLocalFunction('m', 'void'); | |
| 497 expect(suggestion.parameterNames, hasLength(2)); | |
| 498 expect(suggestion.parameterNames[0], 'x'); | |
| 499 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 500 expect(suggestion.parameterNames[1], 'y'); | |
| 501 expect(suggestion.parameterTypes[1], 'int'); | |
| 502 expect(suggestion.requiredParameterCount, 1); | |
| 503 expect(suggestion.hasNamedParameters, true); | |
| 504 } | |
| 505 | |
| 506 test_function_parameters_mixed_required_and_positional() { | |
| 507 addTestSource(''' | |
| 508 void m(x, [int y]) {} | |
| 509 class B extends A { | |
| 510 main() {^} | |
| 511 } | |
| 512 '''); | |
| 513 expect(computeFast(), isTrue); | |
| 514 CompletionSuggestion suggestion = assertSuggestLocalFunction('m', 'void'); | |
| 515 expect(suggestion.parameterNames, hasLength(2)); | |
| 516 expect(suggestion.parameterNames[0], 'x'); | |
| 517 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 518 expect(suggestion.parameterNames[1], 'y'); | |
| 519 expect(suggestion.parameterTypes[1], 'int'); | |
| 520 expect(suggestion.requiredParameterCount, 1); | |
| 521 expect(suggestion.hasNamedParameters, false); | |
| 522 } | |
| 523 | |
| 524 test_function_parameters_named() { | |
| 525 addTestSource(''' | |
| 526 void m({x, int y}) {} | |
| 527 class B extends A { | |
| 528 main() {^} | |
| 529 } | |
| 530 '''); | |
| 531 expect(computeFast(), isTrue); | |
| 532 CompletionSuggestion suggestion = assertSuggestLocalFunction('m', 'void'); | |
| 533 expect(suggestion.parameterNames, hasLength(2)); | |
| 534 expect(suggestion.parameterNames[0], 'x'); | |
| 535 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 536 expect(suggestion.parameterNames[1], 'y'); | |
| 537 expect(suggestion.parameterTypes[1], 'int'); | |
| 538 expect(suggestion.requiredParameterCount, 0); | |
| 539 expect(suggestion.hasNamedParameters, true); | |
| 540 } | |
| 541 | |
| 542 test_function_parameters_none() { | |
| 543 addTestSource(''' | |
| 544 void m() {} | |
| 545 class B extends A { | |
| 546 main() {^} | |
| 547 } | |
| 548 '''); | |
| 549 expect(computeFast(), isTrue); | |
| 550 CompletionSuggestion suggestion = assertSuggestLocalFunction('m', 'void'); | |
| 551 expect(suggestion.parameterNames, isEmpty); | |
| 552 expect(suggestion.parameterTypes, isEmpty); | |
| 553 expect(suggestion.requiredParameterCount, 0); | |
| 554 expect(suggestion.hasNamedParameters, false); | |
| 555 } | |
| 556 | |
| 557 test_function_parameters_positional() { | |
| 558 addTestSource(''' | |
| 559 void m([x, int y]) {} | |
| 560 class B extends A { | |
| 561 main() {^} | |
| 562 } | |
| 563 '''); | |
| 564 expect(computeFast(), isTrue); | |
| 565 CompletionSuggestion suggestion = assertSuggestLocalFunction('m', 'void'); | |
| 566 expect(suggestion.parameterNames, hasLength(2)); | |
| 567 expect(suggestion.parameterNames[0], 'x'); | |
| 568 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 569 expect(suggestion.parameterNames[1], 'y'); | |
| 570 expect(suggestion.parameterTypes[1], 'int'); | |
| 571 expect(suggestion.requiredParameterCount, 0); | |
| 572 expect(suggestion.hasNamedParameters, false); | |
| 573 } | |
| 574 | |
| 575 test_function_parameters_required() { | |
| 576 addTestSource(''' | |
| 577 void m(x, int y) {} | |
| 578 class B extends A { | |
| 579 main() {^} | |
| 580 } | |
| 581 '''); | |
| 582 expect(computeFast(), isTrue); | |
| 583 CompletionSuggestion suggestion = assertSuggestLocalFunction('m', 'void'); | |
| 584 expect(suggestion.parameterNames, hasLength(2)); | |
| 585 expect(suggestion.parameterNames[0], 'x'); | |
| 586 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 587 expect(suggestion.parameterNames[1], 'y'); | |
| 588 expect(suggestion.parameterTypes[1], 'int'); | |
| 589 expect(suggestion.requiredParameterCount, 2); | |
| 590 expect(suggestion.hasNamedParameters, false); | |
| 591 } | |
| 592 | |
| 593 test_ignore_symbol_being_completed() { | |
| 594 addTestSource('class MyClass { } main(MC^) { }'); | |
| 595 expect(computeFast(), isTrue); | |
| 596 assertSuggestLocalClass('MyClass'); | |
| 597 assertNotSuggested('MC'); | |
| 598 } | |
| 599 | |
| 600 test_inComment_block_beforeNode() { | |
| 601 addTestSource(''' | |
| 602 main(aaa, bbb) { | |
| 603 /* text ^ */ | |
| 604 print(42); | |
| 605 } | |
| 606 '''); | |
| 607 expect(computeFast(), isTrue); | |
| 608 assertNoSuggestions(); | |
| 609 } | |
| 610 | |
| 611 test_inComment_endOfLine_beforeNode() { | |
| 612 addTestSource(''' | |
| 613 main(aaa, bbb) { | |
| 614 // text ^ | |
| 615 print(42); | |
| 616 } | |
| 617 '''); | |
| 618 expect(computeFast(), isTrue); | |
| 619 assertNoSuggestions(); | |
| 620 } | |
| 621 | |
| 622 test_inComment_endOfLine_beforeToken() { | |
| 623 addTestSource(''' | |
| 624 main(aaa, bbb) { | |
| 625 // text ^ | |
| 626 } | |
| 627 '''); | |
| 628 expect(computeFast(), isTrue); | |
| 629 assertNoSuggestions(); | |
| 630 } | |
| 631 | |
| 632 test_InstanceCreationExpression() { | |
| 633 addTestSource(''' | |
| 634 class A {foo(){var f; {var x;}}} | |
| 635 class B {B(this.x, [String boo]) { } int x;} | |
| 636 class C {C.bar({boo: 'hoo', int z: 0}) { } } | |
| 637 main() {new ^ String x = "hello";}'''); | |
| 638 computeFast(); | |
| 639 return computeFull((bool result) { | |
| 640 // Suggested by ConstructorContributor | |
| 641 assertNotSuggested('A'); | |
| 642 assertNotSuggested('B'); | |
| 643 assertNotSuggested('C.bar'); | |
| 644 }); | |
| 645 } | |
| 646 | |
| 647 test_method_parameters_mixed_required_and_named() { | |
| 648 addTestSource(''' | |
| 649 class A { | |
| 650 void m(x, {int y}) {} | |
| 651 } | |
| 652 class B extends A { | |
| 653 main() {^} | |
| 654 } | |
| 655 '''); | |
| 656 expect(computeFast(), isTrue); | |
| 657 CompletionSuggestion suggestion = | |
| 658 assertSuggestLocalMethod('m', 'A', 'void'); | |
| 659 expect(suggestion.parameterNames, hasLength(2)); | |
| 660 expect(suggestion.parameterNames[0], 'x'); | |
| 661 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 662 expect(suggestion.parameterNames[1], 'y'); | |
| 663 expect(suggestion.parameterTypes[1], 'int'); | |
| 664 expect(suggestion.requiredParameterCount, 1); | |
| 665 expect(suggestion.hasNamedParameters, true); | |
| 666 } | |
| 667 | |
| 668 test_method_parameters_mixed_required_and_positional() { | |
| 669 addTestSource(''' | |
| 670 class A { | |
| 671 void m(x, [int y]) {} | |
| 672 } | |
| 673 class B extends A { | |
| 674 main() {^} | |
| 675 } | |
| 676 '''); | |
| 677 expect(computeFast(), isTrue); | |
| 678 CompletionSuggestion suggestion = | |
| 679 assertSuggestLocalMethod('m', 'A', 'void'); | |
| 680 expect(suggestion.parameterNames, hasLength(2)); | |
| 681 expect(suggestion.parameterNames[0], 'x'); | |
| 682 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 683 expect(suggestion.parameterNames[1], 'y'); | |
| 684 expect(suggestion.parameterTypes[1], 'int'); | |
| 685 expect(suggestion.requiredParameterCount, 1); | |
| 686 expect(suggestion.hasNamedParameters, false); | |
| 687 } | |
| 688 | |
| 689 test_method_parameters_named() { | |
| 690 addTestSource(''' | |
| 691 class A { | |
| 692 void m({x, int y}) {} | |
| 693 } | |
| 694 class B extends A { | |
| 695 main() {^} | |
| 696 } | |
| 697 '''); | |
| 698 expect(computeFast(), isTrue); | |
| 699 CompletionSuggestion suggestion = | |
| 700 assertSuggestLocalMethod('m', 'A', 'void'); | |
| 701 expect(suggestion.parameterNames, hasLength(2)); | |
| 702 expect(suggestion.parameterNames[0], 'x'); | |
| 703 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 704 expect(suggestion.parameterNames[1], 'y'); | |
| 705 expect(suggestion.parameterTypes[1], 'int'); | |
| 706 expect(suggestion.requiredParameterCount, 0); | |
| 707 expect(suggestion.hasNamedParameters, true); | |
| 708 } | |
| 709 | |
| 710 test_method_parameters_none() { | |
| 711 addTestSource(''' | |
| 712 class A { | |
| 713 void m() {} | |
| 714 } | |
| 715 class B extends A { | |
| 716 main() {^} | |
| 717 } | |
| 718 '''); | |
| 719 expect(computeFast(), isTrue); | |
| 720 CompletionSuggestion suggestion = | |
| 721 assertSuggestLocalMethod('m', 'A', 'void'); | |
| 722 expect(suggestion.parameterNames, isEmpty); | |
| 723 expect(suggestion.parameterTypes, isEmpty); | |
| 724 expect(suggestion.requiredParameterCount, 0); | |
| 725 expect(suggestion.hasNamedParameters, false); | |
| 726 } | |
| 727 | |
| 728 test_method_parameters_positional() { | |
| 729 addTestSource(''' | |
| 730 class A { | |
| 731 void m([x, int y]) {} | |
| 732 } | |
| 733 class B extends A { | |
| 734 main() {^} | |
| 735 } | |
| 736 '''); | |
| 737 expect(computeFast(), isTrue); | |
| 738 CompletionSuggestion suggestion = | |
| 739 assertSuggestLocalMethod('m', 'A', 'void'); | |
| 740 expect(suggestion.parameterNames, hasLength(2)); | |
| 741 expect(suggestion.parameterNames[0], 'x'); | |
| 742 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 743 expect(suggestion.parameterNames[1], 'y'); | |
| 744 expect(suggestion.parameterTypes[1], 'int'); | |
| 745 expect(suggestion.requiredParameterCount, 0); | |
| 746 expect(suggestion.hasNamedParameters, false); | |
| 747 } | |
| 748 | |
| 749 test_method_parameters_required() { | |
| 750 addTestSource(''' | |
| 751 class A { | |
| 752 void m(x, int y) {} | |
| 753 } | |
| 754 class B extends A { | |
| 755 main() {^} | |
| 756 } | |
| 757 '''); | |
| 758 expect(computeFast(), isTrue); | |
| 759 CompletionSuggestion suggestion = | |
| 760 assertSuggestLocalMethod('m', 'A', 'void'); | |
| 761 expect(suggestion.parameterNames, hasLength(2)); | |
| 762 expect(suggestion.parameterNames[0], 'x'); | |
| 763 expect(suggestion.parameterTypes[0], 'dynamic'); | |
| 764 expect(suggestion.parameterNames[1], 'y'); | |
| 765 expect(suggestion.parameterTypes[1], 'int'); | |
| 766 expect(suggestion.requiredParameterCount, 2); | |
| 767 expect(suggestion.hasNamedParameters, false); | |
| 768 } | |
| 769 | |
| 770 test_missing_params_constructor() { | |
| 771 addTestSource('class C1{C1{} main(){C^}}'); | |
| 772 expect(computeFast(), isTrue); | |
| 773 } | |
| 774 | |
| 775 test_missing_params_function() { | |
| 776 addTestSource('int f1{} main(){f^}'); | |
| 777 expect(computeFast(), isTrue); | |
| 778 } | |
| 779 | |
| 780 test_missing_params_method() { | |
| 781 addTestSource('class C1{int f1{} main(){f^}}'); | |
| 782 expect(computeFast(), isTrue); | |
| 783 } | |
| 784 | |
| 785 test_overrides() { | |
| 786 addTestSource(''' | |
| 787 class A {m() {}} | |
| 788 class B extends A {m() {^}} | |
| 789 '''); | |
| 790 expect(computeFast(), isTrue); | |
| 791 assertSuggestMethod('m', 'B', null, relevance: DART_RELEVANCE_LOCAL_METHOD); | |
| 792 } | |
| 793 | |
| 794 test_prioritization_private() { | |
| 795 addTestSource('main() {var ab; var _ab; _^}'); | |
| 796 expect(computeFast(), isTrue); | |
| 797 assertSuggestLocalVariable('ab', null); | |
| 798 assertSuggestLocalVariable('_ab', null); | |
| 799 } | |
| 800 | |
| 801 test_prioritization_public() { | |
| 802 addTestSource('main() {var ab; var _ab; a^}'); | |
| 803 expect(computeFast(), isTrue); | |
| 804 assertSuggestLocalVariable('ab', null); | |
| 805 assertSuggestLocalVariable('_ab', null, relevance: DART_RELEVANCE_DEFAULT); | |
| 806 } | |
| 807 | |
| 808 test_shadowed_name() { | |
| 809 addTestSource('var a; class A { var a; m() { ^ } }'); | |
| 810 expect(computeFast(), isTrue); | |
| 811 assertSuggestLocalField('a', null); | |
| 812 } | |
| 813 } | |
| OLD | NEW |