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 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 | 574 |
575 test_BinaryExpression_RHS() { | 575 test_BinaryExpression_RHS() { |
576 // SimpleIdentifier BinaryExpression VariableDeclaration | 576 // SimpleIdentifier BinaryExpression VariableDeclaration |
577 // VariableDeclarationList VariableDeclarationStatement | 577 // VariableDeclarationList VariableDeclarationStatement |
578 addTestSource('main() {int a = 1, b = 2 + ^;}'); | 578 addTestSource('main() {int a = 1, b = 2 + ^;}'); |
579 computeFast(); | 579 computeFast(); |
580 return computeFull(true).then((_) { | 580 return computeFull(true).then((_) { |
581 assertSuggestLocalVariable('a', 'int'); | 581 assertSuggestLocalVariable('a', 'int'); |
582 assertSuggestImportedClass('Object'); | 582 assertSuggestImportedClass('Object'); |
583 assertNotSuggested('b'); | 583 assertNotSuggested('b'); |
| 584 assertNotSuggested('=='); |
584 }); | 585 }); |
585 } | 586 } |
586 | 587 |
587 test_Block() { | 588 test_Block() { |
588 // Block BlockFunctionBody MethodDeclaration | 589 // Block BlockFunctionBody MethodDeclaration |
589 addSource('/testAB.dart', ''' | 590 addSource('/testAB.dart', ''' |
590 export "dart:math" hide max; | 591 export "dart:math" hide max; |
591 class A {int x;} | 592 class A {int x;} |
592 @deprecated D1() {int x;} | 593 @deprecated D1() {int x;} |
593 class _B { }'''); | 594 class _B { }'''); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 'max', | 646 'max', |
646 'num', | 647 'num', |
647 false, | 648 false, |
648 CompletionRelevance.LOW); | 649 CompletionRelevance.LOW); |
649 assertSuggestTopLevelVarGetterSetter('T1', 'String'); | 650 assertSuggestTopLevelVarGetterSetter('T1', 'String'); |
650 assertNotSuggested('_T2'); | 651 assertNotSuggested('_T2'); |
651 assertSuggestImportedTopLevelVar('T3', 'int', CompletionRelevance.LOW); | 652 assertSuggestImportedTopLevelVar('T3', 'int', CompletionRelevance.LOW); |
652 assertNotSuggested('_T4'); | 653 assertNotSuggested('_T4'); |
653 assertSuggestLocalTopLevelVar('T5', 'int'); | 654 assertSuggestLocalTopLevelVar('T5', 'int'); |
654 assertSuggestLocalTopLevelVar('_T6', null); | 655 assertSuggestLocalTopLevelVar('_T6', null); |
| 656 assertNotSuggested('=='); |
655 // TODO (danrubel) suggest HtmlElement as low relevance | 657 // TODO (danrubel) suggest HtmlElement as low relevance |
656 assertNotSuggested('HtmlElement'); | 658 assertNotSuggested('HtmlElement'); |
657 }); | 659 }); |
658 } | 660 } |
659 | 661 |
660 test_CascadeExpression_selector1() { | 662 test_CascadeExpression_selector1() { |
661 // PropertyAccess CascadeExpression ExpressionStatement Block | 663 // PropertyAccess CascadeExpression ExpressionStatement Block |
662 addSource('/testB.dart', ''' | 664 addSource('/testB.dart', ''' |
663 class B { }'''); | 665 class B { }'''); |
664 addTestSource(''' | 666 addTestSource(''' |
665 import "/testB.dart"; | 667 import "/testB.dart"; |
666 class A {var b; X _c;} | 668 class A {var b; X _c;} |
667 class X{} | 669 class X{} |
668 // looks like a cascade to the parser | 670 // looks like a cascade to the parser |
669 // but the user is trying to get completions for a non-cascade | 671 // but the user is trying to get completions for a non-cascade |
670 main() {A a; a.^.z}'''); | 672 main() {A a; a.^.z}'''); |
671 computeFast(); | 673 computeFast(); |
672 return computeFull(true).then((_) { | 674 return computeFull(true).then((_) { |
673 assertSuggestInvocationGetter('b', null); | 675 assertSuggestInvocationGetter('b', null); |
674 assertSuggestInvocationGetter('_c', 'X'); | 676 assertSuggestInvocationGetter('_c', 'X'); |
675 assertNotSuggested('Object'); | 677 assertNotSuggested('Object'); |
676 assertNotSuggested('A'); | 678 assertNotSuggested('A'); |
677 assertNotSuggested('B'); | 679 assertNotSuggested('B'); |
678 assertNotSuggested('X'); | 680 assertNotSuggested('X'); |
679 assertNotSuggested('z'); | 681 assertNotSuggested('z'); |
| 682 assertNotSuggested('=='); |
680 }); | 683 }); |
681 } | 684 } |
682 | 685 |
683 test_CascadeExpression_selector2() { | 686 test_CascadeExpression_selector2() { |
684 // SimpleIdentifier PropertyAccess CascadeExpression ExpressionStatement | 687 // SimpleIdentifier PropertyAccess CascadeExpression ExpressionStatement |
685 addSource('/testB.dart', ''' | 688 addSource('/testB.dart', ''' |
686 class B { }'''); | 689 class B { }'''); |
687 addTestSource(''' | 690 addTestSource(''' |
688 import "/testB.dart"; | 691 import "/testB.dart"; |
689 class A {var b; X _c;} | 692 class A {var b; X _c;} |
690 class X{} | 693 class X{} |
691 main() {A a; a..^z}'''); | 694 main() {A a; a..^z}'''); |
692 computeFast(); | 695 computeFast(); |
693 return computeFull(true).then((_) { | 696 return computeFull(true).then((_) { |
694 assertSuggestInvocationGetter('b', null); | 697 assertSuggestInvocationGetter('b', null); |
695 assertSuggestInvocationGetter('_c', 'X'); | 698 assertSuggestInvocationGetter('_c', 'X'); |
696 assertNotSuggested('Object'); | 699 assertNotSuggested('Object'); |
697 assertNotSuggested('A'); | 700 assertNotSuggested('A'); |
698 assertNotSuggested('B'); | 701 assertNotSuggested('B'); |
699 assertNotSuggested('X'); | 702 assertNotSuggested('X'); |
700 assertNotSuggested('z'); | 703 assertNotSuggested('z'); |
| 704 assertNotSuggested('=='); |
701 }); | 705 }); |
702 } | 706 } |
703 | 707 |
704 test_CascadeExpression_target() { | 708 test_CascadeExpression_target() { |
705 // SimpleIdentifier CascadeExpression ExpressionStatement | 709 // SimpleIdentifier CascadeExpression ExpressionStatement |
706 addTestSource(''' | 710 addTestSource(''' |
707 class A {var b; X _c;} | 711 class A {var b; X _c;} |
708 class X{} | 712 class X{} |
709 main() {A a; a^..b}'''); | 713 main() {A a; a^..b}'''); |
710 computeFast(); | 714 computeFast(); |
711 return computeFull(true).then((_) { | 715 return computeFull(true).then((_) { |
712 assertNotSuggested('b'); | 716 assertNotSuggested('b'); |
713 assertNotSuggested('_c'); | 717 assertNotSuggested('_c'); |
714 assertSuggestLocalVariable('a', 'A'); | 718 assertSuggestLocalVariable('a', 'A'); |
715 assertSuggestLocalClass('A'); | 719 assertSuggestLocalClass('A'); |
716 assertSuggestLocalClass('X'); | 720 assertSuggestLocalClass('X'); |
717 assertSuggestImportedClass('Object'); | 721 assertSuggestImportedClass('Object'); |
| 722 assertNotSuggested('=='); |
718 }); | 723 }); |
719 } | 724 } |
720 | 725 |
721 test_CatchClause_typed() { | 726 test_CatchClause_typed() { |
722 // Block CatchClause TryStatement | 727 // Block CatchClause TryStatement |
723 addTestSource('class A {a() {try{var x;} on E catch (e) {^}}}'); | 728 addTestSource('class A {a() {try{var x;} on E catch (e) {^}}}'); |
724 computeFast(); | 729 computeFast(); |
725 return computeFull(true).then((_) { | 730 return computeFull(true).then((_) { |
726 assertSuggestParameter('e', 'E'); | 731 assertSuggestParameter('e', 'E'); |
727 assertSuggestLocalMethod('a', 'A', null); | 732 assertSuggestLocalMethod('a', 'A', null); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 } | 1103 } |
1099 | 1104 |
1100 test_InterpolationExpression_prefix_selector() { | 1105 test_InterpolationExpression_prefix_selector() { |
1101 // SimpleIdentifier PrefixedIdentifier InterpolationExpression | 1106 // SimpleIdentifier PrefixedIdentifier InterpolationExpression |
1102 addTestSource('main() {String name; print("hello \${name.^}");}'); | 1107 addTestSource('main() {String name; print("hello \${name.^}");}'); |
1103 computeFast(); | 1108 computeFast(); |
1104 return computeFull(true).then((_) { | 1109 return computeFull(true).then((_) { |
1105 assertSuggestInvocationGetter('length', 'int'); | 1110 assertSuggestInvocationGetter('length', 'int'); |
1106 assertNotSuggested('name'); | 1111 assertNotSuggested('name'); |
1107 assertNotSuggested('Object'); | 1112 assertNotSuggested('Object'); |
| 1113 assertNotSuggested('=='); |
1108 }); | 1114 }); |
1109 } | 1115 } |
1110 | 1116 |
1111 test_InterpolationExpression_prefix_target() { | 1117 test_InterpolationExpression_prefix_target() { |
1112 // SimpleIdentifier PrefixedIdentifier InterpolationExpression | 1118 // SimpleIdentifier PrefixedIdentifier InterpolationExpression |
1113 addTestSource('main() {String name; print("hello \${nam^e.length}");}'); | 1119 addTestSource('main() {String name; print("hello \${nam^e.length}");}'); |
1114 computeFast(); | 1120 computeFast(); |
1115 return computeFull(true).then((_) { | 1121 return computeFull(true).then((_) { |
1116 assertSuggestLocalVariable('name', 'String'); | 1122 assertSuggestLocalVariable('name', 'String'); |
1117 assertSuggestImportedClass('Object'); | 1123 assertSuggestImportedClass('Object'); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 assertSuggestInvocationGetter('f', 'X'); | 1280 assertSuggestInvocationGetter('f', 'X'); |
1275 assertNotSuggested('_g'); | 1281 assertNotSuggested('_g'); |
1276 assertSuggestInvocationSetter('s1'); | 1282 assertSuggestInvocationSetter('s1'); |
1277 assertNotSuggested('_s2'); | 1283 assertNotSuggested('_s2'); |
1278 assertSuggestInvocationMethod('m', 'A', null); | 1284 assertSuggestInvocationMethod('m', 'A', null); |
1279 assertNotSuggested('_n'); | 1285 assertNotSuggested('_n'); |
1280 assertNotSuggested('a'); | 1286 assertNotSuggested('a'); |
1281 assertNotSuggested('A'); | 1287 assertNotSuggested('A'); |
1282 assertNotSuggested('X'); | 1288 assertNotSuggested('X'); |
1283 assertNotSuggested('Object'); | 1289 assertNotSuggested('Object'); |
| 1290 assertNotSuggested('=='); |
1284 }); | 1291 }); |
1285 } | 1292 } |
1286 | 1293 |
1287 test_PrefixedIdentifier_class_local() { | 1294 test_PrefixedIdentifier_class_local() { |
1288 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | 1295 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
1289 addTestSource(''' | 1296 addTestSource(''' |
1290 main() {A a; a.^} | 1297 main() {A a; a.^} |
1291 class I {X get f => new A();get _g => new A();} | 1298 class I {X get f => new A();get _g => new A();} |
1292 class A implements I { | 1299 class A implements I { |
1293 var b; X _c; | 1300 var b; X _c; |
(...skipping 10 matching lines...) Expand all Loading... |
1304 assertSuggestInvocationGetter('f', 'X'); | 1311 assertSuggestInvocationGetter('f', 'X'); |
1305 assertSuggestInvocationGetter('_g', null); | 1312 assertSuggestInvocationGetter('_g', null); |
1306 assertSuggestInvocationSetter('s1'); | 1313 assertSuggestInvocationSetter('s1'); |
1307 assertSuggestInvocationSetter('_s2'); | 1314 assertSuggestInvocationSetter('_s2'); |
1308 assertSuggestInvocationMethod('m', 'A', null); | 1315 assertSuggestInvocationMethod('m', 'A', null); |
1309 assertSuggestInvocationMethod('_n', 'A', 'I'); | 1316 assertSuggestInvocationMethod('_n', 'A', 'I'); |
1310 assertNotSuggested('a'); | 1317 assertNotSuggested('a'); |
1311 assertNotSuggested('A'); | 1318 assertNotSuggested('A'); |
1312 assertNotSuggested('X'); | 1319 assertNotSuggested('X'); |
1313 assertNotSuggested('Object'); | 1320 assertNotSuggested('Object'); |
| 1321 assertNotSuggested('=='); |
1314 }); | 1322 }); |
1315 } | 1323 } |
1316 | 1324 |
1317 test_PrefixedIdentifier_library() { | 1325 test_PrefixedIdentifier_library() { |
1318 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | 1326 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
1319 addSource('/testB.dart', ''' | 1327 addSource('/testB.dart', ''' |
1320 lib B; | 1328 lib B; |
1321 var T1; | 1329 var T1; |
1322 class X { } | 1330 class X { } |
1323 class Y { }'''); | 1331 class Y { }'''); |
1324 addTestSource(''' | 1332 addTestSource(''' |
1325 import "/testB.dart" as b; | 1333 import "/testB.dart" as b; |
1326 var T2; | 1334 var T2; |
1327 class A { } | 1335 class A { } |
1328 main() {b.^}'''); | 1336 main() {b.^}'''); |
1329 computeFast(); | 1337 computeFast(); |
1330 return computeFull(true).then((_) { | 1338 return computeFull(true).then((_) { |
1331 assertSuggestInvocationClass('X'); | 1339 assertSuggestInvocationClass('X'); |
1332 assertSuggestInvocationClass('Y'); | 1340 assertSuggestInvocationClass('Y'); |
1333 assertSuggestInvocationTopLevelVar('T1', null); | 1341 assertSuggestInvocationTopLevelVar('T1', null); |
1334 assertNotSuggested('T2'); | 1342 assertNotSuggested('T2'); |
1335 assertNotSuggested('Object'); | 1343 assertNotSuggested('Object'); |
1336 assertNotSuggested('b'); | 1344 assertNotSuggested('b'); |
1337 assertNotSuggested('A'); | 1345 assertNotSuggested('A'); |
| 1346 assertNotSuggested('=='); |
1338 }); | 1347 }); |
1339 } | 1348 } |
1340 | 1349 |
1341 test_PrefixedIdentifier_parameter() { | 1350 test_PrefixedIdentifier_parameter() { |
1342 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | 1351 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
1343 addSource('/testB.dart', ''' | 1352 addSource('/testB.dart', ''' |
1344 lib B; | 1353 lib B; |
1345 class _W {M y; var _z;} | 1354 class _W {M y; var _z;} |
1346 class X extends _W {} | 1355 class X extends _W {} |
1347 class M{}'''); | 1356 class M{}'''); |
1348 addTestSource(''' | 1357 addTestSource(''' |
1349 import "/testB.dart"; | 1358 import "/testB.dart"; |
1350 foo(X x) {x.^}'''); | 1359 foo(X x) {x.^}'''); |
1351 computeFast(); | 1360 computeFast(); |
1352 return computeFull(true).then((_) { | 1361 return computeFull(true).then((_) { |
1353 assertSuggestInvocationGetter('y', 'M'); | 1362 assertSuggestInvocationGetter('y', 'M'); |
1354 assertNotSuggested('_z'); | 1363 assertNotSuggested('_z'); |
| 1364 assertNotSuggested('=='); |
1355 }); | 1365 }); |
1356 } | 1366 } |
1357 | 1367 |
1358 test_PrefixedIdentifier_prefix() { | 1368 test_PrefixedIdentifier_prefix() { |
1359 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | 1369 // SimpleIdentifier PrefixedIdentifier ExpressionStatement |
1360 addSource('/testA.dart', ''' | 1370 addSource('/testA.dart', ''' |
1361 class A {static int bar = 10;} | 1371 class A {static int bar = 10;} |
1362 _B() {}'''); | 1372 _B() {}'''); |
1363 addTestSource(''' | 1373 addTestSource(''' |
1364 import "/testA.dart"; | 1374 import "/testA.dart"; |
1365 class X {foo(){A^.bar}}'''); | 1375 class X {foo(){A^.bar}}'''); |
1366 computeFast(); | 1376 computeFast(); |
1367 return computeFull(true).then((_) { | 1377 return computeFull(true).then((_) { |
1368 assertSuggestImportedClass('A'); | 1378 assertSuggestImportedClass('A'); |
1369 assertSuggestLocalClass('X'); | 1379 assertSuggestLocalClass('X'); |
1370 assertSuggestLocalMethod('foo', 'X', null); | 1380 assertSuggestLocalMethod('foo', 'X', null); |
1371 assertNotSuggested('bar'); | 1381 assertNotSuggested('bar'); |
1372 assertNotSuggested('_B'); | 1382 assertNotSuggested('_B'); |
1373 }); | 1383 }); |
1374 } | 1384 } |
1375 | 1385 |
1376 test_PropertyAccess_expression() { | 1386 test_PropertyAccess_expression() { |
1377 // SimpleIdentifier MethodInvocation PropertyAccess ExpressionStatement | 1387 // SimpleIdentifier MethodInvocation PropertyAccess ExpressionStatement |
1378 addTestSource('class A {a() {"hello".to^String().length}}'); | 1388 addTestSource('class A {a() {"hello".to^String().length}}'); |
1379 computeFast(); | 1389 computeFast(); |
1380 return computeFull(true).then((_) { | 1390 return computeFull(true).then((_) { |
1381 assertSuggestInvocationGetter('length', 'int'); | 1391 assertSuggestInvocationGetter('length', 'int'); |
| 1392 assertNotSuggested('=='); |
1382 assertNotSuggested('A'); | 1393 assertNotSuggested('A'); |
1383 assertNotSuggested('a'); | 1394 assertNotSuggested('a'); |
1384 assertNotSuggested('Object'); | 1395 assertNotSuggested('Object'); |
| 1396 assertNotSuggested('=='); |
1385 }); | 1397 }); |
1386 } | 1398 } |
1387 | 1399 |
1388 test_PropertyAccess_selector() { | 1400 test_PropertyAccess_selector() { |
1389 // SimpleIdentifier PropertyAccess ExpressionStatement Block | 1401 // SimpleIdentifier PropertyAccess ExpressionStatement Block |
1390 addTestSource('class A {a() {"hello".length.^}}'); | 1402 addTestSource('class A {a() {"hello".length.^}}'); |
1391 computeFast(); | 1403 computeFast(); |
1392 return computeFull(true).then((_) { | 1404 return computeFull(true).then((_) { |
1393 assertSuggestInvocationGetter('isEven', 'bool'); | 1405 assertSuggestInvocationGetter('isEven', 'bool'); |
1394 assertNotSuggested('A'); | 1406 assertNotSuggested('A'); |
1395 assertNotSuggested('a'); | 1407 assertNotSuggested('a'); |
1396 assertNotSuggested('Object'); | 1408 assertNotSuggested('Object'); |
| 1409 assertNotSuggested('=='); |
1397 }); | 1410 }); |
1398 } | 1411 } |
1399 | 1412 |
1400 test_TopLevelVariableDeclaration_typed_name() { | 1413 test_TopLevelVariableDeclaration_typed_name() { |
1401 // SimpleIdentifier VariableDeclaration VariableDeclarationList | 1414 // SimpleIdentifier VariableDeclaration VariableDeclarationList |
1402 // TopLevelVariableDeclaration | 1415 // TopLevelVariableDeclaration |
1403 addTestSource('class A {} B ^'); | 1416 addTestSource('class A {} B ^'); |
1404 computeFast(); | 1417 computeFast(); |
1405 return computeFull(true).then((_) { | 1418 return computeFull(true).then((_) { |
1406 assertNoSuggestions(); | 1419 assertNoSuggestions(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 assertSuggestImportedClass('X'); | 1489 assertSuggestImportedClass('X'); |
1477 assertNotSuggested('_B'); | 1490 assertNotSuggested('_B'); |
1478 assertSuggestLocalClass('Y'); | 1491 assertSuggestLocalClass('Y'); |
1479 assertSuggestLocalClass('C'); | 1492 assertSuggestLocalClass('C'); |
1480 assertSuggestLocalVariable('f', null); | 1493 assertSuggestLocalVariable('f', null); |
1481 assertNotSuggested('x'); | 1494 assertNotSuggested('x'); |
1482 assertNotSuggested('e'); | 1495 assertNotSuggested('e'); |
1483 }); | 1496 }); |
1484 } | 1497 } |
1485 } | 1498 } |
OLD | NEW |