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