| Index: pkg/analysis_server/test/services/completion/completion_target_test.dart
|
| diff --git a/pkg/analysis_server/test/services/completion/completion_target_test.dart b/pkg/analysis_server/test/services/completion/completion_target_test.dart
|
| index 8decbb71145cb806bb13bd409390b5f8bdb70938..bb258c4345fd1866cea2d408b5829bb4165e822c 100644
|
| --- a/pkg/analysis_server/test/services/completion/completion_target_test.dart
|
| +++ b/pkg/analysis_server/test/services/completion/completion_target_test.dart
|
| @@ -19,6 +19,7 @@ main() {
|
|
|
| @reflectiveTest
|
| class CompletionTargetTest extends AbstractContextTest {
|
| + Source testSource;
|
| int completionOffset;
|
| CompletionTarget target;
|
|
|
| @@ -30,78 +31,139 @@ class CompletionTargetTest extends AbstractContextTest {
|
| expect(nextOffset, equals(-1), reason: 'too many ^');
|
| content = content.substring(0, completionOffset) +
|
| content.substring(completionOffset + 1);
|
| - Source testSource = addSource('/test.dart', content);
|
| + testSource = addSource('/test.dart', content);
|
| CompilationUnit unit = context.parseCompilationUnit(testSource);
|
| target = new CompletionTarget.forOffset(unit, completionOffset);
|
| }
|
|
|
| + void assertTarget(entityText, nodeText,
|
| + {int argIndex: null, bool isFunctionalArgument: false}) {
|
| + void assertCommon() {
|
| + expect(target.entity.toString(), entityText);
|
| + expect(target.containingNode.toString(), nodeText);
|
| + expect(target.argIndex, argIndex);
|
| + }
|
| + // Assert with parsed unit
|
| + assertCommon();
|
| + CompilationUnit unit =
|
| + context.resolveCompilationUnit2(testSource, testSource);
|
| + target = new CompletionTarget.forOffset(unit, completionOffset);
|
| + // Assert more with resolved unit
|
| + assertCommon();
|
| + expect(target.isFunctionalArgument(), isFunctionalArgument);
|
| + }
|
| +
|
| + test_ArgumentList_InstanceCreationExpression() {
|
| + // ArgumentList InstanceCreationExpression Block
|
| + addTestSource('main() {new Foo(^)}');
|
| + assertTarget(')', '()', argIndex: 0);
|
| + }
|
| +
|
| + test_ArgumentList_MethodInvocation() {
|
| + // ArgumentList MethodInvocation Block
|
| + addTestSource('main() {foo(^)}');
|
| + assertTarget(')', '()', argIndex: 0);
|
| + }
|
| +
|
| + test_ArgumentList_MethodInvocation2() {
|
| + // ArgumentList MethodInvocation Block
|
| + addTestSource('main() {foo(^n)}');
|
| + assertTarget('n', '(n)', argIndex: 0);
|
| + }
|
| +
|
| + test_ArgumentList_MethodInvocation3() {
|
| + // ArgumentList MethodInvocation Block
|
| + addTestSource('main() {foo(n^)}');
|
| + assertTarget('n', '(n)', argIndex: 0);
|
| + }
|
| +
|
| + test_ArgumentList_MethodInvocation4() {
|
| + // ArgumentList MethodInvocation Block
|
| + addTestSource('main() {foo(n,^)}');
|
| + assertTarget('', '(n, )', argIndex: 1);
|
| + }
|
| +
|
| + test_ArgumentList_MethodInvocation_functionArg() {
|
| + // ArgumentList MethodInvocation Block
|
| + addTestSource('main() {foo(^)} foo(f()) {}');
|
| + assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
|
| + }
|
| +
|
| + test_ArgumentList_MethodInvocation_functionArg2() {
|
| + // ArgumentList MethodInvocation Block
|
| + addTestSource('main() {new B().boo(^)} class B{boo(f()){}}');
|
| + assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
|
| + }
|
| +
|
| + test_ArgumentList_InstanceCreationExpression_functionArg2() {
|
| + // ArgumentList InstanceCreationExpression Block
|
| + addTestSource('main() {new B(^)} class B{B(f()){}}');
|
| + assertTarget(')', '()', argIndex: 0, isFunctionalArgument: true);
|
| + }
|
| +
|
| test_AsExpression_identifier() {
|
| // SimpleIdentifier TypeName AsExpression
|
| addTestSource('class A {var b; X _c; foo() {var a; (a^ as String).foo();}');
|
| - expect(target.entity.toString(), 'a as String');
|
| - expect(target.containingNode.toString(), '(a as String)');
|
| + assertTarget('a as String', '(a as String)');
|
| }
|
|
|
| test_AsExpression_keyword() {
|
| // SimpleIdentifier TypeName AsExpression
|
| addTestSource('class A {var b; X _c; foo() {var a; (a ^as String).foo();}');
|
| - expect(target.entity.toString(), 'as');
|
| - expect(target.containingNode.toString(), 'a as String');
|
| + assertTarget('as', 'a as String');
|
| }
|
|
|
| test_AsExpression_keyword2() {
|
| // SimpleIdentifier TypeName AsExpression
|
| addTestSource('class A {var b; X _c; foo() {var a; (a a^s String).foo();}');
|
| - expect(target.entity.toString(), 'as');
|
| - expect(target.containingNode.toString(), 'a as String');
|
| + assertTarget('as', 'a as String');
|
| }
|
|
|
| test_AsExpression_keyword3() {
|
| // SimpleIdentifier TypeName AsExpression
|
| addTestSource('class A {var b; X _c; foo() {var a; (a as^ String).foo();}');
|
| - expect(target.entity.toString(), 'as');
|
| - expect(target.containingNode.toString(), 'a as String');
|
| + assertTarget('as', 'a as String');
|
| }
|
|
|
| test_AsExpression_type() {
|
| // SimpleIdentifier TypeName AsExpression
|
| addTestSource('class A {var b; X _c; foo() {var a; (a as ^String).foo();}');
|
| - expect(target.entity.toString(), 'String');
|
| - expect(target.containingNode.toString(), 'a as String');
|
| + assertTarget('String', 'a as String');
|
| + }
|
| +
|
| + test_Block() {
|
| + // Block
|
| + addTestSource('main() {^}');
|
| + assertTarget('}', '{}');
|
| + }
|
| +
|
| + test_InstanceCreationExpression_identifier() {
|
| + // InstanceCreationExpression ExpressionStatement Block
|
| + addTestSource('class C {foo(){var f; {var x;} new ^C();}}');
|
| + assertTarget('C', 'new C()');
|
| }
|
|
|
| test_InstanceCreationExpression_keyword() {
|
| // InstanceCreationExpression ExpressionStatement Block
|
| addTestSource('class C {foo(){var f; {var x;} new^ }}');
|
| - expect(target.entity.toString(), 'new ();');
|
| - expect(target.containingNode.toString(), '{var f; {var x;} new ();}');
|
| + assertTarget('new ();', '{var f; {var x;} new ();}');
|
| }
|
|
|
| test_InstanceCreationExpression_keyword2() {
|
| // InstanceCreationExpression ExpressionStatement Block
|
| addTestSource('class C {foo(){var f; {var x;} new^ C();}}');
|
| - expect(target.entity.toString(), 'new C();');
|
| - expect(target.containingNode.toString(), '{var f; {var x;} new C();}');
|
| - }
|
| -
|
| - test_InstanceCreationExpression_identifier() {
|
| - // InstanceCreationExpression ExpressionStatement Block
|
| - addTestSource('class C {foo(){var f; {var x;} new ^C();}}');
|
| - expect(target.entity.toString(), 'C');
|
| - expect(target.containingNode.toString(), 'new C()');
|
| + assertTarget('new C();', '{var f; {var x;} new C();}');
|
| }
|
|
|
| test_VariableDeclaration_lhs_identifier_after() {
|
| // VariableDeclaration VariableDeclarationList
|
| addTestSource('main() {int b^ = 1;}');
|
| - expect(target.entity.toString(), 'b = 1');
|
| - expect(target.containingNode.toString(), 'int b = 1');
|
| + assertTarget('b = 1', 'int b = 1');
|
| }
|
|
|
| test_VariableDeclaration_lhs_identifier_before() {
|
| // VariableDeclaration VariableDeclarationList
|
| addTestSource('main() {int ^b = 1;}');
|
| - expect(target.entity.toString(), 'b = 1');
|
| - expect(target.containingNode.toString(), 'int b = 1');
|
| + assertTarget('b = 1', 'int b = 1');
|
| }
|
| }
|
|
|