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

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

Issue 1002713003: completions in map literals (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge cleanup 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
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.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 21 matching lines...) Expand all
32 content = content.substring(0, completionOffset) + 32 content = content.substring(0, completionOffset) +
33 content.substring(completionOffset + 1); 33 content.substring(completionOffset + 1);
34 testSource = addSource('/test.dart', content); 34 testSource = addSource('/test.dart', content);
35 CompilationUnit unit = context.parseCompilationUnit(testSource); 35 CompilationUnit unit = context.parseCompilationUnit(testSource);
36 target = new CompletionTarget.forOffset(unit, completionOffset); 36 target = new CompletionTarget.forOffset(unit, completionOffset);
37 } 37 }
38 38
39 void assertTarget(entityText, nodeText, 39 void assertTarget(entityText, nodeText,
40 {int argIndex: null, bool isFunctionalArgument: false}) { 40 {int argIndex: null, bool isFunctionalArgument: false}) {
41 void assertCommon() { 41 void assertCommon() {
42 expect(target.entity.toString(), entityText); 42 expect(target.entity.toString(), entityText, reason: 'entity');
43 expect(target.containingNode.toString(), nodeText); 43 expect(target.containingNode.toString(), nodeText,
44 expect(target.argIndex, argIndex); 44 reason: 'containingNode');
45 expect(target.argIndex, argIndex, reason: 'argIndex');
45 } 46 }
46 // Assert with parsed unit 47 // Assert with parsed unit
47 assertCommon(); 48 assertCommon();
48 CompilationUnit unit = 49 CompilationUnit unit =
49 context.resolveCompilationUnit2(testSource, testSource); 50 context.resolveCompilationUnit2(testSource, testSource);
50 target = new CompletionTarget.forOffset(unit, completionOffset); 51 target = new CompletionTarget.forOffset(unit, completionOffset);
51 // Assert more with resolved unit 52 // Assert more with resolved unit
52 assertCommon(); 53 assertCommon();
53 expect(target.isFunctionalArgument(), isFunctionalArgument); 54 expect(target.isFunctionalArgument(), isFunctionalArgument);
54 } 55 }
55 56
56 test_ArgumentList_InstanceCreationExpression() { 57 test_ArgumentList_InstanceCreationExpression() {
57 // ArgumentList InstanceCreationExpression Block 58 // ArgumentList InstanceCreationExpression Block
58 addTestSource('main() {new Foo(^)}'); 59 addTestSource('main() {new Foo(^)}');
59 assertTarget(')', '()', argIndex: 0); 60 assertTarget(')', '()', argIndex: 0);
60 } 61 }
61 62
62 test_ArgumentList_InstanceCreationExpression_functionArg2() { 63 test_ArgumentList_InstanceCreationExpression_functionArg2() {
63 // ArgumentList InstanceCreationExpression Block 64 // ArgumentList InstanceCreationExpression Block
64 addTestSource('main() {new B(^)} class B{B(f()){}}'); 65 addTestSource('main() {new B(^)} class B{B(f()){}}');
65 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true); 66 assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
66 } 67 }
67 68
68 test_TypeArgumentList() {
69 // SimpleIdentifier BinaryExpression ExpressionStatement
70 addTestSource('main() { C<^> c; }');
71 assertTarget('', 'C < ');
72 }
73
74 test_TypeArgumentList2() {
75 // TypeName TypeArgumentList TypeName
76 addTestSource('main() { C<C^> c; }');
77 assertTarget('C', '<C>');
78 }
79
80 test_ArgumentList_MethodInvocation() { 69 test_ArgumentList_MethodInvocation() {
81 // ArgumentList MethodInvocation Block 70 // ArgumentList MethodInvocation Block
82 addTestSource('main() {foo(^)}'); 71 addTestSource('main() {foo(^)}');
83 assertTarget(')', '()', argIndex: 0); 72 assertTarget(')', '()', argIndex: 0);
84 } 73 }
85 74
86 test_ArgumentList_MethodInvocation2() { 75 test_ArgumentList_MethodInvocation2() {
87 // ArgumentList MethodInvocation Block 76 // ArgumentList MethodInvocation Block
88 addTestSource('main() {foo(^n)}'); 77 addTestSource('main() {foo(^n)}');
89 assertTarget('n', '(n)', argIndex: 0); 78 assertTarget('n', '(n)', argIndex: 0);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 addTestSource('class C {foo(){var f; {var x;} new^ }}'); 294 addTestSource('class C {foo(){var f; {var x;} new^ }}');
306 assertTarget('new ();', '{var f; {var x;} new ();}'); 295 assertTarget('new ();', '{var f; {var x;} new ();}');
307 } 296 }
308 297
309 test_InstanceCreationExpression_keyword2() { 298 test_InstanceCreationExpression_keyword2() {
310 // InstanceCreationExpression ExpressionStatement Block 299 // InstanceCreationExpression ExpressionStatement Block
311 addTestSource('class C {foo(){var f; {var x;} new^ C();}}'); 300 addTestSource('class C {foo(){var f; {var x;} new^ C();}}');
312 assertTarget('new C();', '{var f; {var x;} new C();}'); 301 assertTarget('new C();', '{var f; {var x;} new C();}');
313 } 302 }
314 303
304 test_MapLiteralEntry() {
305 // MapLiteralEntry MapLiteral VariableDeclaration
306 addTestSource('foo = {^');
307 assertTarget(' : ', '{ : }');
308 }
309
310 test_MapLiteralEntry1() {
311 // MapLiteralEntry MapLiteral VariableDeclaration
312 addTestSource('foo = {T^');
313 assertTarget('T : ', '{T : }');
314 }
315
316 test_MapLiteralEntry2() {
317 // SimpleIdentifier MapLiteralEntry MapLiteral VariableDeclaration
318 addTestSource('foo = {7:T^};');
319 assertTarget('T', '7 : T');
320 }
321
315 test_MethodDeclaration_inLineComment() { 322 test_MethodDeclaration_inLineComment() {
316 // Comment ClassDeclaration CompilationUnit 323 // Comment ClassDeclaration CompilationUnit
317 addTestSource(''' 324 addTestSource('''
318 class C2 { 325 class C2 {
319 // normal comment ^ 326 // normal comment ^
320 zoo(z) { } String name; }'''); 327 zoo(z) { } String name; }''');
321 assertTarget('// normal comment ', 'class C2 {zoo(z) {} String name;}'); 328 assertTarget('// normal comment ', 'class C2 {zoo(z) {} String name;}');
322 } 329 }
323 330
324 test_MethodDeclaration_inLineComment2() { 331 test_MethodDeclaration_inLineComment2() {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 addTestSource('class C2 {/** */ ^ zoo(z) { } String name; }'); 467 addTestSource('class C2 {/** */ ^ zoo(z) { } String name; }');
461 assertTarget('zoo', 'zoo(z) {}'); 468 assertTarget('zoo', 'zoo(z) {}');
462 } 469 }
463 470
464 test_MethodDeclaration_returnType_afterStarDocComment2() { 471 test_MethodDeclaration_returnType_afterStarDocComment2() {
465 // MethodDeclaration ClassDeclaration CompilationUnit 472 // MethodDeclaration ClassDeclaration CompilationUnit
466 addTestSource('class C2 {/** */^ zoo(z) { } String name; }'); 473 addTestSource('class C2 {/** */^ zoo(z) { } String name; }');
467 assertTarget('zoo', 'zoo(z) {}'); 474 assertTarget('zoo', 'zoo(z) {}');
468 } 475 }
469 476
477 test_TypeArgumentList() {
478 // SimpleIdentifier BinaryExpression ExpressionStatement
479 addTestSource('main() { C<^> c; }');
480 assertTarget('', 'C < ');
481 }
482
483 test_TypeArgumentList2() {
484 // TypeName TypeArgumentList TypeName
485 addTestSource('main() { C<C^> c; }');
486 assertTarget('C', '<C>');
487 }
488
470 test_VariableDeclaration_lhs_identifier_after() { 489 test_VariableDeclaration_lhs_identifier_after() {
471 // VariableDeclaration VariableDeclarationList 490 // VariableDeclaration VariableDeclarationList
472 addTestSource('main() {int b^ = 1;}'); 491 addTestSource('main() {int b^ = 1;}');
473 assertTarget('b = 1', 'int b = 1'); 492 assertTarget('b = 1', 'int b = 1');
474 } 493 }
475 494
476 test_VariableDeclaration_lhs_identifier_before() { 495 test_VariableDeclaration_lhs_identifier_before() {
477 // VariableDeclaration VariableDeclarationList 496 // VariableDeclaration VariableDeclarationList
478 addTestSource('main() {int ^b = 1;}'); 497 addTestSource('main() {int ^b = 1;}');
479 assertTarget('b = 1', 'int b = 1'); 498 assertTarget('b = 1', 'int b = 1');
480 } 499 }
481 } 500 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698