| 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.integration.analysis.domain; | 5 library test.integration.analysis.domain; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/constants.dart'; | |
| 10 import 'package:analysis_testing/reflective_tests.dart'; | 9 import 'package:analysis_testing/reflective_tests.dart'; |
| 11 import 'package:path/path.dart'; | 10 import 'package:path/path.dart'; |
| 12 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 13 | 12 |
| 14 import 'integration_tests.dart'; | 13 import 'integration_tests.dart'; |
| 15 import 'protocol_matchers.dart'; | |
| 16 | 14 |
| 17 @ReflectiveTestCase() | 15 @ReflectiveTestCase() |
| 18 class AnalysisDomainIntegrationTest extends | 16 class AnalysisDomainIntegrationTest extends |
| 19 AbstractAnalysisServerIntegrationTest { | 17 AbstractAnalysisServerIntegrationTest { |
| 20 test_getHover() { | 18 test_getHover() { |
| 21 String pathname = sourcePath('test.dart'); | 19 String pathname = sourcePath('test.dart'); |
| 22 String text = | 20 String text = |
| 23 r''' | 21 r''' |
| 24 library lib.test; | 22 library lib.test; |
| 25 | 23 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 } | 37 } |
| 40 '''; | 38 '''; |
| 41 writeFile(pathname, text); | 39 writeFile(pathname, text); |
| 42 standardAnalysisRoot(); | 40 standardAnalysisRoot(); |
| 43 | 41 |
| 44 testHover(String target, int length, List<String> descriptionRegexps, String | 42 testHover(String target, int length, List<String> descriptionRegexps, String |
| 45 kind, List<String> staticTypeRegexps, {bool isCore: false, String docReg
exp: | 43 kind, List<String> staticTypeRegexps, {bool isCore: false, String docReg
exp: |
| 46 null, bool isLiteral: false, List<String> parameterRegexps: | 44 null, bool isLiteral: false, List<String> parameterRegexps: |
| 47 null, propagatedType: null}) { | 45 null, propagatedType: null}) { |
| 48 int offset = text.indexOf(target); | 46 int offset = text.indexOf(target); |
| 49 return server.send(ANALYSIS_GET_HOVER, { | 47 return sendAnalysisGetHover(pathname, offset).then((result) { |
| 50 'file': pathname, | |
| 51 'offset': offset | |
| 52 }).then((result) { | |
| 53 expect(result, isAnalysisGetHoverResult); | |
| 54 expect(result['hovers'], hasLength(1)); | 48 expect(result['hovers'], hasLength(1)); |
| 55 var info = result['hovers'][0]; | 49 var info = result['hovers'][0]; |
| 56 expect(info['offset'], equals(offset)); | 50 expect(info['offset'], equals(offset)); |
| 57 expect(info['length'], equals(length)); | 51 expect(info['length'], equals(length)); |
| 58 if (isCore) { | 52 if (isCore) { |
| 59 expect(basename(info['containingLibraryPath']), equals('core.dart')); | 53 expect(basename(info['containingLibraryPath']), equals('core.dart')); |
| 60 expect(info['containingLibraryName'], equals('dart.core')); | 54 expect(info['containingLibraryName'], equals('dart.core')); |
| 61 } else if (isLiteral) { | 55 } else if (isLiteral) { |
| 62 expect(info['containingLibraryPath'], isNull); | 56 expect(info['containingLibraryPath'], isNull); |
| 63 expect(info['containingLibraryName'], isNull); | 57 expect(info['containingLibraryName'], isNull); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // no code | 137 // no code |
| 144 } | 138 } |
| 145 '''; | 139 '''; |
| 146 writeFile(pathname, text); | 140 writeFile(pathname, text); |
| 147 standardAnalysisRoot(); | 141 standardAnalysisRoot(); |
| 148 | 142 |
| 149 // Note: analysis.getHover doesn't wait for analysis to complete--it simply | 143 // Note: analysis.getHover doesn't wait for analysis to complete--it simply |
| 150 // returns the latest results that are available at the time that the | 144 // returns the latest results that are available at the time that the |
| 151 // request is made. So wait for analysis to finish before testing anything. | 145 // request is made. So wait for analysis to finish before testing anything. |
| 152 return analysisFinished.then((_) { | 146 return analysisFinished.then((_) { |
| 153 return server.send(ANALYSIS_GET_HOVER, { | 147 return sendAnalysisGetHover(pathname, text.indexOf('no code')).then( |
| 154 'file': pathname, | 148 (result) { |
| 155 'offset': text.indexOf('no code') | |
| 156 }).then((result) { | |
| 157 expect(result, isAnalysisGetHoverResult); | |
| 158 expect(result['hovers'], hasLength(0)); | 149 expect(result['hovers'], hasLength(0)); |
| 159 }); | 150 }); |
| 160 }); | 151 }); |
| 161 } | 152 } |
| 162 | 153 |
| 163 test_getErrors_before_analysis() { | 154 test_getErrors_before_analysis() { |
| 164 return getErrorsTest(false); | 155 return getErrorsTest(false); |
| 165 } | 156 } |
| 166 | 157 |
| 167 test_getErrors_after_analysis() { | 158 test_getErrors_after_analysis() { |
| 168 return getErrorsTest(true); | 159 return getErrorsTest(true); |
| 169 } | 160 } |
| 170 | 161 |
| 171 Future getErrorsTest(bool afterAnalysis) { | 162 Future getErrorsTest(bool afterAnalysis) { |
| 172 String pathname = sourcePath('test.dart'); | 163 String pathname = sourcePath('test.dart'); |
| 173 String text = r''' | 164 String text = r''' |
| 174 main() { | 165 main() { |
| 175 var x // parse error: missing ';' | 166 var x // parse error: missing ';' |
| 176 }'''; | 167 }'''; |
| 177 writeFile(pathname, text); | 168 writeFile(pathname, text); |
| 178 standardAnalysisRoot(); | 169 standardAnalysisRoot(); |
| 179 Future finishTest() { | 170 Future finishTest() { |
| 180 return server.send(ANALYSIS_GET_ERRORS, { | 171 return sendAnalysisGetErrors(pathname).then((result) { |
| 181 'file': pathname | |
| 182 }).then((result) { | |
| 183 expect(result, isAnalysisGetErrorsResult); | |
| 184 expect(result['errors'], equals(currentAnalysisErrors[pathname])); | 172 expect(result['errors'], equals(currentAnalysisErrors[pathname])); |
| 185 }); | 173 }); |
| 186 } | 174 } |
| 187 if (afterAnalysis) { | 175 if (afterAnalysis) { |
| 188 return analysisFinished.then((_) => finishTest()); | 176 return analysisFinished.then((_) => finishTest()); |
| 189 } else { | 177 } else { |
| 190 return finishTest(); | 178 return finishTest(); |
| 191 } | 179 } |
| 192 } | 180 } |
| 193 | 181 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 212 // The contents on disk (badText) are missing a semicolon. | 200 // The contents on disk (badText) are missing a semicolon. |
| 213 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); | 201 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); |
| 214 var contentChange = { | 202 var contentChange = { |
| 215 'content': goodText | 203 'content': goodText |
| 216 }; | 204 }; |
| 217 if (includeOffsetAndLengths) { | 205 if (includeOffsetAndLengths) { |
| 218 contentChange['offset'] = goodText.indexOf(';'); | 206 contentChange['offset'] = goodText.indexOf(';'); |
| 219 contentChange['oldLength'] = 0; | 207 contentChange['oldLength'] = 0; |
| 220 contentChange['newLength'] = 1; | 208 contentChange['newLength'] = 1; |
| 221 } | 209 } |
| 222 return server.send(ANALYSIS_UPDATE_CONTENT, { | 210 return sendAnalysisUpdateContent({ |
| 223 'files': { | 211 pathname: contentChange |
| 224 pathname: contentChange | |
| 225 } | |
| 226 }); | 212 }); |
| 227 }).then((result) { | 213 }).then((result) => analysisFinished).then((_) { |
| 228 expect(result, isNull); | |
| 229 return analysisFinished; | |
| 230 }).then((_) { | |
| 231 // There should be no errors now because the contents on disk have been | 214 // There should be no errors now because the contents on disk have been |
| 232 // overriden with goodText. | 215 // overriden with goodText. |
| 233 expect(currentAnalysisErrors[pathname], isEmpty); | 216 expect(currentAnalysisErrors[pathname], isEmpty); |
| 234 return server.send(ANALYSIS_UPDATE_CONTENT, { | 217 // TODO(paulberry): passing "checkTypes: false" to work around the fact |
| 235 'files': { | 218 // that isContentChange doesn't permit 'content' to be null. |
| 236 pathname: { | 219 return sendAnalysisUpdateContent({ |
| 237 'content': null | 220 pathname: { |
| 238 } | 221 'content': null |
| 239 } | 222 } |
| 240 }); | 223 }, checkTypes: false); |
| 241 }).then((result) { | 224 }).then((result) => analysisFinished).then((_) { |
| 242 expect(result, isNull); | |
| 243 return analysisFinished; | |
| 244 }).then((_) { | |
| 245 // Now there should be errors again, because the contents on disk are no | 225 // Now there should be errors again, because the contents on disk are no |
| 246 // longer overridden. | 226 // longer overridden. |
| 247 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); | 227 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); |
| 248 }); | 228 }); |
| 249 } | 229 } |
| 250 } | 230 } |
| 251 | 231 |
| 252 main() { | 232 main() { |
| 253 runReflectiveTests(AnalysisDomainIntegrationTest); | 233 runReflectiveTests(AnalysisDomainIntegrationTest); |
| 254 } | 234 } |
| OLD | NEW |