| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.services.completion.target; |
| 6 |
| 7 import 'package:analysis_server/src/services/completion/completion_target.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 |
| 12 import '../../abstract_context.dart'; |
| 13 import '../../reflective_tests.dart'; |
| 14 |
| 15 main() { |
| 16 groupSep = ' | '; |
| 17 runReflectiveTests(CompletionTargetTest); |
| 18 } |
| 19 |
| 20 @reflectiveTest |
| 21 class CompletionTargetTest extends AbstractContextTest { |
| 22 int completionOffset; |
| 23 CompletionTarget target; |
| 24 |
| 25 void addTestSource(String content) { |
| 26 expect(completionOffset, isNull, reason: 'Call addTestSource exactly once'); |
| 27 completionOffset = content.indexOf('^'); |
| 28 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); |
| 29 int nextOffset = content.indexOf('^', completionOffset + 1); |
| 30 expect(nextOffset, equals(-1), reason: 'too many ^'); |
| 31 content = content.substring(0, completionOffset) + |
| 32 content.substring(completionOffset + 1); |
| 33 Source testSource = addSource('/test.dart', content); |
| 34 CompilationUnit unit = context.parseCompilationUnit(testSource); |
| 35 target = new CompletionTarget.forOffset(unit, completionOffset); |
| 36 } |
| 37 |
| 38 test_AsExpression_identifier() { |
| 39 // SimpleIdentifier TypeName AsExpression |
| 40 addTestSource('class A {var b; X _c; foo() {var a; (a^ as String).foo();}'); |
| 41 expect(target.entity.toString(), 'a as String'); |
| 42 expect(target.containingNode.toString(), '(a as String)'); |
| 43 } |
| 44 |
| 45 test_AsExpression_keyword() { |
| 46 // SimpleIdentifier TypeName AsExpression |
| 47 addTestSource('class A {var b; X _c; foo() {var a; (a ^as String).foo();}'); |
| 48 expect(target.entity.toString(), 'as'); |
| 49 expect(target.containingNode.toString(), 'a as String'); |
| 50 } |
| 51 |
| 52 test_AsExpression_keyword2() { |
| 53 // SimpleIdentifier TypeName AsExpression |
| 54 addTestSource('class A {var b; X _c; foo() {var a; (a a^s String).foo();}'); |
| 55 expect(target.entity.toString(), 'as'); |
| 56 expect(target.containingNode.toString(), 'a as String'); |
| 57 } |
| 58 |
| 59 test_AsExpression_keyword3() { |
| 60 // SimpleIdentifier TypeName AsExpression |
| 61 addTestSource('class A {var b; X _c; foo() {var a; (a as^ String).foo();}'); |
| 62 expect(target.entity.toString(), 'as'); |
| 63 expect(target.containingNode.toString(), 'a as String'); |
| 64 } |
| 65 |
| 66 test_AsExpression_type() { |
| 67 // SimpleIdentifier TypeName AsExpression |
| 68 addTestSource('class A {var b; X _c; foo() {var a; (a as ^String).foo();}'); |
| 69 expect(target.entity.toString(), 'String'); |
| 70 expect(target.containingNode.toString(), 'a as String'); |
| 71 } |
| 72 |
| 73 test_InstanceCreationExpression_keyword() { |
| 74 // InstanceCreationExpression ExpressionStatement Block |
| 75 addTestSource('class C {foo(){var f; {var x;} new^ }}'); |
| 76 expect(target.entity.toString(), 'new ();'); |
| 77 expect(target.containingNode.toString(), '{var f; {var x;} new ();}'); |
| 78 } |
| 79 |
| 80 test_InstanceCreationExpression_keyword2() { |
| 81 // InstanceCreationExpression ExpressionStatement Block |
| 82 addTestSource('class C {foo(){var f; {var x;} new^ C();}}'); |
| 83 expect(target.entity.toString(), 'new C();'); |
| 84 expect(target.containingNode.toString(), '{var f; {var x;} new C();}'); |
| 85 } |
| 86 |
| 87 test_InstanceCreationExpression_identifier() { |
| 88 // InstanceCreationExpression ExpressionStatement Block |
| 89 addTestSource('class C {foo(){var f; {var x;} new ^C();}}'); |
| 90 expect(target.entity.toString(), 'C'); |
| 91 expect(target.containingNode.toString(), 'new C()'); |
| 92 } |
| 93 |
| 94 test_VariableDeclaration_lhs_identifier_after() { |
| 95 // VariableDeclaration VariableDeclarationList |
| 96 addTestSource('main() {int b^ = 1;}'); |
| 97 expect(target.entity.toString(), 'b = 1'); |
| 98 expect(target.containingNode.toString(), 'int b = 1'); |
| 99 } |
| 100 |
| 101 test_VariableDeclaration_lhs_identifier_before() { |
| 102 // VariableDeclaration VariableDeclarationList |
| 103 addTestSource('main() {int ^b = 1;}'); |
| 104 expect(target.entity.toString(), 'b = 1'); |
| 105 expect(target.containingNode.toString(), 'int b = 1'); |
| 106 } |
| 107 } |
| OLD | NEW |