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

Side by Side Diff: pkg/analysis_server/test/services/correction/assist_test.dart

Issue 1014503004: Issue 22834. Disable 'Add type annotation' Quick Assist if the type is not accessible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/util.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.correction.assist; 5 library test.services.correction.assist;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/correction/assist.dart'; 8 import 'package:analysis_server/src/services/correction/assist.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return new LinkedEditSuggestion(value, kind); 90 return new LinkedEditSuggestion(value, kind);
91 }).toList(); 91 }).toList();
92 } 92 }
93 93
94 void setUp() { 94 void setUp() {
95 super.setUp(); 95 super.setUp();
96 offset = 0; 96 offset = 0;
97 length = 0; 97 length = 0;
98 } 98 }
99 99
100 void test_addTypeAnnotation_BAD_privateType_closureParameter() {
101 addSource('/my_lib.dart', '''
102 library my_lib;
103 class A {}
104 class _B extends A {}
105 foo(f(_B p)) {}
106 ''');
107 resolveTestUnit('''
108 import 'my_lib.dart';
109 main() {
110 foo((test) {});
111 }
112 ''');
113 assertNoAssistAt('test)', AssistKind.ADD_TYPE_ANNOTATION);
114 }
115
116 void test_addTypeAnnotation_BAD_privateType_declaredIdentifier() {
117 addSource('/my_lib.dart', '''
118 library my_lib;
119 class A {}
120 class _B extends A {}
121 List<_B> getValues() => [];
122 ''');
123 resolveTestUnit('''
124 import 'my_lib.dart';
125 class A<T> {
126 main() {
127 for (var item in getValues()) {
128 }
129 }
130 }
131 ''');
132 assertNoAssistAt('var item', AssistKind.ADD_TYPE_ANNOTATION);
133 }
134
135 void test_addTypeAnnotation_BAD_privateType_variable() {
136 addSource('/my_lib.dart', '''
137 library my_lib;
138 class A {}
139 class _B extends A {}
140 _B getValue() => new _B();
141 ''');
142 resolveTestUnit('''
143 import 'my_lib.dart';
144 main() {
145 var v = getValue();
146 }
147 ''');
148 assertNoAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION);
149 }
150
100 void test_addTypeAnnotation_classField_OK_final() { 151 void test_addTypeAnnotation_classField_OK_final() {
101 resolveTestUnit(''' 152 resolveTestUnit('''
102 class A { 153 class A {
103 final f = 0; 154 final f = 0;
104 } 155 }
105 '''); 156 ''');
106 assertHasAssistAt('final ', AssistKind.ADD_TYPE_ANNOTATION, ''' 157 assertHasAssistAt('final ', AssistKind.ADD_TYPE_ANNOTATION, '''
107 class A { 158 class A {
108 final int f = 0; 159 final int f = 0;
109 } 160 }
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 void test_addTypeAnnotation_local_wrong_unknown() { 564 void test_addTypeAnnotation_local_wrong_unknown() {
514 verifyNoTestUnitErrors = false; 565 verifyNoTestUnitErrors = false;
515 resolveTestUnit(''' 566 resolveTestUnit('''
516 main() { 567 main() {
517 var v = unknownVar; 568 var v = unknownVar;
518 } 569 }
519 '''); 570 ''');
520 assertNoAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION); 571 assertNoAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION);
521 } 572 }
522 573
574 void test_addTypeAnnotation_OK_privateType_sameLibrary() {
575 resolveTestUnit('''
576 class _A {}
577 _A getValue() => new _A();
578 main() {
579 var v = getValue();
580 }
581 ''');
582 assertHasAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION, '''
583 class _A {}
584 _A getValue() => new _A();
585 main() {
586 _A v = getValue();
587 }
588 ''');
589 }
590
523 void test_addTypeAnnotation_parameter_BAD_hasExplicitType() { 591 void test_addTypeAnnotation_parameter_BAD_hasExplicitType() {
524 resolveTestUnit(''' 592 resolveTestUnit('''
525 foo(f(int p)) {} 593 foo(f(int p)) {}
526 main() { 594 main() {
527 foo((num test) {}); 595 foo((num test) {});
528 } 596 }
529 '''); 597 ''');
530 assertNoAssistAt('test', AssistKind.ADD_TYPE_ANNOTATION); 598 assertNoAssistAt('test', AssistKind.ADD_TYPE_ANNOTATION);
531 } 599 }
532 600
(...skipping 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 positions.add(new Position(testFile, offset)); 2847 positions.add(new Position(testFile, offset));
2780 } 2848 }
2781 return positions; 2849 return positions;
2782 } 2850 }
2783 2851
2784 void _setStartEndSelection() { 2852 void _setStartEndSelection() {
2785 offset = findOffset('// start\n') + '// start\n'.length; 2853 offset = findOffset('// start\n') + '// start\n'.length;
2786 length = findOffset('// end') - offset; 2854 length = findOffset('// end') - offset;
2787 } 2855 }
2788 } 2856 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/util.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698