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

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

Issue 628473002: cleanup/organize/improve completion tests (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
« no previous file with comments | « pkg/analysis_server/test/services/completion/invocation_computer_test.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.completion.dart.local; 5 library test.services.completion.dart.local;
6 6
7 import 'package:analysis_server/src/services/completion/local_computer.dart'; 7 import 'package:analysis_server/src/services/completion/local_computer.dart';
8 import '../../reflective_tests.dart';
9 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
10 9
10 import '../../reflective_tests.dart';
11 import 'completion_test_util.dart'; 11 import 'completion_test_util.dart';
12 12
13 main() { 13 main() {
14 groupSep = ' | '; 14 groupSep = ' | ';
15 runReflectiveTests(LocalComputerTest); 15 runReflectiveTests(LocalComputerTest);
16 } 16 }
17 17
18 @ReflectiveTestCase() 18 @ReflectiveTestCase()
19 class LocalComputerTest extends AbstractCompletionTest { 19 class LocalComputerTest extends AbstractCompletionTest {
20 20
21 @override 21 @override
22 void setUp() { 22 void setUp() {
23 super.setUp(); 23 super.setUp();
24 computer = new LocalComputer(); 24 computer = new LocalComputer();
25 } 25 }
26 26
27 test_block() { 27 test_BinaryExpression_LHS() {
28 // SimpleIdentifier BinaryExpression VariableDeclaration
29 // VariableDeclarationList VariableDeclarationStatement
30 addTestSource('main() {int a = 1, b = ^ + 2;}');
31 expect(computeFast(), isTrue);
32 assertSuggestLocalVariable('a', 'int');
33 assertNotSuggested('b');
34 }
35
36 test_BinaryExpression_RHS() {
37 // SimpleIdentifier BinaryExpression VariableDeclaration
38 // VariableDeclarationList VariableDeclarationStatement
39 addTestSource('main() {int a = 1, b = 2 + ^;}');
40 expect(computeFast(), isTrue);
41 assertSuggestLocalVariable('a', 'int');
42 assertNotSuggested('b');
43 }
44
45 test_Block() {
46 // Block BlockFunctionBody
28 addTestSource('class A {a() {var f; {var x;} ^ var g;}}'); 47 addTestSource('class A {a() {var f; {var x;} ^ var g;}}');
29 expect(computeFast(), isTrue); 48 expect(computeFast(), isTrue);
49 assertSuggestClass('A');
30 assertSuggestLocalVariable('f', null); 50 assertSuggestLocalVariable('f', null);
31 assertNotSuggested('g'); 51 assertNotSuggested('g');
32 assertNotSuggested('x'); 52 assertNotSuggested('x');
33 } 53 }
34 54
35 test_catch() { 55 test_CatchClause_typed() {
56 // Block CatchClause TryStatement
36 addTestSource('class A {a() {try{} on E catch (e) {^}}}'); 57 addTestSource('class A {a() {try{} on E catch (e) {^}}}');
37 expect(computeFast(), isTrue); 58 expect(computeFast(), isTrue);
38 assertSuggestParameter('e', 'E'); 59 assertSuggestParameter('e', 'E');
39 } 60 }
40 61
41 test_catch2() { 62 test_CatchClause_untyped() {
63 // Block CatchClause TryStatement
42 addTestSource('class A {a() {try{} catch (e, s) {^}}}'); 64 addTestSource('class A {a() {try{} catch (e, s) {^}}}');
43 expect(computeFast(), isTrue); 65 expect(computeFast(), isTrue);
44 assertSuggestParameter('e', null); 66 assertSuggestParameter('e', null);
45 assertSuggestParameter('s', 'StackTrace'); 67 assertSuggestParameter('s', 'StackTrace');
46 } 68 }
47 69
48 test_compilationUnit_declarations() { 70 test_ClassDeclaration_body() {
49 addTestSource('@deprecated class A {^} class _B {} A T;'); 71 // ClassDeclaration CompilationUnit
72 addTestSource( //
73 'import "boo.dart" as x;' //
74 ' @deprecated class A {^}' //
75 ' class _B {}' //
76 ' A T;');
50 expect(computeFast(), isTrue); 77 expect(computeFast(), isTrue);
51 var a = assertSuggestClass('A'); 78 var a = assertSuggestClass('A');
52 expect(a.element.isDeprecated, isTrue); 79 expect(a.element.isDeprecated, isTrue);
53 expect(a.element.isPrivate, isFalse); 80 expect(a.element.isPrivate, isFalse);
54 var b = assertSuggestClass('_B'); 81 var b = assertSuggestClass('_B');
55 expect(b.element.isDeprecated, isFalse); 82 expect(b.element.isDeprecated, isFalse);
56 expect(b.element.isPrivate, isTrue); 83 expect(b.element.isPrivate, isTrue);
57 assertSuggestTopLevelVar('T', 'A'); 84 assertSuggestTopLevelVar('T', 'A');
58 }
59
60 test_compilationUnit_directives() {
61 addTestSource('import "boo.dart" as x; class A {^}');
62 expect(computeFast(), isTrue);
63 assertSuggestLibraryPrefix('x'); 85 assertSuggestLibraryPrefix('x');
64 } 86 }
65 87
66 test_field_name() { 88 test_ExpressionStatement_name() {
89 // ExpressionStatement Block
90 addTestSource('class A {a() {var f; A ^}}');
91 expect(computeFast(), isTrue);
92 assertNotSuggested('A');
93 assertNotSuggested('a');
94 assertNotSuggested('f');
95 }
96
97 test_FieldDeclaration_name() {
98 // SimpleIdentifier VariableDeclaration VariableDeclarationList
99 // FieldDeclaration
67 addTestSource('class A {B ^}}'); 100 addTestSource('class A {B ^}}');
68 expect(computeFast(), isTrue); 101 expect(computeFast(), isTrue);
69 assertNotSuggested('A'); 102 assertNotSuggested('A');
70 } 103 }
71 104
72 test_field_name2() { 105 test_ForEachStatement_body_typed() {
73 addTestSource('class A {var ^}}'); 106 // Block ForEachStatement
107 addTestSource('main(args) {for (int foo in bar) {^}}');
74 expect(computeFast(), isTrue); 108 expect(computeFast(), isTrue);
75 assertNotSuggested('A'); 109 assertSuggestLocalVariable('foo', 'int');
76 } 110 }
77 111
78 test_for() { 112 test_ForEachStatement_body_untyped() {
113 // Block ForEachStatement
114 addTestSource('main(args) {for (foo in bar) {^}}');
115 expect(computeFast(), isTrue);
116 assertSuggestLocalVariable('foo', null);
117 }
118
119 test_ForStatement_body() {
120 // Block ForStatement
79 addTestSource('main(args) {for (int i; i < 10; ++i) {^}}'); 121 addTestSource('main(args) {for (int i; i < 10; ++i) {^}}');
80 expect(computeFast(), isTrue); 122 expect(computeFast(), isTrue);
81 assertSuggestLocalVariable('i', 'int'); 123 assertSuggestLocalVariable('i', 'int');
82 } 124 }
83 125
84 test_forEach() { 126 test_FunctionExpression_body_function() {
85 addTestSource('main(args) {for (foo in bar) {^}}'); 127 // Block BlockFunctionBody FunctionExpression
86 expect(computeFast(), isTrue);
87 assertSuggestLocalVariable('foo', null);
88 }
89
90 test_forEach2() {
91 addTestSource('main(args) {for (int foo in bar) {^}}');
92 expect(computeFast(), isTrue);
93 assertSuggestLocalVariable('foo', 'int');
94 }
95
96 test_function() {
97 addTestSource('String foo(List args) {x.then((R b) {^});}'); 128 addTestSource('String foo(List args) {x.then((R b) {^});}');
98 expect(computeFast(), isTrue); 129 expect(computeFast(), isTrue);
99 var f = assertSuggestFunction('foo', 'String', false); 130 var f = assertSuggestFunction('foo', 'String', false);
100 expect(f.element.isPrivate, isFalse); 131 expect(f.element.isPrivate, isFalse);
101 assertSuggestParameter('args', 'List'); 132 assertSuggestParameter('args', 'List');
102 assertSuggestParameter('b', 'R'); 133 assertSuggestParameter('b', 'R');
103 } 134 }
104 135
105 test_getters() { 136 test_InstanceCreationExpression() {
137 // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression
138 addTestSource('class A {a() {var f; {var x;} new ^}} class B { }');
139 expect(computeFast(), isTrue);
140 assertSuggestClass('A');
141 assertSuggestClass('B');
142 // TODO (danrubel) should only suggest types
143 //assertNotSuggested('a');
144 assertSuggestMethod('a', 'A', null);
145 //assertNotSuggested('f');
146 assertSuggestLocalVariable('f', null);
147 assertNotSuggested('x');
148 }
149
150 test_MethodDeclaration_body_getters() {
151 // Block BlockFunctionBody MethodDeclaration
106 addTestSource('class A {@deprecated X get f => 0; Z a() {^} get _g => 1;}'); 152 addTestSource('class A {@deprecated X get f => 0; Z a() {^} get _g => 1;}');
107 expect(computeFast(), isTrue); 153 expect(computeFast(), isTrue);
108 var a = assertSuggestMethod('a', 'A', 'Z'); 154 var a = assertSuggestMethod('a', 'A', 'Z');
109 expect(a.element.isDeprecated, isFalse); 155 expect(a.element.isDeprecated, isFalse);
110 expect(a.element.isPrivate, isFalse); 156 expect(a.element.isPrivate, isFalse);
111 var f = assertSuggestGetter('f', 'X'); 157 var f = assertSuggestGetter('f', 'X');
112 expect(f.element.isDeprecated, isTrue); 158 expect(f.element.isDeprecated, isTrue);
113 expect(f.element.isPrivate, isFalse); 159 expect(f.element.isPrivate, isFalse);
114 var g = assertSuggestGetter('_g', null); 160 var g = assertSuggestGetter('_g', null);
115 expect(g.element.isDeprecated, isFalse); 161 expect(g.element.isDeprecated, isFalse);
116 expect(g.element.isPrivate, isTrue); 162 expect(g.element.isPrivate, isTrue);
117 } 163 }
118 164
119 test_local_name() { 165 test_MethodDeclaration_members() {
120 addTestSource('class A {a() {var f; A ^}}'); 166 // Block BlockFunctionBody MethodDeclaration
121 expect(computeFast(), isTrue);
122 assertNotSuggested('A');
123 assertNotSuggested('a');
124 assertNotSuggested('f');
125 }
126
127 test_local_name2() {
128 addTestSource('class _A {a() {var f; var ^}}');
129 expect(computeFast(), isTrue);
130 assertNotSuggested('A');
131 assertNotSuggested('a');
132 assertNotSuggested('f');
133 }
134
135 test_members() {
136 addTestSource('class A {@deprecated X f; Z _a() {^} var _g;}'); 167 addTestSource('class A {@deprecated X f; Z _a() {^} var _g;}');
137 expect(computeFast(), isTrue); 168 expect(computeFast(), isTrue);
138 var a = assertSuggestMethod('_a', 'A', 'Z'); 169 var a = assertSuggestMethod('_a', 'A', 'Z');
139 expect(a.element.isDeprecated, isFalse); 170 expect(a.element.isDeprecated, isFalse);
140 expect(a.element.isPrivate, isTrue); 171 expect(a.element.isPrivate, isTrue);
141 var f = assertSuggestGetter('f', 'X'); 172 var f = assertSuggestGetter('f', 'X');
142 expect(f.element.isDeprecated, isTrue); 173 expect(f.element.isDeprecated, isTrue);
143 expect(f.element.isPrivate, isFalse); 174 expect(f.element.isPrivate, isFalse);
144 var g = assertSuggestGetter('_g', null); 175 var g = assertSuggestGetter('_g', null);
145 expect(g.element.isDeprecated, isFalse); 176 expect(g.element.isDeprecated, isFalse);
146 expect(g.element.isPrivate, isTrue); 177 expect(g.element.isPrivate, isTrue);
147 } 178 }
148 179
149 test_methodParam_named() { 180 test_MethodDeclaration_parameters_named() {
181 // Block BlockFunctionBody MethodDeclaration
150 addTestSource('class A {@deprecated Z a(X x, {y: boo}) {^}}'); 182 addTestSource('class A {@deprecated Z a(X x, {y: boo}) {^}}');
151 expect(computeFast(), isTrue); 183 expect(computeFast(), isTrue);
152 var a = assertSuggestMethod('a', 'A', 'Z'); 184 var a = assertSuggestMethod('a', 'A', 'Z');
153 expect(a.element.isDeprecated, isTrue); 185 expect(a.element.isDeprecated, isTrue);
154 expect(a.element.isPrivate, isFalse); 186 expect(a.element.isPrivate, isFalse);
155 assertSuggestParameter('x', 'X'); 187 assertSuggestParameter('x', 'X');
156 assertSuggestParameter('y', null); 188 assertSuggestParameter('y', null);
157 } 189 }
158 190
159 test_methodParam_positional() { 191 test_MethodDeclaration_parameters_positional() {
192 // Block BlockFunctionBody MethodDeclaration
160 addTestSource('class A {Z a(X x, [int y=1]) {^}}'); 193 addTestSource('class A {Z a(X x, [int y=1]) {^}}');
161 expect(computeFast(), isTrue); 194 expect(computeFast(), isTrue);
162 assertSuggestMethod('a', 'A', 'Z'); 195 assertSuggestMethod('a', 'A', 'Z');
163 assertSuggestParameter('x', 'X'); 196 assertSuggestParameter('x', 'X');
164 assertSuggestParameter('y', 'int'); 197 assertSuggestParameter('y', 'int');
165 } 198 }
166 199
167 test_topLevelVar_name() { 200 test_TopLevelVariableDeclaration_typed_name() {
201 // SimpleIdentifier VariableDeclaration VariableDeclarationList
202 // TopLevelVariableDeclaration
168 addTestSource('class A {} B ^'); 203 addTestSource('class A {} B ^');
169 expect(computeFast(), isTrue); 204 expect(computeFast(), isTrue);
170 assertNotSuggested('A'); 205 assertNotSuggested('A');
171 } 206 }
172 207
173 test_topLevelVar_name2() { 208 test_TopLevelVariableDeclaration_untyped_name() {
209 // SimpleIdentifier VariableDeclaration VariableDeclarationList
210 // TopLevelVariableDeclaration
174 addTestSource('class A {} var ^'); 211 addTestSource('class A {} var ^');
175 expect(computeFast(), isTrue); 212 expect(computeFast(), isTrue);
176 assertNotSuggested('A'); 213 assertNotSuggested('A');
177 } 214 }
178 215
179 test_variableDeclaration() { 216 test_VariableDeclarationStatement_name() {
180 addTestSource('main() {int a = 1, b = 2 + ^;}'); 217 // SimpleIdentifier VariableDeclaration VariableDeclarationList
218 // VariableDeclarationStatement
219 addTestSource('class _A {a() {var f; var ^}}');
181 expect(computeFast(), isTrue); 220 expect(computeFast(), isTrue);
182 assertSuggestLocalVariable('a', 'int'); 221 assertNotSuggested('A');
183 assertNotSuggested('b'); 222 assertNotSuggested('a');
223 assertNotSuggested('f');
224 }
225
226 test_VariableDeclaration_RHS() {
227
228 // VariableDeclaration VariableDeclarationList VariableDeclarationStat ement
229 addTestSource('class A {a() {var f; {var x;} var e = ^ var g;}}');
230 expect(computeFast(), isTrue);
231 assertSuggestClass('A');
232 assertSuggestLocalVariable('f', null);
233 assertNotSuggested('g');
234 assertNotSuggested('x');
184 } 235 }
185 } 236 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/services/completion/invocation_computer_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698