| 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_testing/reflective_tests.dart'; | 9 import 'package:analysis_testing/reflective_tests.dart'; |
| 10 import 'package:path/path.dart'; | 10 import 'package:path/path.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 num localVar = topLevelVar.length; | 30 num localVar = topLevelVar.length; |
| 31 topLevelVar.length = param; | 31 topLevelVar.length = param; |
| 32 topLevelVar.add(localVar); | 32 topLevelVar.add(localVar); |
| 33 } | 33 } |
| 34 | 34 |
| 35 main() { | 35 main() { |
| 36 func(35); | 36 func(35); |
| 37 } | 37 } |
| 38 '''; | 38 '''; |
| 39 writeFile(pathname, text); | 39 writeFile(pathname, text); |
| 40 standardAnalysisRoot(); | 40 standardAnalysisSetup(); |
| 41 | 41 |
| 42 testHover(String target, int length, List<String> descriptionRegexps, String | 42 testHover(String target, int length, List<String> descriptionRegexps, String |
| 43 kind, List<String> staticTypeRegexps, {bool isCore: false, String docReg
exp: | 43 kind, List<String> staticTypeRegexps, {bool isCore: false, String docReg
exp: |
| 44 null, bool isLiteral: false, List<String> parameterRegexps: | 44 null, bool isLiteral: false, List<String> parameterRegexps: |
| 45 null, propagatedType: null}) { | 45 null, propagatedType: null}) { |
| 46 int offset = text.indexOf(target); | 46 int offset = text.indexOf(target); |
| 47 return sendAnalysisGetHover(pathname, offset).then((result) { | 47 return sendAnalysisGetHover(pathname, offset).then((result) { |
| 48 expect(result['hovers'], hasLength(1)); | 48 expect(result['hovers'], hasLength(1)); |
| 49 var info = result['hovers'][0]; | 49 var info = result['hovers'][0]; |
| 50 expect(info['offset'], equals(offset)); | 50 expect(info['offset'], equals(offset)); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 131 } |
| 132 | 132 |
| 133 test_getHover_noInfo() { | 133 test_getHover_noInfo() { |
| 134 String pathname = sourcePath('test.dart'); | 134 String pathname = sourcePath('test.dart'); |
| 135 String text = r''' | 135 String text = r''' |
| 136 main() { | 136 main() { |
| 137 // no code | 137 // no code |
| 138 } | 138 } |
| 139 '''; | 139 '''; |
| 140 writeFile(pathname, text); | 140 writeFile(pathname, text); |
| 141 standardAnalysisRoot(); | 141 standardAnalysisSetup(); |
| 142 | 142 |
| 143 // 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 |
| 144 // 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 |
| 145 // 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. |
| 146 return analysisFinished.then((_) { | 146 return analysisFinished.then((_) { |
| 147 return sendAnalysisGetHover(pathname, text.indexOf('no code')).then( | 147 return sendAnalysisGetHover(pathname, text.indexOf('no code')).then( |
| 148 (result) { | 148 (result) { |
| 149 expect(result['hovers'], hasLength(0)); | 149 expect(result['hovers'], hasLength(0)); |
| 150 }); | 150 }); |
| 151 }); | 151 }); |
| 152 } | 152 } |
| 153 | 153 |
| 154 test_getErrors_before_analysis() { | 154 test_getErrors_before_analysis() { |
| 155 return getErrorsTest(false); | 155 return getErrorsTest(false); |
| 156 } | 156 } |
| 157 | 157 |
| 158 test_getErrors_after_analysis() { | 158 test_getErrors_after_analysis() { |
| 159 return getErrorsTest(true); | 159 return getErrorsTest(true); |
| 160 } | 160 } |
| 161 | 161 |
| 162 Future getErrorsTest(bool afterAnalysis) { | 162 Future getErrorsTest(bool afterAnalysis) { |
| 163 String pathname = sourcePath('test.dart'); | 163 String pathname = sourcePath('test.dart'); |
| 164 String text = r''' | 164 String text = r''' |
| 165 main() { | 165 main() { |
| 166 var x // parse error: missing ';' | 166 var x // parse error: missing ';' |
| 167 }'''; | 167 }'''; |
| 168 writeFile(pathname, text); | 168 writeFile(pathname, text); |
| 169 standardAnalysisRoot(); | 169 standardAnalysisSetup(); |
| 170 Future finishTest() { | 170 Future finishTest() { |
| 171 return sendAnalysisGetErrors(pathname).then((result) { | 171 return sendAnalysisGetErrors(pathname).then((result) { |
| 172 expect(result['errors'], equals(currentAnalysisErrors[pathname])); | 172 expect(result['errors'], equals(currentAnalysisErrors[pathname])); |
| 173 }); | 173 }); |
| 174 } | 174 } |
| 175 if (afterAnalysis) { | 175 if (afterAnalysis) { |
| 176 return analysisFinished.then((_) => finishTest()); | 176 return analysisFinished.then((_) => finishTest()); |
| 177 } else { | 177 } else { |
| 178 return finishTest(); | 178 return finishTest(); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 test_updateContent_content_only() { | 182 test_updateContent_content_only() { |
| 183 return updateContentTest(false); | 183 return updateContentTest(false); |
| 184 } | 184 } |
| 185 | 185 |
| 186 test_updateContent_including_offset_and_lengths() { | 186 test_updateContent_including_offset_and_lengths() { |
| 187 return updateContentTest(true); | 187 return updateContentTest(true); |
| 188 } | 188 } |
| 189 | 189 |
| 190 Future updateContentTest(bool includeOffsetAndLengths) { | 190 Future updateContentTest(bool includeOffsetAndLengths) { |
| 191 String pathname = sourcePath('test.dart'); | 191 String pathname = sourcePath('test.dart'); |
| 192 String goodText = r''' | 192 String goodText = r''' |
| 193 main() { | 193 main() { |
| 194 print("Hello, world!"); | 194 print("Hello, world!"); |
| 195 }'''; | 195 }'''; |
| 196 String badText = goodText.replaceAll(';', ''); | 196 String badText = goodText.replaceAll(';', ''); |
| 197 writeFile(pathname, badText); | 197 writeFile(pathname, badText); |
| 198 standardAnalysisRoot(); | 198 standardAnalysisSetup(); |
| 199 return analysisFinished.then((_) { | 199 return analysisFinished.then((_) { |
| 200 // The contents on disk (badText) are missing a semicolon. | 200 // The contents on disk (badText) are missing a semicolon. |
| 201 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); | 201 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); |
| 202 | 202 |
| 203 if (includeOffsetAndLengths) { | 203 if (includeOffsetAndLengths) { |
| 204 // Before we send a ChangeContentOverlay directive we need to send an | 204 // Before we send a ChangeContentOverlay directive we need to send an |
| 205 // AddContentOverlay directive. So send that with badText. | 205 // AddContentOverlay directive. So send that with badText. |
| 206 return sendAnalysisUpdateContent({ | 206 return sendAnalysisUpdateContent({ |
| 207 pathname: { | 207 pathname: { |
| 208 'type': 'add', | 208 'type': 'add', |
| (...skipping 16 matching lines...) Expand all Loading... |
| 225 pathname: { | 225 pathname: { |
| 226 'type': 'add', | 226 'type': 'add', |
| 227 'content': goodText | 227 'content': goodText |
| 228 } | 228 } |
| 229 }); | 229 }); |
| 230 } | 230 } |
| 231 }).then((result) => analysisFinished).then((_) { | 231 }).then((result) => analysisFinished).then((_) { |
| 232 // There should be no errors now because the contents on disk have been | 232 // There should be no errors now because the contents on disk have been |
| 233 // overriden with goodText. | 233 // overriden with goodText. |
| 234 expect(currentAnalysisErrors[pathname], isEmpty); | 234 expect(currentAnalysisErrors[pathname], isEmpty); |
| 235 // TODO(paulberry): passing "checkTypes: false" to work around the fact | |
| 236 // that isContentChange doesn't permit 'content' to be null. | |
| 237 return sendAnalysisUpdateContent({ | 235 return sendAnalysisUpdateContent({ |
| 238 pathname: { | 236 pathname: { |
| 239 'type': 'remove' | 237 'type': 'remove' |
| 240 } | 238 } |
| 241 }); | 239 }); |
| 242 }).then((result) => analysisFinished).then((_) { | 240 }).then((result) => analysisFinished).then((_) { |
| 243 // Now there should be errors again, because the contents on disk are no | 241 // Now there should be errors again, because the contents on disk are no |
| 244 // longer overridden. | 242 // longer overridden. |
| 245 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); | 243 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); |
| 246 }); | 244 }); |
| 247 } | 245 } |
| 248 } | 246 } |
| 249 | 247 |
| 250 main() { | 248 main() { |
| 251 runReflectiveTests(AnalysisDomainIntegrationTest); | 249 runReflectiveTests(AnalysisDomainIntegrationTest); |
| 252 } | 250 } |
| OLD | NEW |