| 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'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 10 import 'package:analysis_testing/reflective_tests.dart'; | 10 import 'package:analysis_testing/reflective_tests.dart'; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return getErrorsTest(false); | 165 return getErrorsTest(false); |
| 166 } | 166 } |
| 167 | 167 |
| 168 test_getErrors_after_analysis() { | 168 test_getErrors_after_analysis() { |
| 169 return getErrorsTest(true); | 169 return getErrorsTest(true); |
| 170 } | 170 } |
| 171 | 171 |
| 172 Future getErrorsTest(bool afterAnalysis) { | 172 Future getErrorsTest(bool afterAnalysis) { |
| 173 String filename = 'test.dart'; | 173 String filename = 'test.dart'; |
| 174 String pathname = normalizePath(filename); | 174 String pathname = normalizePath(filename); |
| 175 String text = | 175 String text = r''' |
| 176 r''' | 176 main() { |
| 177 main() { | 177 var x // parse error: missing ';' |
| 178 var x // parse error: missing ';' | 178 }'''; |
| 179 }'''; | |
| 180 writeFile(filename, text); | 179 writeFile(filename, text); |
| 181 setAnalysisRoots(['']); | 180 setAnalysisRoots(['']); |
| 182 Future finishTest() { | 181 Future finishTest() { |
| 183 return server.send(ANALYSIS_GET_ERRORS, { | 182 return server.send(ANALYSIS_GET_ERRORS, { |
| 184 'file': pathname | 183 'file': pathname |
| 185 }).then((result) { | 184 }).then((result) { |
| 186 expect(result, isAnalysisGetErrorsResult); | 185 expect(result, isAnalysisGetErrorsResult); |
| 187 expect(result['errors'], equals(currentAnalysisErrors[pathname])); | 186 expect(result['errors'], equals(currentAnalysisErrors[pathname])); |
| 188 }); | 187 }); |
| 189 } | 188 } |
| 190 if (afterAnalysis) { | 189 if (afterAnalysis) { |
| 191 return analysisFinished.then((_) => finishTest()); | 190 return analysisFinished.then((_) => finishTest()); |
| 192 } else { | 191 } else { |
| 193 return finishTest(); | 192 return finishTest(); |
| 194 } | 193 } |
| 195 } | 194 } |
| 195 |
| 196 test_updateContent_content_only() { |
| 197 return updateContentTest(false); |
| 198 } |
| 199 |
| 200 test_updateContent_including_offset_and_lengths() { |
| 201 return updateContentTest(true); |
| 202 } |
| 203 |
| 204 Future updateContentTest(bool includeOffsetAndLengths) { |
| 205 String filename = 'test.dart'; |
| 206 String pathname = normalizePath(filename); |
| 207 String goodText = r''' |
| 208 main() { |
| 209 print("Hello, world!"); |
| 210 }'''; |
| 211 String badText = goodText.replaceAll(';', ''); |
| 212 writeFile(filename, badText); |
| 213 setAnalysisRoots(['']); |
| 214 return analysisFinished.then((_) { |
| 215 // The contents on disk (badText) are missing a semicolon. |
| 216 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); |
| 217 var contentChange = { |
| 218 'content': goodText |
| 219 }; |
| 220 if (includeOffsetAndLengths) { |
| 221 contentChange['offset'] = goodText.indexOf(';'); |
| 222 contentChange['oldLength'] = 0; |
| 223 contentChange['newLength'] = 1; |
| 224 } |
| 225 return server.send(ANALYSIS_UPDATE_CONTENT, { |
| 226 'files': { |
| 227 pathname: contentChange |
| 228 } |
| 229 }); |
| 230 }).then((result) { |
| 231 expect(result, isNull); |
| 232 return analysisFinished; |
| 233 }).then((_) { |
| 234 // There should be no errors now because the contents on disk have been |
| 235 // overriden with goodText. |
| 236 expect(currentAnalysisErrors[pathname], isEmpty); |
| 237 return server.send(ANALYSIS_UPDATE_CONTENT, { |
| 238 'files': { |
| 239 pathname: { |
| 240 'content': null |
| 241 } |
| 242 } |
| 243 }); |
| 244 }).then((result) { |
| 245 expect(result, isNull); |
| 246 return analysisFinished; |
| 247 }).then((_) { |
| 248 // Now there should be errors again, because the contents on disk are no |
| 249 // longer overridden. |
| 250 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); |
| 251 }); |
| 252 } |
| 196 } | 253 } |
| 197 | 254 |
| 198 main() { | 255 main() { |
| 199 runReflectiveTests(AnalysisDomainIntegrationTest); | 256 runReflectiveTests(AnalysisDomainIntegrationTest); |
| 200 } | 257 } |
| OLD | NEW |