| 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.invocation; | 5 library test.services.completion.invocation; |
| 6 | 6 |
| 7 | 7 |
| 8 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; | 8 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| 11 import '../../reflective_tests.dart'; | 11 import '../../reflective_tests.dart'; |
| 12 import 'completion_test_util.dart'; | 12 import 'completion_test_util.dart'; |
| 13 | 13 |
| 14 main() { | 14 main() { |
| 15 groupSep = ' | '; | 15 groupSep = ' | '; |
| 16 runReflectiveTests(InvocationComputerTest); | 16 runReflectiveTests(InvocationComputerTest); |
| 17 } | 17 } |
| 18 | 18 |
| 19 @ReflectiveTestCase() | 19 @ReflectiveTestCase() |
| 20 class InvocationComputerTest extends AbstractSelectorSuggestionTest { | 20 class InvocationComputerTest extends AbstractSelectorSuggestionTest { |
| 21 | 21 |
| 22 @override | 22 @override |
| 23 void setUp() { | 23 void setUp() { |
| 24 super.setUp(); | 24 super.setUp(); |
| 25 computer = new InvocationComputer(); | 25 computer = new InvocationComputer(); |
| 26 } | 26 } |
| 27 | |
| 28 test_PrefixedIdentifier_field() { | |
| 29 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 30 addTestSource(''' | |
| 31 class A {var b; X _c;} | |
| 32 class X{} | |
| 33 main() {A a; a.^}'''); | |
| 34 return computeFull().then((_) { | |
| 35 assertSuggestGetter('b', null); | |
| 36 assertSuggestGetter('_c', 'X'); | |
| 37 }); | |
| 38 } | |
| 39 | |
| 40 test_PrefixedIdentifier_field_imported() { | |
| 41 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 42 addSource('/testB.dart', ''' | |
| 43 lib B; | |
| 44 class X{} | |
| 45 class A {var b; X _c;}'''); | |
| 46 addTestSource(''' | |
| 47 import "/testB.dart"; | |
| 48 main() {A a; a.^}'''); | |
| 49 return computeFull().then((_) { | |
| 50 assertSuggestGetter('b', null); | |
| 51 assertNotSuggested('_c'); | |
| 52 }); | |
| 53 } | |
| 54 | |
| 55 test_PrefixedIdentifier_getter() { | |
| 56 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 57 addTestSource(''' | |
| 58 class A {X get b => new A();get _c => new A();} | |
| 59 class X{} | |
| 60 main() {A a; a.^}'''); | |
| 61 return computeFull().then((_) { | |
| 62 assertSuggestGetter('b', 'X'); | |
| 63 assertSuggestGetter('_c', null); | |
| 64 }); | |
| 65 } | |
| 66 | |
| 67 test_PrefixedIdentifier_getter_imported() { | |
| 68 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 69 addSource('/testB.dart', ''' | |
| 70 lib B; | |
| 71 class S{} | |
| 72 class X {S get y => new X(); X get _z => new X();}'''); | |
| 73 addTestSource('import "/testB.dart"; main() {X x; x.^}'); | |
| 74 return computeFull().then((_) { | |
| 75 assertSuggestGetter('y', 'S'); | |
| 76 assertNotSuggested('_z'); | |
| 77 }); | |
| 78 } | |
| 79 | |
| 80 test_PrefixedIdentifier_getter_interface() { | |
| 81 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 82 addTestSource(''' | |
| 83 class A {S get b => new A();A get _c => new A();} | |
| 84 class B implements A {S get b => new A();} class S{} | |
| 85 main() {B b; b.^}'''); | |
| 86 return computeFull().then((_) { | |
| 87 assertSuggestGetter('b', 'S'); | |
| 88 assertSuggestGetter('_c', 'A'); | |
| 89 }); | |
| 90 } | |
| 91 | |
| 92 test_PrefixedIdentifier_interpolation() { | |
| 93 // SimpleIdentifier PrefixedIdentifier InterpolationExpression | |
| 94 addTestSource('main() {String name; print("hello \${name.^}");}'); | |
| 95 return computeFull().then((_) { | |
| 96 assertSuggestGetter('length', 'int'); | |
| 97 }); | |
| 98 } | |
| 99 | |
| 100 test_PrefixedIdentifier_library() { | |
| 101 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 102 addSource('/testB.dart', ''' | |
| 103 lib B; | |
| 104 class X { } | |
| 105 class Y { }'''); | |
| 106 addTestSource(''' | |
| 107 import "/testB.dart" as b; | |
| 108 main() {b.^}'''); | |
| 109 return computeFull().then((_) { | |
| 110 assertSuggestClass('X'); | |
| 111 assertSuggestClass('Y'); | |
| 112 }); | |
| 113 } | |
| 114 | |
| 115 test_PrefixedIdentifier_method() { | |
| 116 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 117 addTestSource(''' | |
| 118 class S{} | |
| 119 class A {b(X x) {} S _c(X x) {}} | |
| 120 main() {A a; a.^}'''); | |
| 121 return computeFull().then((_) { | |
| 122 assertSuggestMethod('b', 'A', null); | |
| 123 assertSuggestMethod('_c', 'A', 'S'); | |
| 124 }); | |
| 125 } | |
| 126 | |
| 127 test_PrefixedIdentifier_method_imported() { | |
| 128 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 129 addSource('/testB.dart', ''' | |
| 130 lib B; | |
| 131 class X {T y(X x) {} _z(X x) {}} | |
| 132 class T{}'''); | |
| 133 addTestSource('import "/testB.dart"; main() {X x; x.^}'); | |
| 134 return computeFull().then((_) { | |
| 135 assertSuggestMethod('y', 'X', 'T'); | |
| 136 assertNotSuggested('_z'); | |
| 137 }); | |
| 138 } | |
| 139 | |
| 140 test_PrefixedIdentifier_method_imported_mixin() { | |
| 141 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 142 addSource('/testB.dart', ''' | |
| 143 lib B; | |
| 144 class X {T y(X x) {} _z(X x) {}} | |
| 145 class T{}'''); | |
| 146 addTestSource(''' | |
| 147 import "/testB.dart"; | |
| 148 class A extends Object with X {} | |
| 149 main() {A a; a.^}'''); | |
| 150 return computeFull().then((_) { | |
| 151 assertSuggestMethod('y', 'X', 'T'); | |
| 152 assertNotSuggested('_z'); | |
| 153 }); | |
| 154 } | |
| 155 | |
| 156 test_PrefixedIdentifier_parameter() { | |
| 157 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 158 addSource('/testB.dart', ''' | |
| 159 lib B; | |
| 160 class _W {M y; var _z;} | |
| 161 class X extends _W {} | |
| 162 class M{}'''); | |
| 163 addTestSource(''' | |
| 164 import "/testB.dart"; | |
| 165 foo(X x) {x.^}'''); | |
| 166 return computeFull().then((_) { | |
| 167 assertSuggestGetter('y', 'M'); | |
| 168 assertNotSuggested('_z'); | |
| 169 }); | |
| 170 } | |
| 171 | |
| 172 test_PrefixedIdentifier_prefix() { | |
| 173 // SimpleIdentifier PrefixedIdentifier InterpolationExpression | |
| 174 addTestSource('main() {String name; print("hello \${nam^e.length}");}'); | |
| 175 return computeFull().then((_) { | |
| 176 // LocalComputer generates suggestions for prefix | |
| 177 assertNotSuggested('name'); | |
| 178 assertNotSuggested('length'); | |
| 179 }); | |
| 180 } | |
| 181 | |
| 182 test_PrefixedIdentifier_setter() { | |
| 183 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 184 addTestSource(''' | |
| 185 class A {set b(X x) {} set _c(X x) {}} | |
| 186 main() {A a; a.^}'''); | |
| 187 return computeFull().then((_) { | |
| 188 assertSuggestSetter('b'); | |
| 189 assertSuggestSetter('_c'); | |
| 190 }); | |
| 191 } | |
| 192 | |
| 193 test_PrefixedIdentifier_setter_imported() { | |
| 194 // SimpleIdentifier PrefixedIdentifier ExpressionStatement | |
| 195 addSource('/testB.dart', ''' | |
| 196 lib B; | |
| 197 class X {set y(X x) {} set _z(X x) {}}'''); | |
| 198 addTestSource(''' | |
| 199 import "/testB.dart"; | |
| 200 main() {X x; x.^}'''); | |
| 201 return computeFull().then((_) { | |
| 202 assertSuggestSetter('y'); | |
| 203 assertNotSuggested('_z'); | |
| 204 }); | |
| 205 } | |
| 206 } | 27 } |
| OLD | NEW |