| 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.target; | 5 library test.services.completion.target; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/services/completion/completion_target.dart'; | 7 import 'package:analysis_server/src/services/completion/completion_target.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 assertCommon(); | 52 assertCommon(); |
| 53 expect(target.isFunctionalArgument(), isFunctionalArgument); | 53 expect(target.isFunctionalArgument(), isFunctionalArgument); |
| 54 } | 54 } |
| 55 | 55 |
| 56 test_ArgumentList_InstanceCreationExpression() { | 56 test_ArgumentList_InstanceCreationExpression() { |
| 57 // ArgumentList InstanceCreationExpression Block | 57 // ArgumentList InstanceCreationExpression Block |
| 58 addTestSource('main() {new Foo(^)}'); | 58 addTestSource('main() {new Foo(^)}'); |
| 59 assertTarget(')', '()', argIndex: 0); | 59 assertTarget(')', '()', argIndex: 0); |
| 60 } | 60 } |
| 61 | 61 |
| 62 test_ArgumentList_InstanceCreationExpression_functionArg2() { |
| 63 // ArgumentList InstanceCreationExpression Block |
| 64 addTestSource('main() {new B(^)} class B{B(f()){}}'); |
| 65 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true); |
| 66 } |
| 67 |
| 62 test_ArgumentList_MethodInvocation() { | 68 test_ArgumentList_MethodInvocation() { |
| 63 // ArgumentList MethodInvocation Block | 69 // ArgumentList MethodInvocation Block |
| 64 addTestSource('main() {foo(^)}'); | 70 addTestSource('main() {foo(^)}'); |
| 65 assertTarget(')', '()', argIndex: 0); | 71 assertTarget(')', '()', argIndex: 0); |
| 66 } | 72 } |
| 67 | 73 |
| 68 test_ArgumentList_MethodInvocation2() { | 74 test_ArgumentList_MethodInvocation2() { |
| 69 // ArgumentList MethodInvocation Block | 75 // ArgumentList MethodInvocation Block |
| 70 addTestSource('main() {foo(^n)}'); | 76 addTestSource('main() {foo(^n)}'); |
| 71 assertTarget('n', '(n)', argIndex: 0); | 77 assertTarget('n', '(n)', argIndex: 0); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 88 addTestSource('main() {foo(^)} foo(f()) {}'); | 94 addTestSource('main() {foo(^)} foo(f()) {}'); |
| 89 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true); | 95 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true); |
| 90 } | 96 } |
| 91 | 97 |
| 92 test_ArgumentList_MethodInvocation_functionArg2() { | 98 test_ArgumentList_MethodInvocation_functionArg2() { |
| 93 // ArgumentList MethodInvocation Block | 99 // ArgumentList MethodInvocation Block |
| 94 addTestSource('main() {new B().boo(^)} class B{boo(f()){}}'); | 100 addTestSource('main() {new B().boo(^)} class B{boo(f()){}}'); |
| 95 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true); | 101 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true); |
| 96 } | 102 } |
| 97 | 103 |
| 98 test_ArgumentList_InstanceCreationExpression_functionArg2() { | |
| 99 // ArgumentList InstanceCreationExpression Block | |
| 100 addTestSource('main() {new B(^)} class B{B(f()){}}'); | |
| 101 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true); | |
| 102 } | |
| 103 | |
| 104 test_AsExpression_identifier() { | 104 test_AsExpression_identifier() { |
| 105 // SimpleIdentifier TypeName AsExpression | 105 // SimpleIdentifier TypeName AsExpression |
| 106 addTestSource('class A {var b; X _c; foo() {var a; (a^ as String).foo();}'); | 106 addTestSource('class A {var b; X _c; foo() {var a; (a^ as String).foo();}'); |
| 107 assertTarget('a as String', '(a as String)'); | 107 assertTarget('a as String', '(a as String)'); |
| 108 } | 108 } |
| 109 | 109 |
| 110 test_AsExpression_keyword() { | 110 test_AsExpression_keyword() { |
| 111 // SimpleIdentifier TypeName AsExpression | 111 // SimpleIdentifier TypeName AsExpression |
| 112 addTestSource('class A {var b; X _c; foo() {var a; (a ^as String).foo();}'); | 112 addTestSource('class A {var b; X _c; foo() {var a; (a ^as String).foo();}'); |
| 113 assertTarget('as', 'a as String'); | 113 assertTarget('as', 'a as String'); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 addTestSource('class C {foo(){var f; {var x;} new^ }}'); | 148 addTestSource('class C {foo(){var f; {var x;} new^ }}'); |
| 149 assertTarget('new ();', '{var f; {var x;} new ();}'); | 149 assertTarget('new ();', '{var f; {var x;} new ();}'); |
| 150 } | 150 } |
| 151 | 151 |
| 152 test_InstanceCreationExpression_keyword2() { | 152 test_InstanceCreationExpression_keyword2() { |
| 153 // InstanceCreationExpression ExpressionStatement Block | 153 // InstanceCreationExpression ExpressionStatement Block |
| 154 addTestSource('class C {foo(){var f; {var x;} new^ C();}}'); | 154 addTestSource('class C {foo(){var f; {var x;} new^ C();}}'); |
| 155 assertTarget('new C();', '{var f; {var x;} new C();}'); | 155 assertTarget('new C();', '{var f; {var x;} new C();}'); |
| 156 } | 156 } |
| 157 | 157 |
| 158 test_MethodDeclaration_inLineComment() { |
| 159 // Comment ClassDeclaration CompilationUnit |
| 160 addTestSource(''' |
| 161 class C2 { |
| 162 // normal comment ^ |
| 163 zoo(z) { } String name; }'''); |
| 164 assertTarget('// normal comment ', 'class C2 {zoo(z) {} String name;}'); |
| 165 } |
| 166 |
| 167 test_MethodDeclaration_inLineComment2() { |
| 168 // Comment ClassDeclaration CompilationUnit |
| 169 addTestSource(''' |
| 170 class C2 { |
| 171 // normal ^comment |
| 172 zoo(z) { } String name; }'''); |
| 173 assertTarget('// normal comment', 'class C2 {zoo(z) {} String name;}'); |
| 174 } |
| 175 |
| 176 test_MethodDeclaration_inLineComment3() { |
| 177 // Comment ClassDeclaration CompilationUnit |
| 178 addTestSource(''' |
| 179 class C2 { |
| 180 // normal comment ^ |
| 181 // normal comment 2 |
| 182 zoo(z) { } String name; }'''); |
| 183 assertTarget('// normal comment ', 'class C2 {zoo(z) {} String name;}'); |
| 184 } |
| 185 |
| 186 test_MethodDeclaration_inLineComment4() { |
| 187 // Comment ClassDeclaration CompilationUnit |
| 188 addTestSource(''' |
| 189 class C2 { |
| 190 // normal comment |
| 191 // normal comment 2^ |
| 192 zoo(z) { } String name; }'''); |
| 193 assertTarget('// normal comment 2', 'class C2 {zoo(z) {} String name;}'); |
| 194 } |
| 195 |
| 196 test_MethodDeclaration_inLineDocComment() { |
| 197 // Comment MethodDeclaration ClassDeclaration CompilationUnit |
| 198 addTestSource(''' |
| 199 class C2 { |
| 200 /// some dartdoc ^ |
| 201 zoo(z) { } String name; }'''); |
| 202 assertTarget('/// some dartdoc ', ''); |
| 203 expect(target.containingNode is Comment, isTrue); |
| 204 expect(target.containingNode.parent.toSource(), 'zoo(z) {}'); |
| 205 } |
| 206 |
| 207 test_MethodDeclaration_inLineDocComment2() { |
| 208 // Comment MethodDeclaration ClassDeclaration CompilationUnit |
| 209 addTestSource(''' |
| 210 class C2 { |
| 211 /// some ^dartdoc |
| 212 zoo(z) { } String name; }'''); |
| 213 assertTarget('/// some dartdoc', ''); |
| 214 expect(target.containingNode is Comment, isTrue); |
| 215 expect(target.containingNode.parent.toSource(), 'zoo(z) {}'); |
| 216 } |
| 217 |
| 218 test_MethodDeclaration_inStarComment() { |
| 219 // Comment ClassDeclaration CompilationUnit |
| 220 addTestSource('class C2 {/* ^ */ zoo(z) {} String name;}'); |
| 221 assertTarget('/* */', 'class C2 {zoo(z) {} String name;}'); |
| 222 } |
| 223 |
| 224 test_MethodDeclaration_inStarComment2() { |
| 225 // Comment ClassDeclaration CompilationUnit |
| 226 addTestSource('class C2 {/* *^/ zoo(z) {} String name;}'); |
| 227 assertTarget('/* */', 'class C2 {zoo(z) {} String name;}'); |
| 228 } |
| 229 |
| 230 test_MethodDeclaration_inStarDocComment() { |
| 231 // Comment MethodDeclaration ClassDeclaration CompilationUnit |
| 232 addTestSource('class C2 {/** ^ */ zoo(z) { } String name; }'); |
| 233 assertTarget('/** */', ''); |
| 234 expect(target.containingNode is Comment, isTrue); |
| 235 expect(target.containingNode.parent.toSource(), 'zoo(z) {}'); |
| 236 } |
| 237 |
| 238 test_MethodDeclaration_inStarDocComment2() { |
| 239 // Comment MethodDeclaration ClassDeclaration CompilationUnit |
| 240 addTestSource('class C2 {/** *^/ zoo(z) { } String name; }'); |
| 241 assertTarget('/** */', ''); |
| 242 expect(target.containingNode is Comment, isTrue); |
| 243 expect(target.containingNode.parent.toSource(), 'zoo(z) {}'); |
| 244 } |
| 245 |
| 246 test_MethodDeclaration_returnType() { |
| 247 // ClassDeclaration CompilationUnit |
| 248 addTestSource('class C2 {^ zoo(z) { } String name; }'); |
| 249 assertTarget('zoo(z) {}', 'class C2 {zoo(z) {} String name;}'); |
| 250 } |
| 251 |
| 252 test_MethodDeclaration_returnType_afterLineComment() { |
| 253 // MethodDeclaration ClassDeclaration CompilationUnit |
| 254 addTestSource(''' |
| 255 class C2 { |
| 256 // normal comment |
| 257 ^ zoo(z) {} String name;}'''); |
| 258 assertTarget('zoo(z) {}', 'class C2 {zoo(z) {} String name;}'); |
| 259 } |
| 260 |
| 261 test_MethodDeclaration_returnType_afterLineComment2() { |
| 262 // MethodDeclaration ClassDeclaration CompilationUnit |
| 263 // TOD(danrubel) left align all test source |
| 264 addTestSource(''' |
| 265 class C2 { |
| 266 // normal comment |
| 267 ^ zoo(z) {} String name;}'''); |
| 268 assertTarget('zoo(z) {}', 'class C2 {zoo(z) {} String name;}'); |
| 269 } |
| 270 |
| 271 test_MethodDeclaration_returnType_afterLineDocComment() { |
| 272 // SimpleIdentifier MethodDeclaration ClassDeclaration CompilationUnit |
| 273 addTestSource(''' |
| 274 class C2 { |
| 275 /// some dartdoc |
| 276 ^ zoo(z) { } String name; }'''); |
| 277 assertTarget('zoo', 'zoo(z) {}'); |
| 278 } |
| 279 |
| 280 test_MethodDeclaration_returnType_afterLineDocComment2() { |
| 281 // SimpleIdentifier MethodDeclaration ClassDeclaration CompilationUnit |
| 282 addTestSource(''' |
| 283 class C2 { |
| 284 /// some dartdoc |
| 285 ^ zoo(z) { } String name; }'''); |
| 286 assertTarget('zoo', 'zoo(z) {}'); |
| 287 } |
| 288 |
| 289 test_MethodDeclaration_returnType_afterStarComment() { |
| 290 // ClassDeclaration CompilationUnit |
| 291 addTestSource('class C2 {/* */ ^ zoo(z) { } String name; }'); |
| 292 assertTarget('zoo(z) {}', 'class C2 {zoo(z) {} String name;}'); |
| 293 } |
| 294 |
| 295 test_MethodDeclaration_returnType_afterStarComment2() { |
| 296 // ClassDeclaration CompilationUnit |
| 297 addTestSource('class C2 {/* */^ zoo(z) { } String name; }'); |
| 298 assertTarget('zoo(z) {}', 'class C2 {zoo(z) {} String name;}'); |
| 299 } |
| 300 |
| 301 test_MethodDeclaration_returnType_afterStarDocComment() { |
| 302 // MethodDeclaration ClassDeclaration CompilationUnit |
| 303 addTestSource('class C2 {/** */ ^ zoo(z) { } String name; }'); |
| 304 assertTarget('zoo', 'zoo(z) {}'); |
| 305 } |
| 306 |
| 307 test_MethodDeclaration_returnType_afterStarDocComment2() { |
| 308 // MethodDeclaration ClassDeclaration CompilationUnit |
| 309 addTestSource('class C2 {/** */^ zoo(z) { } String name; }'); |
| 310 assertTarget('zoo', 'zoo(z) {}'); |
| 311 } |
| 312 |
| 158 test_VariableDeclaration_lhs_identifier_after() { | 313 test_VariableDeclaration_lhs_identifier_after() { |
| 159 // VariableDeclaration VariableDeclarationList | 314 // VariableDeclaration VariableDeclarationList |
| 160 addTestSource('main() {int b^ = 1;}'); | 315 addTestSource('main() {int b^ = 1;}'); |
| 161 assertTarget('b = 1', 'int b = 1'); | 316 assertTarget('b = 1', 'int b = 1'); |
| 162 } | 317 } |
| 163 | 318 |
| 164 test_VariableDeclaration_lhs_identifier_before() { | 319 test_VariableDeclaration_lhs_identifier_before() { |
| 165 // VariableDeclaration VariableDeclarationList | 320 // VariableDeclaration VariableDeclarationList |
| 166 addTestSource('main() {int ^b = 1;}'); | 321 addTestSource('main() {int ^b = 1;}'); |
| 167 assertTarget('b = 1', 'int b = 1'); | 322 assertTarget('b = 1', 'int b = 1'); |
| 168 } | 323 } |
| 169 } | 324 } |
| OLD | NEW |