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

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

Issue 637703002: add suggestions for variable declaration assignment RHS (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge 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.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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 CompletionSuggestion cs = 102 CompletionSuggestion cs =
103 assertSuggest(CompletionSuggestionKind.CLASS, name, relevance); 103 assertSuggest(CompletionSuggestionKind.CLASS, name, relevance);
104 protocol.Element element = cs.element; 104 protocol.Element element = cs.element;
105 expect(element, isNotNull); 105 expect(element, isNotNull);
106 expect(element.kind, equals(protocol.ElementKind.CLASS)); 106 expect(element.kind, equals(protocol.ElementKind.CLASS));
107 expect(element.name, equals(name)); 107 expect(element.name, equals(name));
108 expect(element.returnType, isNull); 108 expect(element.returnType, isNull);
109 return cs; 109 return cs;
110 } 110 }
111 111
112 CompletionSuggestion assertSuggestConstructor(String name,
113 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) {
114 CompletionSuggestion cs =
115 assertSuggest(CompletionSuggestionKind.CONSTRUCTOR, name, relevance);
116 protocol.Element element = cs.element;
117 expect(element, isNotNull);
118 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR));
119 expect(element.name, equals(name));
120 expect(element.returnType, isNull);
121 return cs;
122 }
123
124 CompletionSuggestion assertSuggestFunction(String name, String returnType, 112 CompletionSuggestion assertSuggestFunction(String name, String returnType,
125 bool isDeprecated, [CompletionRelevance relevance = 113 bool isDeprecated, [CompletionRelevance relevance =
126 CompletionRelevance.DEFAULT]) { 114 CompletionRelevance.DEFAULT]) {
127 CompletionSuggestion cs = assertSuggest( 115 CompletionSuggestion cs = assertSuggest(
128 CompletionSuggestionKind.FUNCTION, 116 CompletionSuggestionKind.FUNCTION,
129 name, 117 name,
130 relevance, 118 relevance,
131 isDeprecated); 119 isDeprecated);
132 expect(cs.returnType, equals(returnType)); 120 expect(cs.returnType, equals(returnType));
133 protocol.Element element = cs.element; 121 protocol.Element element = cs.element;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 protocol.Element element = cs.element; 191 protocol.Element element = cs.element;
204 expect(element, isNotNull); 192 expect(element, isNotNull);
205 expect(element.kind, equals(protocol.ElementKind.METHOD)); 193 expect(element.kind, equals(protocol.ElementKind.METHOD));
206 expect(element.name, equals(name)); 194 expect(element.name, equals(name));
207 expect( 195 expect(
208 element.returnType, 196 element.returnType,
209 equals(returnType != null ? returnType : 'dynamic')); 197 equals(returnType != null ? returnType : 'dynamic'));
210 return cs; 198 return cs;
211 } 199 }
212 200
201 CompletionSuggestion assertSuggestNamedConstructor(String name,
202 String returnType, [CompletionRelevance relevance =
203 CompletionRelevance.DEFAULT]) {
204 if (computer is InvocationComputer) {
205 CompletionSuggestion cs =
206 assertSuggest(CompletionSuggestionKind.CONSTRUCTOR, name, relevance);
207 protocol.Element element = cs.element;
208 expect(element, isNotNull);
209 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR));
210 expect(element.name, equals(name));
211 expect(element.returnType, equals(returnType));
212 return cs;
213 } else {
214 return null;
215 }
216 }
217
213 CompletionSuggestion assertSuggestParameter(String name, String returnType, 218 CompletionSuggestion assertSuggestParameter(String name, String returnType,
214 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { 219 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) {
215 CompletionSuggestion cs = 220 CompletionSuggestion cs =
216 assertSuggest(CompletionSuggestionKind.PARAMETER, name, relevance); 221 assertSuggest(CompletionSuggestionKind.PARAMETER, name, relevance);
217 expect(cs.returnType, equals(returnType)); 222 expect(cs.returnType, equals(returnType));
218 protocol.Element element = cs.element; 223 protocol.Element element = cs.element;
219 expect(element, isNotNull); 224 expect(element, isNotNull);
220 expect(element.kind, equals(protocol.ElementKind.PARAMETER)); 225 expect(element.kind, equals(protocol.ElementKind.PARAMETER));
221 expect(element.name, equals(name)); 226 expect(element.name, equals(name));
222 expect( 227 expect(
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 return computeFull(true).then((_) { 505 return computeFull(true).then((_) {
501 assertNotSuggested('b'); 506 assertNotSuggested('b');
502 assertNotSuggested('_c'); 507 assertNotSuggested('_c');
503 assertSuggestLocalVariable('a', 'A'); 508 assertSuggestLocalVariable('a', 'A');
504 assertSuggestLocalClass('A'); 509 assertSuggestLocalClass('A');
505 assertSuggestLocalClass('X'); 510 assertSuggestLocalClass('X');
506 assertSuggestImportedClass('Object'); 511 assertSuggestImportedClass('Object');
507 }); 512 });
508 } 513 }
509 514
515 test_ConstructorName_importedClass() {
516 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
517 // InstanceCreationExpression
518 addSource('/testB.dart', '''
519 lib B;
520 int T1;
521 F1() { }
522 class X {X.c(); X._d(); z() {}}''');
523 addTestSource('''
524 import "/testB.dart";
525 var m;
526 main() {new X.^}''');
527 computeFast();
528 return computeFull(true).then((_) {
529 assertSuggestNamedConstructor('c', 'X');
530 assertNotSuggested('F1');
531 assertNotSuggested('T1');
532 assertNotSuggested('_d');
533 assertNotSuggested('z');
534 assertNotSuggested('m');
535 });
536 }
537
538 test_ConstructorName_localClass() {
539 // SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
540 // InstanceCreationExpression
541 addTestSource('''
542 int T1;
543 F1() { }
544 class X {X.c(); X._d(); z() {}}
545 main() {new X.^}''');
546 computeFast();
547 return computeFull(true).then((_) {
548 assertSuggestNamedConstructor('c', 'X');
549 assertSuggestNamedConstructor('_d', 'X');
550 assertNotSuggested('F1');
551 assertNotSuggested('T1');
552 assertNotSuggested('z');
553 assertNotSuggested('m');
554 });
555 }
556
557 test_InstanceCreationExpression_imported() {
558 // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression
559 addSource('/testA.dart', '''
560 int T1;
561 F1() { }
562 class A {int x;}''');
563 addTestSource('''
564 import "/testA.dart";
565 int T2;
566 F2() { }
567 class B {int x;}
568 class C {foo(){var f; {var x;} new ^}}''');
569 computeFast();
570 return computeFull(true).then((_) {
571 assertSuggestImportedClass('Object');
572 assertSuggestImportedClass('A');
573 assertSuggestLocalClass('B');
574 assertSuggestLocalClass('C');
575 assertNotSuggested('f');
576 assertNotSuggested('x');
577 assertNotSuggested('foo');
578 assertNotSuggested('F1');
579 assertNotSuggested('F2');
580 assertNotSuggested('T1');
581 assertNotSuggested('T2');
582 });
583 }
584
510 test_IsExpression_type() { 585 test_IsExpression_type() {
511 // SimpleIdentifier TypeName IsExpression IfStatement 586 // SimpleIdentifier TypeName IsExpression IfStatement
512 addSource('/testB.dart', ''' 587 addSource('/testB.dart', '''
513 lib B; 588 lib B;
514 foo() { } 589 foo() { }
515 class X {X.c(); X._d(); z() {}}'''); 590 class X {X.c(); X._d(); z() {}}''');
516 addTestSource(''' 591 addTestSource('''
517 import "/testB.dart"; 592 import "/testB.dart";
518 class Y {Y.c(); Y._d(); z() {}} 593 class Y {Y.c(); Y._d(); z() {}}
519 main() {var x; if (x is ^) { }}'''); 594 main() {var x; if (x is ^) { }}''');
520 computeFast(); 595 computeFast();
521 return computeFull(true).then((_) { 596 return computeFull(true).then((_) {
522 assertSuggestImportedClass('X'); 597 assertSuggestImportedClass('X');
523 assertSuggestLocalClass('Y'); 598 assertSuggestLocalClass('Y');
524 assertNotSuggested('x'); 599 assertNotSuggested('x');
525 assertNotSuggested('main'); 600 assertNotSuggested('main');
526 assertNotSuggested('foo'); 601 assertNotSuggested('foo');
527 }); 602 });
528 } 603 }
604
605 test_VariableDeclaration_name() {
606 // SimpleIdentifier VariableDeclaration VariableDeclarationList
607 // VariableDeclarationStatement Block
608 addSource('/testB.dart', '''
609 lib B;
610 foo() { }
611 class _B { }
612 class X {X.c(); X._d(); z() {}}''');
613 addTestSource('''
614 import "/testB.dart";
615 class Y {Y.c(); Y._d(); z() {}}
616 main() {var ^}''');
617 computeFast();
618 return computeFull(true).then((_) {
619 assertNoSuggestions();
620 });
621 }
622
623 test_VariableDeclarationStatement_RHS() {
624 // SimpleIdentifier VariableDeclaration VariableDeclarationList
625 // VariableDeclarationStatement
626 addSource('/testB.dart', '''
627 lib B;
628 foo() { }
629 class _B { }
630 class X {X.c(); X._d(); z() {}}''');
631 addTestSource('''
632 import "/testB.dart";
633 class Y {Y.c(); Y._d(); z() {}}
634 class C {bar(){var f; {var x;} var e = ^}}''');
635 computeFast();
636 return computeFull(true).then((_) {
637 assertSuggestImportedClass('X');
638 assertNotSuggested('_B');
639 assertSuggestLocalClass('Y');
640 assertSuggestLocalClass('C');
641 assertSuggestLocalVariable('f', null);
642 assertNotSuggested('x');
643 assertNotSuggested('e');
644 });
645 }
646
647 test_VariableDeclarationStatement_RHS_missing_semicolon() {
648 // VariableDeclaration VariableDeclarationList
649 // VariableDeclarationStatement
650 addSource('/testB.dart', '''
651 lib B;
652 foo() { }
653 class _B { }
654 class X {X.c(); X._d(); z() {}}''');
655 addTestSource('''
656 import "/testB.dart";
657 class Y {Y.c(); Y._d(); z() {}}
658 class C {bar(){var f; {var x;} var e = ^ var g}}''');
659 computeFast();
660 return computeFull(true).then((_) {
661 assertSuggestImportedClass('X');
662 assertNotSuggested('_B');
663 assertSuggestLocalClass('Y');
664 assertSuggestLocalClass('C');
665 assertSuggestLocalVariable('f', null);
666 assertNotSuggested('x');
667 assertNotSuggested('e');
668 });
669 }
529 } 670 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698