OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.statement; | 5 library test.services.completion.statement; |
6 | 6 |
7 import 'package:analysis_server/src/protocol_server.dart'; | 7 import 'package:analysis_server/src/protocol_server.dart'; |
8 import 'package:analysis_server/src/services/completion/statement/statement_comp
letion.dart'; | 8 import 'package:analysis_server/src/services/completion/statement/statement_comp
letion.dart'; |
9 import 'package:analyzer/src/dart/analysis/driver.dart'; | 9 import 'package:analyzer/src/dart/analysis/driver.dart'; |
10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
11 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
12 | 12 |
13 import '../../../abstract_single_unit.dart'; | 13 import '../../../abstract_single_unit.dart'; |
14 | 14 |
15 main() { | 15 main() { |
16 defineReflectiveSuite(() { | 16 defineReflectiveSuite(() { |
17 defineReflectiveTests(StatementCompletionTest); | 17 defineReflectiveTests(StatementCompletionTest); |
18 }); | 18 }); |
19 } | 19 } |
20 | 20 |
21 @reflectiveTest | 21 @reflectiveTest |
22 class StatementCompletionTest extends AbstractSingleUnitTest { | 22 class StatementCompletionTest extends AbstractSingleUnitTest { |
23 SourceChange change; | 23 SourceChange change; |
24 | 24 |
25 bool get enableNewAnalysisDriver => true; | 25 bool get enableNewAnalysisDriver => true; |
26 | 26 |
27 test_completeIfEmptyCondition() async { | 27 test_completeDoEmptyCondition() async { |
28 await _prepareCompletion( | 28 await _prepareCompletion( |
29 'if ()', | 29 'while ()', |
30 ''' | 30 ''' |
31 main() { | 31 main() { |
32 if () | 32 do { |
| 33 } while () |
33 } | 34 } |
34 ''', | 35 ''', |
35 atEnd: true); | 36 atEnd: true); |
36 _assertHasChange( | 37 _assertHasChange( |
37 'Complete if-statement', | 38 'Complete do-statement', |
38 ''' | 39 ''' |
39 main() { | 40 main() { |
40 if () { | 41 do { |
41 //// | 42 } while (); |
42 } | |
43 } | 43 } |
44 ''', | 44 ''', |
45 (s) => s.indexOf('if (') + 'if ('.length); | 45 (s) => s.indexOf('while (') + 'while ('.length); |
46 } | 46 } |
47 | 47 |
48 test_completeIfKeywordOnly() async { | 48 test_completeDoKeywordOnly() async { |
49 await _prepareCompletion( | 49 await _prepareCompletion( |
50 'if', | 50 'do', |
51 ''' | 51 ''' |
52 main() { | 52 main() { |
53 if //// | 53 do //// |
54 } | 54 } |
55 ''', | 55 ''', |
56 atEnd: true); | 56 atEnd: true); |
57 _assertHasChange( | 57 _assertHasChange( |
58 'Complete if-statement', | 58 'Complete do-statement', |
59 ''' | 59 ''' |
60 main() { | 60 main() { |
61 if () { | 61 do { |
62 //// | 62 //// |
63 } | 63 } while (); |
64 } | 64 } |
65 ''', | 65 ''', |
66 (s) => s.indexOf('if (') + 'if ('.length); | 66 (s) => s.indexOf('while (') + 'while ('.length); |
67 } | 67 } |
68 | 68 |
69 test_completeIfWithCondition() async { | 69 test_completeDoNoBody() async { |
70 await _prepareCompletion( | 70 await _prepareCompletion( |
71 'if (tr', // Trigger completion from within expression. | 71 'do', |
72 ''' | 72 ''' |
73 main() { | 73 main() { |
74 if (true) | 74 do; |
| 75 while |
75 } | 76 } |
76 ''', | 77 ''', |
77 atEnd: true); | 78 atEnd: true); |
78 _assertHasChange( | 79 _assertHasChange( |
79 'Complete if-statement', | 80 'Complete do-statement', |
80 ''' | 81 ''' |
81 main() { | 82 main() { |
82 if (true) { | 83 do { |
83 //// | 84 //// |
| 85 } while (); |
| 86 } |
| 87 ''', |
| 88 (s) => s.indexOf('while (') + 'while ('.length); |
| 89 } |
| 90 |
| 91 test_completeDoNoCondition() async { |
| 92 await _prepareCompletion( |
| 93 'while', |
| 94 ''' |
| 95 main() { |
| 96 do { |
| 97 } while |
| 98 } |
| 99 ''', |
| 100 atEnd: true); |
| 101 _assertHasChange( |
| 102 'Complete do-statement', |
| 103 ''' |
| 104 main() { |
| 105 do { |
| 106 } while (); |
| 107 } |
| 108 ''', |
| 109 (s) => s.indexOf('while (') + 'while ('.length); |
| 110 } |
| 111 |
| 112 test_completeDoNoWhile() async { |
| 113 await _prepareCompletion( |
| 114 '}', |
| 115 ''' |
| 116 main() { |
| 117 do { |
84 } | 118 } |
85 } | 119 } |
86 ''', | 120 ''', |
87 (s) => s.indexOf(' ') + ' '.length); | 121 atEnd: true); |
| 122 _assertHasChange( |
| 123 'Complete do-statement', |
| 124 ''' |
| 125 main() { |
| 126 do { |
| 127 } while (); |
| 128 } |
| 129 ''', |
| 130 (s) => s.indexOf('while (') + 'while ('.length); |
88 } | 131 } |
89 | 132 |
90 test_completeIfAfterCondition_BAD() async { | 133 test_completeIfAfterCondition_BAD() async { |
91 // TODO(messick): Fix the code to make this like test_completeIfWithConditio
n. | 134 // TODO(messick): Fix the code to make this like test_completeIfWithConditio
n. |
92 // Recap: Finding the node at the selectionOffset returns the block, not the | 135 // Recap: Finding the node at the selectionOffset returns the block, not the |
93 // if-statement. Need to understand if that only happens when the if-stateme
nt | 136 // if-statement. Need to understand if that only happens when the if-stateme
nt |
94 // is the only statement in the block, or perhaps first or last? And what | 137 // is the only statement in the block, or perhaps first or last? And what |
95 // happens when it is in the middle of other statements? | 138 // happens when it is in the middle of other statements? |
96 await _prepareCompletion( | 139 await _prepareCompletion( |
97 'if (true) ', // Trigger completion after space. | 140 'if (true) ', // Trigger completion after space. |
98 ''' | 141 ''' |
99 main() { | 142 main() { |
100 if (true) //// | 143 if (true) //// |
101 } | 144 } |
102 ''', | 145 ''', |
103 atEnd: true); | 146 atEnd: true); |
104 _assertHasChange( | 147 _assertHasChange( |
105 // Note: This is not what we want. | 148 // Note: This is not what we want. |
106 'Insert a newline at the end of the current line', | 149 'Insert a newline at the end of the current line', |
107 ''' | 150 ''' |
108 main() { | 151 main() { |
109 if (true) //// | 152 if (true) //// |
110 } | 153 } |
111 } | 154 } |
112 ''', | 155 ''', |
113 (s) => s.indexOf('if (true) ') + 'if (true) '.length); | 156 (s) => s.indexOf('if (true) ') + 'if (true) '.length); |
114 } | 157 } |
115 | 158 |
| 159 test_completeIfEmptyCondition() async { |
| 160 await _prepareCompletion( |
| 161 'if ()', |
| 162 ''' |
| 163 main() { |
| 164 if () |
| 165 } |
| 166 ''', |
| 167 atEnd: true); |
| 168 _assertHasChange( |
| 169 'Complete if-statement', |
| 170 ''' |
| 171 main() { |
| 172 if () { |
| 173 //// |
| 174 } |
| 175 } |
| 176 ''', |
| 177 (s) => s.indexOf('if (') + 'if ('.length); |
| 178 } |
| 179 |
| 180 test_completeIfKeywordOnly() async { |
| 181 await _prepareCompletion( |
| 182 'if', |
| 183 ''' |
| 184 main() { |
| 185 if //// |
| 186 } |
| 187 ''', |
| 188 atEnd: true); |
| 189 _assertHasChange( |
| 190 'Complete if-statement', |
| 191 ''' |
| 192 main() { |
| 193 if () { |
| 194 //// |
| 195 } |
| 196 } |
| 197 ''', |
| 198 (s) => s.indexOf('if (') + 'if ('.length); |
| 199 } |
| 200 |
| 201 test_completeIfWithCondition() async { |
| 202 await _prepareCompletion( |
| 203 'if (tr', // Trigger completion from within expression. |
| 204 ''' |
| 205 main() { |
| 206 if (true) |
| 207 } |
| 208 ''', |
| 209 atEnd: true); |
| 210 _assertHasChange( |
| 211 'Complete if-statement', |
| 212 ''' |
| 213 main() { |
| 214 if (true) { |
| 215 //// |
| 216 } |
| 217 } |
| 218 ''', |
| 219 (s) => s.indexOf(' ') + ' '.length); |
| 220 } |
| 221 |
116 test_completeIfWithElse_BAD() async { | 222 test_completeIfWithElse_BAD() async { |
117 await _prepareCompletion( | 223 await _prepareCompletion( |
118 'if ()', | 224 'if ()', |
119 ''' | 225 ''' |
120 main() { | 226 main() { |
121 if () | 227 if () |
122 else | 228 else |
123 } | 229 } |
124 ''', | 230 ''', |
125 atEnd: true); | 231 atEnd: true); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 371 } |
266 await _prepareCompletionAt(offset + delta, testCode); | 372 await _prepareCompletionAt(offset + delta, testCode); |
267 } | 373 } |
268 | 374 |
269 _prepareCompletionAt(int offset, String sourceCode) async { | 375 _prepareCompletionAt(int offset, String sourceCode) async { |
270 verifyNoTestUnitErrors = false; | 376 verifyNoTestUnitErrors = false; |
271 await resolveTestUnit(sourceCode); | 377 await resolveTestUnit(sourceCode); |
272 await _computeCompletion(offset); | 378 await _computeCompletion(offset); |
273 } | 379 } |
274 } | 380 } |
OLD | NEW |