| 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.domain.completion; | 5 library test.domain.completion; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 10 import 'package:analysis_server/src/domain_completion.dart'; | 10 import 'package:analysis_server/src/domain_completion.dart'; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 test_imports() { | 134 test_imports() { |
| 135 addTestFile(''' | 135 addTestFile(''' |
| 136 import 'dart:html'; | 136 import 'dart:html'; |
| 137 main() {^} | 137 main() {^} |
| 138 '''); | 138 '''); |
| 139 return getSuggestions().then((_) { | 139 return getSuggestions().then((_) { |
| 140 expect(replacementOffset, equals(completionOffset)); | 140 expect(replacementOffset, equals(completionOffset)); |
| 141 expect(replacementLength, equals(0)); | 141 expect(replacementLength, equals(0)); |
| 142 assertHasResult(CompletionSuggestionKind.CLASS, 'Object'); | 142 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); |
| 143 assertHasResult(CompletionSuggestionKind.CLASS, 'HtmlElement'); | 143 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); |
| 144 assertNoResult('test'); | 144 assertNoResult('test'); |
| 145 }); | 145 }); |
| 146 } | 146 } |
| 147 | 147 |
| 148 test_imports_prefixed() { | 148 test_imports_prefixed() { |
| 149 addTestFile(''' | 149 addTestFile(''' |
| 150 import 'dart:html' as foo; | 150 import 'dart:html' as foo; |
| 151 main() {^} | 151 main() {^} |
| 152 '''); | 152 '''); |
| 153 return getSuggestions().then((_) { | 153 return getSuggestions().then((_) { |
| 154 expect(replacementOffset, equals(completionOffset)); | 154 expect(replacementOffset, equals(completionOffset)); |
| 155 expect(replacementLength, equals(0)); | 155 expect(replacementLength, equals(0)); |
| 156 assertHasResult(CompletionSuggestionKind.CLASS, 'Object'); | 156 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); |
| 157 assertHasResult(CompletionSuggestionKind.LIBRARY_PREFIX, 'foo'); | 157 assertHasResult(CompletionSuggestionKind.INVOCATION, 'foo'); |
| 158 assertNoResult('HtmlElement'); | 158 assertNoResult('HtmlElement'); |
| 159 assertNoResult('test'); | 159 assertNoResult('test'); |
| 160 }); | 160 }); |
| 161 } | 161 } |
| 162 | 162 |
| 163 test_keyword() { | 163 test_keyword() { |
| 164 addTestFile('library A; cl^'); | 164 addTestFile('library A; cl^'); |
| 165 return getSuggestions().then((_) { | 165 return getSuggestions().then((_) { |
| 166 expect(replacementOffset, equals(completionOffset - 2)); | 166 expect(replacementOffset, equals(completionOffset - 2)); |
| 167 expect(replacementLength, equals(2)); | 167 expect(replacementLength, equals(2)); |
| 168 assertHasResult( | 168 assertHasResult( |
| 169 CompletionSuggestionKind.KEYWORD, | 169 CompletionSuggestionKind.KEYWORD, |
| 170 'import', | 170 'import', |
| 171 CompletionRelevance.HIGH); | 171 CompletionRelevance.HIGH); |
| 172 assertHasResult( | 172 assertHasResult( |
| 173 CompletionSuggestionKind.KEYWORD, | 173 CompletionSuggestionKind.KEYWORD, |
| 174 'class', | 174 'class', |
| 175 CompletionRelevance.HIGH); | 175 CompletionRelevance.HIGH); |
| 176 }); | 176 }); |
| 177 } | 177 } |
| 178 | 178 |
| 179 test_locals() { | 179 test_locals() { |
| 180 addTestFile('class A {var a; x() {var b;^}}'); | 180 addTestFile('class A {var a; x() {var b;^}}'); |
| 181 return getSuggestions().then((_) { | 181 return getSuggestions().then((_) { |
| 182 expect(replacementOffset, equals(completionOffset)); | 182 expect(replacementOffset, equals(completionOffset)); |
| 183 expect(replacementLength, equals(0)); | 183 expect(replacementLength, equals(0)); |
| 184 assertHasResult(CompletionSuggestionKind.CLASS, 'A'); | 184 assertHasResult(CompletionSuggestionKind.INVOCATION, 'A'); |
| 185 assertHasResult(CompletionSuggestionKind.GETTER, 'a'); | 185 assertHasResult(CompletionSuggestionKind.INVOCATION, 'a'); |
| 186 assertHasResult(CompletionSuggestionKind.LOCAL_VARIABLE, 'b'); | 186 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); |
| 187 assertHasResult(CompletionSuggestionKind.METHOD, 'x'); | 187 assertHasResult(CompletionSuggestionKind.INVOCATION, 'x'); |
| 188 }); | 188 }); |
| 189 } | 189 } |
| 190 | 190 |
| 191 test_invocation() { | 191 test_invocation() { |
| 192 addTestFile('class A {b() {}} main() {A a; a.^}'); | 192 addTestFile('class A {b() {}} main() {A a; a.^}'); |
| 193 return getSuggestions().then((_) { | 193 return getSuggestions().then((_) { |
| 194 expect(replacementOffset, equals(completionOffset)); | 194 expect(replacementOffset, equals(completionOffset)); |
| 195 expect(replacementLength, equals(0)); | 195 expect(replacementLength, equals(0)); |
| 196 assertHasResult(CompletionSuggestionKind.METHOD, 'b'); | 196 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); |
| 197 }); | 197 }); |
| 198 } | 198 } |
| 199 | 199 |
| 200 test_topLevel() { | 200 test_topLevel() { |
| 201 addTestFile(''' | 201 addTestFile(''' |
| 202 typedef foo(); | 202 typedef foo(); |
| 203 var test = ''; | 203 var test = ''; |
| 204 main() {tes^t} | 204 main() {tes^t} |
| 205 '''); | 205 '''); |
| 206 return getSuggestions().then((_) { | 206 return getSuggestions().then((_) { |
| 207 expect(replacementOffset, equals(completionOffset - 3)); | 207 expect(replacementOffset, equals(completionOffset - 3)); |
| 208 expect(replacementLength, equals(4)); | 208 expect(replacementLength, equals(4)); |
| 209 assertHasResult(CompletionSuggestionKind.CLASS, 'Object'); | 209 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); |
| 210 assertHasResult(CompletionSuggestionKind.TOP_LEVEL_VARIABLE, 'test'); | 210 assertHasResult(CompletionSuggestionKind.INVOCATION, 'test'); |
| 211 assertNoResult('HtmlElement'); | 211 assertNoResult('HtmlElement'); |
| 212 }); | 212 }); |
| 213 } | 213 } |
| 214 } | 214 } |
| OLD | NEW |