| OLD | NEW |
| 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.util; | 5 library test.services.completion.util; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, | 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, |
| 10 ElementKind; | 10 ElementKind; |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 main(){var a; if (a is ^)}'''); | 531 main(){var a; if (a is ^)}'''); |
| 532 computeFast(); | 532 computeFast(); |
| 533 return computeFull(true).then((_) { | 533 return computeFull(true).then((_) { |
| 534 assertNotSuggested('a'); | 534 assertNotSuggested('a'); |
| 535 assertNotSuggested('main'); | 535 assertNotSuggested('main'); |
| 536 assertSuggestLocalClass('A'); | 536 assertSuggestLocalClass('A'); |
| 537 assertSuggestImportedClass('Object'); | 537 assertSuggestImportedClass('Object'); |
| 538 }); | 538 }); |
| 539 } | 539 } |
| 540 | 540 |
| 541 test_AssignmentExpression_RHS() { |
| 542 // SimpleIdentifier VariableDeclaration VariableDeclarationList |
| 543 // VariableDeclarationStatement Block |
| 544 addTestSource('class A {} main() {int a; int b = ^}'); |
| 545 computeFast(); |
| 546 return computeFull(true).then((_) { |
| 547 assertSuggestLocalVariable('a', 'int'); |
| 548 assertSuggestLocalFunction('main', null); |
| 549 assertSuggestLocalClass('A'); |
| 550 assertSuggestImportedClass('Object'); |
| 551 }); |
| 552 } |
| 553 |
| 554 test_AssignmentExpression_name() { |
| 555 // SimpleIdentifier VariableDeclaration VariableDeclarationList |
| 556 // VariableDeclarationStatement Block |
| 557 addTestSource('class A {} main() {int a; int ^b = 1;}'); |
| 558 computeFast(); |
| 559 return computeFull(true).then((_) { |
| 560 assertNoSuggestions(); |
| 561 }); |
| 562 } |
| 563 |
| 564 test_AssignmentExpression_type() { |
| 565 // SimpleIdentifier TypeName VariableDeclarationList |
| 566 // VariableDeclarationStatement Block |
| 567 addTestSource('class A {} main() {int a; int^ b = 1;}'); |
| 568 computeFast(); |
| 569 return computeFull(true).then((_) { |
| 570 assertSuggestLocalClass('A'); |
| 571 assertSuggestImportedClass('int'); |
| 572 assertNotSuggested('a'); |
| 573 assertNotSuggested('main'); |
| 574 }); |
| 575 } |
| 576 |
| 577 test_AwaitExpression() { |
| 578 // SimpleIdentifier AwaitExpression ExpressionStatement |
| 579 addTestSource(''' |
| 580 class A {int x; int y() => 0;} |
| 581 main(){A a; await ^}'''); |
| 582 computeFast(); |
| 583 return computeFull(true).then((_) { |
| 584 assertSuggestLocalVariable('a', 'A'); |
| 585 assertSuggestLocalFunction('main', null); |
| 586 assertSuggestLocalClass('A'); |
| 587 assertSuggestImportedClass('Object'); |
| 588 }); |
| 589 } |
| 590 |
| 541 test_BinaryExpression_LHS() { | 591 test_BinaryExpression_LHS() { |
| 542 // SimpleIdentifier BinaryExpression VariableDeclaration | 592 // SimpleIdentifier BinaryExpression VariableDeclaration |
| 543 // VariableDeclarationList VariableDeclarationStatement | 593 // VariableDeclarationList VariableDeclarationStatement |
| 544 addTestSource('main() {int a = 1, b = ^ + 2;}'); | 594 addTestSource('main() {int a = 1, b = ^ + 2;}'); |
| 545 computeFast(); | 595 computeFast(); |
| 546 return computeFull(true).then((_) { | 596 return computeFull(true).then((_) { |
| 547 assertSuggestLocalVariable('a', 'int'); | 597 assertSuggestLocalVariable('a', 'int'); |
| 548 assertSuggestImportedClass('Object'); | 598 assertSuggestImportedClass('Object'); |
| 549 assertNotSuggested('b'); | 599 assertNotSuggested('b'); |
| 550 }); | 600 }); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 int T3; | 633 int T3; |
| 584 var _T4;'''); // not imported | 634 var _T4;'''); // not imported |
| 585 addTestSource(''' | 635 addTestSource(''' |
| 586 import "/testAB.dart"; | 636 import "/testAB.dart"; |
| 587 import "/testCD.dart" hide D; | 637 import "/testCD.dart" hide D; |
| 588 import "/testEEF.dart" show EE; | 638 import "/testEEF.dart" show EE; |
| 589 import "/testG.dart" as g; | 639 import "/testG.dart" as g; |
| 590 int T5; | 640 int T5; |
| 591 var _T6; | 641 var _T6; |
| 592 Z D2() {int x;} | 642 Z D2() {int x;} |
| 593 class X {a() {var f; {var x;} ^ var r;} Z b() { }} | 643 class X {a() {var f; {var x;} ^ var r;} void b() { }} |
| 594 class Z { }'''); | 644 class Z { }'''); |
| 595 computeFast(); | 645 computeFast(); |
| 596 return computeFull(true).then((_) { | 646 return computeFull(true).then((_) { |
| 597 | 647 |
| 598 assertSuggestLocalClass('X'); | 648 assertSuggestLocalClass('X'); |
| 599 assertSuggestLocalClass('Z'); | 649 assertSuggestLocalClass('Z'); |
| 600 assertLocalSuggestMethod('a', 'X', null); | 650 assertLocalSuggestMethod('a', 'X', null); |
| 601 assertLocalSuggestMethod('b', 'X', 'Z'); | 651 assertLocalSuggestMethod('b', 'X', 'void'); |
| 602 assertSuggestLocalVariable('f', null); | 652 assertSuggestLocalVariable('f', null); |
| 603 // Don't suggest locals out of scope | 653 // Don't suggest locals out of scope |
| 604 assertNotSuggested('r'); | 654 assertNotSuggested('r'); |
| 605 assertNotSuggested('x'); | 655 assertNotSuggested('x'); |
| 606 | 656 |
| 607 assertSuggestImportedClass('A'); | 657 assertSuggestImportedClass('A'); |
| 608 assertNotSuggested('_B'); | 658 assertNotSuggested('_B'); |
| 609 assertSuggestImportedClass('C'); | 659 assertSuggestImportedClass('C'); |
| 610 // hidden element suggested as low relevance | 660 // hidden element suggested as low relevance |
| 611 assertSuggestImportedClass('D', CompletionRelevance.LOW); | 661 assertSuggestImportedClass('D', CompletionRelevance.LOW); |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 computeFast(); | 1160 computeFast(); |
| 1111 return computeFull(true).then((_) { | 1161 return computeFull(true).then((_) { |
| 1112 assertSuggestImportedClass('X'); | 1162 assertSuggestImportedClass('X'); |
| 1113 assertSuggestLocalClass('Y'); | 1163 assertSuggestLocalClass('Y'); |
| 1114 assertNotSuggested('x'); | 1164 assertNotSuggested('x'); |
| 1115 assertNotSuggested('main'); | 1165 assertNotSuggested('main'); |
| 1116 assertNotSuggested('foo'); | 1166 assertNotSuggested('foo'); |
| 1117 }); | 1167 }); |
| 1118 } | 1168 } |
| 1119 | 1169 |
| 1170 test_Literal_string() { |
| 1171 // SimpleStringLiteral ExpressionStatement Block |
| 1172 addTestSource('class A {a() {"hel^lo"}}'); |
| 1173 computeFast(); |
| 1174 return computeFull(true).then((_) { |
| 1175 assertNoSuggestions(); |
| 1176 }); |
| 1177 } |
| 1178 |
| 1120 test_MethodDeclaration_body_getters() { | 1179 test_MethodDeclaration_body_getters() { |
| 1121 // Block BlockFunctionBody MethodDeclaration | 1180 // Block BlockFunctionBody MethodDeclaration |
| 1122 addTestSource('class A {@deprecated X get f => 0; Z a() {^} get _g => 1;}'); | 1181 addTestSource('class A {@deprecated X get f => 0; Z a() {^} get _g => 1;}'); |
| 1123 computeFast(); | 1182 computeFast(); |
| 1124 return computeFull(true).then((_) { | 1183 return computeFull(true).then((_) { |
| 1125 CompletionSuggestion methodA = assertSuggestLocalMethod('a', 'A', 'Z'); | 1184 CompletionSuggestion methodA = assertSuggestLocalMethod('a', 'A', 'Z'); |
| 1126 if (methodA != null) { | 1185 if (methodA != null) { |
| 1127 expect(methodA.element.isDeprecated, isFalse); | 1186 expect(methodA.element.isDeprecated, isFalse); |
| 1128 expect(methodA.element.isPrivate, isFalse); | 1187 expect(methodA.element.isPrivate, isFalse); |
| 1129 } | 1188 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 addTestSource(''' | 1452 addTestSource(''' |
| 1394 import "/testB.dart"; | 1453 import "/testB.dart"; |
| 1395 class Y {Y.c(); Y._d(); z() {}} | 1454 class Y {Y.c(); Y._d(); z() {}} |
| 1396 main() {var ^}'''); | 1455 main() {var ^}'''); |
| 1397 computeFast(); | 1456 computeFast(); |
| 1398 return computeFull(true).then((_) { | 1457 return computeFull(true).then((_) { |
| 1399 assertNoSuggestions(); | 1458 assertNoSuggestions(); |
| 1400 }); | 1459 }); |
| 1401 } | 1460 } |
| 1402 } | 1461 } |
| OLD | NEW |