Chromium Code Reviews| 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 analyzer.test.generated.all_the_rest_test; | 5 library analyzer.test.generated.all_the_rest_test; |
| 6 | 6 |
| 7 import 'dart:async'; | |
| 8 | |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 12 import 'package:analyzer/dart/element/type.dart'; |
| 11 import 'package:analyzer/error/error.dart'; | 13 import 'package:analyzer/error/error.dart'; |
| 12 import 'package:analyzer/error/listener.dart'; | 14 import 'package:analyzer/error/listener.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 15 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/file_system/memory_file_system.dart'; | 16 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 15 import 'package:analyzer/file_system/physical_file_system.dart'; | 17 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 16 import 'package:analyzer/src/dart/ast/utilities.dart' hide ConstantEvaluator; | 18 import 'package:analyzer/src/dart/ast/utilities.dart' hide ConstantEvaluator; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 resourceProvider.pathContext | 88 resourceProvider.pathContext |
| 87 .join(sdkFolderName, 'lib', 'core', 'core.dart'), | 89 .join(sdkFolderName, 'lib', 'core', 'core.dart'), |
| 88 ''' | 90 ''' |
| 89 library dart.core; | 91 library dart.core; |
| 90 '''); | 92 '''); |
| 91 return new FolderBasedDartSdk(resourceProvider, sdkFolder); | 93 return new FolderBasedDartSdk(resourceProvider, sdkFolder); |
| 92 } | 94 } |
| 93 | 95 |
| 94 @reflectiveTest | 96 @reflectiveTest |
| 95 class ContentCacheTest { | 97 class ContentCacheTest { |
| 96 void test_setContents() { | 98 test_setContents() async { |
|
Brian Wilkerson
2017/01/10 18:02:39
Not sure there's value in making methods async if
| |
| 97 Source source = new TestSource(); | 99 Source source = new TestSource(); |
| 98 ContentCache cache = new ContentCache(); | 100 ContentCache cache = new ContentCache(); |
| 99 expect(cache.getContents(source), isNull); | 101 expect(cache.getContents(source), isNull); |
| 100 expect(cache.getModificationStamp(source), isNull); | 102 expect(cache.getModificationStamp(source), isNull); |
| 101 String contents = "library lib;"; | 103 String contents = "library lib;"; |
| 102 expect(cache.setContents(source, contents), isNull); | 104 expect(cache.setContents(source, contents), isNull); |
| 103 expect(cache.getContents(source), contents); | 105 expect(cache.getContents(source), contents); |
| 104 expect(cache.getModificationStamp(source), isNotNull); | 106 expect(cache.getModificationStamp(source), isNotNull); |
| 105 expect(cache.setContents(source, contents), contents); | 107 expect(cache.setContents(source, contents), contents); |
| 106 expect(cache.setContents(source, null), contents); | 108 expect(cache.setContents(source, null), contents); |
| 107 expect(cache.getContents(source), isNull); | 109 expect(cache.getContents(source), isNull); |
| 108 expect(cache.getModificationStamp(source), isNull); | 110 expect(cache.getModificationStamp(source), isNull); |
| 109 expect(cache.setContents(source, null), isNull); | 111 expect(cache.setContents(source, null), isNull); |
| 110 } | 112 } |
| 111 } | 113 } |
| 112 | 114 |
| 113 @deprecated | 115 @deprecated |
| 114 @reflectiveTest | 116 @reflectiveTest |
| 115 class CustomUriResolverTest { | 117 class CustomUriResolverTest { |
| 116 void test_creation() { | 118 test_creation() async { |
| 117 expect(new CustomUriResolver({}), isNotNull); | 119 expect(new CustomUriResolver({}), isNotNull); |
| 118 } | 120 } |
| 119 | 121 |
| 120 void test_resolve_unknown_uri() { | 122 test_resolve_unknown_uri() async { |
| 121 UriResolver resolver = new CustomUriResolver({ | 123 UriResolver resolver = new CustomUriResolver({ |
| 122 'custom:library': '/path/to/library.dart', | 124 'custom:library': '/path/to/library.dart', |
| 123 }); | 125 }); |
| 124 Source result = resolver.resolveAbsolute(Uri.parse("custom:non_library")); | 126 Source result = resolver.resolveAbsolute(Uri.parse("custom:non_library")); |
| 125 expect(result, isNull); | 127 expect(result, isNull); |
| 126 } | 128 } |
| 127 | 129 |
| 128 void test_resolve_uri() { | 130 test_resolve_uri() async { |
| 129 String filePath = | 131 String filePath = |
| 130 FileUtilities2.createFile("/path/to/library.dart").getAbsolutePath(); | 132 FileUtilities2.createFile("/path/to/library.dart").getAbsolutePath(); |
| 131 UriResolver resolver = new CustomUriResolver({ | 133 UriResolver resolver = new CustomUriResolver({ |
| 132 'custom:library': filePath, | 134 'custom:library': filePath, |
| 133 }); | 135 }); |
| 134 Source result = resolver.resolveAbsolute(Uri.parse("custom:library")); | 136 Source result = resolver.resolveAbsolute(Uri.parse("custom:library")); |
| 135 expect(result, isNotNull); | 137 expect(result, isNotNull); |
| 136 expect(result.fullName, filePath); | 138 expect(result.fullName, filePath); |
| 137 } | 139 } |
| 138 } | 140 } |
| 139 | 141 |
| 140 @reflectiveTest | 142 @reflectiveTest |
| 141 class DartUriResolverTest { | 143 class DartUriResolverTest { |
| 142 void test_creation() { | 144 test_creation() async { |
| 143 DartSdk sdk = _createSdk(); | 145 DartSdk sdk = _createSdk(); |
| 144 expect(new DartUriResolver(sdk), isNotNull); | 146 expect(new DartUriResolver(sdk), isNotNull); |
| 145 } | 147 } |
| 146 | 148 |
| 147 void test_isDartUri_null_scheme() { | 149 test_isDartUri_null_scheme() async { |
| 148 Uri uri = Uri.parse("foo.dart"); | 150 Uri uri = Uri.parse("foo.dart"); |
| 149 expect('', uri.scheme); | 151 expect('', uri.scheme); |
| 150 expect(DartUriResolver.isDartUri(uri), isFalse); | 152 expect(DartUriResolver.isDartUri(uri), isFalse); |
| 151 } | 153 } |
| 152 | 154 |
| 153 void test_resolve_dart() { | 155 test_resolve_dart() async { |
| 154 DartSdk sdk = _createSdk(); | 156 DartSdk sdk = _createSdk(); |
| 155 UriResolver resolver = new DartUriResolver(sdk); | 157 UriResolver resolver = new DartUriResolver(sdk); |
| 156 Source result = resolver.resolveAbsolute(Uri.parse("dart:core")); | 158 Source result = resolver.resolveAbsolute(Uri.parse("dart:core")); |
| 157 expect(result, isNotNull); | 159 expect(result, isNotNull); |
| 158 } | 160 } |
| 159 | 161 |
| 160 void test_resolve_dart_nonExistingLibrary() { | 162 test_resolve_dart_nonExistingLibrary() async { |
| 161 DartSdk sdk = _createSdk(); | 163 DartSdk sdk = _createSdk(); |
| 162 UriResolver resolver = new DartUriResolver(sdk); | 164 UriResolver resolver = new DartUriResolver(sdk); |
| 163 Source result = resolver.resolveAbsolute(Uri.parse("dart:cor")); | 165 Source result = resolver.resolveAbsolute(Uri.parse("dart:cor")); |
| 164 expect(result, isNull); | 166 expect(result, isNull); |
| 165 } | 167 } |
| 166 | 168 |
| 167 void test_resolve_nonDart() { | 169 test_resolve_nonDart() async { |
| 168 DartSdk sdk = _createSdk(); | 170 DartSdk sdk = _createSdk(); |
| 169 UriResolver resolver = new DartUriResolver(sdk); | 171 UriResolver resolver = new DartUriResolver(sdk); |
| 170 Source result = | 172 Source result = |
| 171 resolver.resolveAbsolute(Uri.parse("package:some/file.dart")); | 173 resolver.resolveAbsolute(Uri.parse("package:some/file.dart")); |
| 172 expect(result, isNull); | 174 expect(result, isNull); |
| 173 } | 175 } |
| 174 } | 176 } |
| 175 | 177 |
| 176 @deprecated | 178 @deprecated |
| 177 @reflectiveTest | 179 @reflectiveTest |
| 178 class DirectoryBasedDartSdkTest { | 180 class DirectoryBasedDartSdkTest { |
| 179 void fail_getDocFileFor() { | 181 void fail_getDocFileFor() { |
| 180 DirectoryBasedDartSdk sdk = _createDartSdk(); | 182 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 181 JavaFile docFile = sdk.getDocFileFor("html"); | 183 JavaFile docFile = sdk.getDocFileFor("html"); |
| 182 expect(docFile, isNotNull); | 184 expect(docFile, isNotNull); |
| 183 } | 185 } |
| 184 | 186 |
| 185 void test_analysisOptions_afterContextCreation() { | 187 test_analysisOptions_afterContextCreation() async { |
| 186 DirectoryBasedDartSdk sdk = _createDartSdk(); | 188 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 187 sdk.context; | 189 sdk.context; |
| 188 expect(() { | 190 expect(() { |
| 189 sdk.analysisOptions = new AnalysisOptionsImpl(); | 191 sdk.analysisOptions = new AnalysisOptionsImpl(); |
| 190 }, throwsStateError); | 192 }, throwsStateError); |
| 191 } | 193 } |
| 192 | 194 |
| 193 void test_analysisOptions_beforeContextCreation() { | 195 test_analysisOptions_beforeContextCreation() async { |
| 194 DirectoryBasedDartSdk sdk = _createDartSdk(); | 196 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 195 sdk.analysisOptions = new AnalysisOptionsImpl(); | 197 sdk.analysisOptions = new AnalysisOptionsImpl(); |
| 196 sdk.context; | 198 sdk.context; |
| 197 // cannot change "analysisOptions" in the context | 199 // cannot change "analysisOptions" in the context |
| 198 expect(() { | 200 expect(() { |
| 199 sdk.context.analysisOptions = new AnalysisOptionsImpl(); | 201 sdk.context.analysisOptions = new AnalysisOptionsImpl(); |
| 200 }, throwsStateError); | 202 }, throwsStateError); |
| 201 } | 203 } |
| 202 | 204 |
| 203 void test_creation() { | 205 test_creation() async { |
| 204 DirectoryBasedDartSdk sdk = _createDartSdk(); | 206 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 205 expect(sdk, isNotNull); | 207 expect(sdk, isNotNull); |
| 206 } | 208 } |
| 207 | 209 |
| 208 void test_fromFile_invalid() { | 210 test_fromFile_invalid() async { |
| 209 DirectoryBasedDartSdk sdk = _createDartSdk(); | 211 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 210 expect( | 212 expect( |
| 211 sdk.fromFileUri(new JavaFile("/not/in/the/sdk.dart").toURI()), isNull); | 213 sdk.fromFileUri(new JavaFile("/not/in/the/sdk.dart").toURI()), isNull); |
| 212 } | 214 } |
| 213 | 215 |
| 214 void test_fromFile_library() { | 216 test_fromFile_library() async { |
| 215 DirectoryBasedDartSdk sdk = _createDartSdk(); | 217 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 216 Source source = sdk.fromFileUri(new JavaFile.relative( | 218 Source source = sdk.fromFileUri(new JavaFile.relative( |
| 217 new JavaFile.relative(sdk.libraryDirectory, "core"), "core.dart") | 219 new JavaFile.relative(sdk.libraryDirectory, "core"), "core.dart") |
| 218 .toURI()); | 220 .toURI()); |
| 219 expect(source, isNotNull); | 221 expect(source, isNotNull); |
| 220 expect(source.isInSystemLibrary, isTrue); | 222 expect(source.isInSystemLibrary, isTrue); |
| 221 expect(source.uri.toString(), "dart:core"); | 223 expect(source.uri.toString(), "dart:core"); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void test_fromFile_library_firstExact() { | 226 test_fromFile_library_firstExact() async { |
| 225 DirectoryBasedDartSdk sdk = _createDartSdk(); | 227 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 226 JavaFile dirHtml = new JavaFile.relative(sdk.libraryDirectory, "html"); | 228 JavaFile dirHtml = new JavaFile.relative(sdk.libraryDirectory, "html"); |
| 227 JavaFile dirDartium = new JavaFile.relative(dirHtml, "dartium"); | 229 JavaFile dirDartium = new JavaFile.relative(dirHtml, "dartium"); |
| 228 JavaFile file = new JavaFile.relative(dirDartium, "html_dartium.dart"); | 230 JavaFile file = new JavaFile.relative(dirDartium, "html_dartium.dart"); |
| 229 expect(file.isFile(), isTrue); | 231 expect(file.isFile(), isTrue); |
| 230 Source source = sdk.fromFileUri(file.toURI()); | 232 Source source = sdk.fromFileUri(file.toURI()); |
| 231 expect(source, isNotNull); | 233 expect(source, isNotNull); |
| 232 expect(source.isInSystemLibrary, isTrue); | 234 expect(source.isInSystemLibrary, isTrue); |
| 233 expect(source.uri.toString(), "dart:html"); | 235 expect(source.uri.toString(), "dart:html"); |
| 234 } | 236 } |
| 235 | 237 |
| 236 void test_fromFile_library_html_common_dart2js() { | 238 test_fromFile_library_html_common_dart2js() async { |
| 237 DirectoryBasedDartSdk sdk = _createDartSdk(); | 239 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 238 JavaFile dirHtml = new JavaFile.relative(sdk.libraryDirectory, "html"); | 240 JavaFile dirHtml = new JavaFile.relative(sdk.libraryDirectory, "html"); |
| 239 JavaFile dirCommon = new JavaFile.relative(dirHtml, "html_common"); | 241 JavaFile dirCommon = new JavaFile.relative(dirHtml, "html_common"); |
| 240 JavaFile file = | 242 JavaFile file = |
| 241 new JavaFile.relative(dirCommon, "html_common_dart2js.dart"); | 243 new JavaFile.relative(dirCommon, "html_common_dart2js.dart"); |
| 242 expect(file.isFile(), isTrue); | 244 expect(file.isFile(), isTrue); |
| 243 Source source = sdk.fromFileUri(file.toURI()); | 245 Source source = sdk.fromFileUri(file.toURI()); |
| 244 expect(source, isNotNull); | 246 expect(source, isNotNull); |
| 245 expect(source.isInSystemLibrary, isTrue); | 247 expect(source.isInSystemLibrary, isTrue); |
| 246 expect(source.uri.toString(), "dart:html_common/html_common_dart2js.dart"); | 248 expect(source.uri.toString(), "dart:html_common/html_common_dart2js.dart"); |
| 247 } | 249 } |
| 248 | 250 |
| 249 void test_fromFile_part() { | 251 test_fromFile_part() async { |
| 250 DirectoryBasedDartSdk sdk = _createDartSdk(); | 252 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 251 Source source = sdk.fromFileUri(new JavaFile.relative( | 253 Source source = sdk.fromFileUri(new JavaFile.relative( |
| 252 new JavaFile.relative(sdk.libraryDirectory, "core"), "num.dart") | 254 new JavaFile.relative(sdk.libraryDirectory, "core"), "num.dart") |
| 253 .toURI()); | 255 .toURI()); |
| 254 expect(source, isNotNull); | 256 expect(source, isNotNull); |
| 255 expect(source.isInSystemLibrary, isTrue); | 257 expect(source.isInSystemLibrary, isTrue); |
| 256 expect(source.uri.toString(), "dart:core/num.dart"); | 258 expect(source.uri.toString(), "dart:core/num.dart"); |
| 257 } | 259 } |
| 258 | 260 |
| 259 void test_getDart2JsExecutable() { | 261 test_getDart2JsExecutable() async { |
| 260 DirectoryBasedDartSdk sdk = _createDartSdk(); | 262 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 261 JavaFile executable = sdk.dart2JsExecutable; | 263 JavaFile executable = sdk.dart2JsExecutable; |
| 262 expect(executable, isNotNull); | 264 expect(executable, isNotNull); |
| 263 expect(executable.exists(), isTrue); | 265 expect(executable.exists(), isTrue); |
| 264 expect(executable.isExecutable(), isTrue); | 266 expect(executable.isExecutable(), isTrue); |
| 265 } | 267 } |
| 266 | 268 |
| 267 void test_getDirectory() { | 269 test_getDirectory() async { |
| 268 DirectoryBasedDartSdk sdk = _createDartSdk(); | 270 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 269 JavaFile directory = sdk.directory; | 271 JavaFile directory = sdk.directory; |
| 270 expect(directory, isNotNull); | 272 expect(directory, isNotNull); |
| 271 expect(directory.exists(), isTrue); | 273 expect(directory.exists(), isTrue); |
| 272 } | 274 } |
| 273 | 275 |
| 274 void test_getDocDirectory() { | 276 test_getDocDirectory() async { |
| 275 DirectoryBasedDartSdk sdk = _createDartSdk(); | 277 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 276 JavaFile directory = sdk.docDirectory; | 278 JavaFile directory = sdk.docDirectory; |
| 277 expect(directory, isNotNull); | 279 expect(directory, isNotNull); |
| 278 } | 280 } |
| 279 | 281 |
| 280 void test_getLibraryDirectory() { | 282 test_getLibraryDirectory() async { |
| 281 DirectoryBasedDartSdk sdk = _createDartSdk(); | 283 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 282 JavaFile directory = sdk.libraryDirectory; | 284 JavaFile directory = sdk.libraryDirectory; |
| 283 expect(directory, isNotNull); | 285 expect(directory, isNotNull); |
| 284 expect(directory.exists(), isTrue); | 286 expect(directory.exists(), isTrue); |
| 285 } | 287 } |
| 286 | 288 |
| 287 void test_getPubExecutable() { | 289 test_getPubExecutable() async { |
| 288 DirectoryBasedDartSdk sdk = _createDartSdk(); | 290 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 289 JavaFile executable = sdk.pubExecutable; | 291 JavaFile executable = sdk.pubExecutable; |
| 290 expect(executable, isNotNull); | 292 expect(executable, isNotNull); |
| 291 expect(executable.exists(), isTrue); | 293 expect(executable.exists(), isTrue); |
| 292 expect(executable.isExecutable(), isTrue); | 294 expect(executable.isExecutable(), isTrue); |
| 293 } | 295 } |
| 294 | 296 |
| 295 void test_getSdkVersion() { | 297 test_getSdkVersion() async { |
| 296 DirectoryBasedDartSdk sdk = _createDartSdk(); | 298 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 297 String version = sdk.sdkVersion; | 299 String version = sdk.sdkVersion; |
| 298 expect(version, isNotNull); | 300 expect(version, isNotNull); |
| 299 expect(version.length > 0, isTrue); | 301 expect(version.length > 0, isTrue); |
| 300 } | 302 } |
| 301 | 303 |
| 302 void test_getVmExecutable() { | 304 test_getVmExecutable() async { |
| 303 DirectoryBasedDartSdk sdk = _createDartSdk(); | 305 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 304 JavaFile executable = sdk.vmExecutable; | 306 JavaFile executable = sdk.vmExecutable; |
| 305 expect(executable, isNotNull); | 307 expect(executable, isNotNull); |
| 306 expect(executable.exists(), isTrue); | 308 expect(executable.exists(), isTrue); |
| 307 expect(executable.isExecutable(), isTrue); | 309 expect(executable.isExecutable(), isTrue); |
| 308 } | 310 } |
| 309 | 311 |
| 310 void test_useSummary_afterContextCreation() { | 312 test_useSummary_afterContextCreation() async { |
| 311 DirectoryBasedDartSdk sdk = _createDartSdk(); | 313 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 312 sdk.context; | 314 sdk.context; |
| 313 expect(() { | 315 expect(() { |
| 314 sdk.useSummary = true; | 316 sdk.useSummary = true; |
| 315 }, throwsStateError); | 317 }, throwsStateError); |
| 316 } | 318 } |
| 317 | 319 |
| 318 void test_useSummary_beforeContextCreation() { | 320 test_useSummary_beforeContextCreation() async { |
| 319 DirectoryBasedDartSdk sdk = _createDartSdk(); | 321 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 320 sdk.useSummary = true; | 322 sdk.useSummary = true; |
| 321 sdk.context; | 323 sdk.context; |
| 322 } | 324 } |
| 323 | 325 |
| 324 DirectoryBasedDartSdk _createDartSdk() { | 326 DirectoryBasedDartSdk _createDartSdk() { |
| 325 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; | 327 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; |
| 326 expect(sdkDirectory, isNotNull, | 328 expect(sdkDirectory, isNotNull, |
| 327 reason: | 329 reason: |
| 328 "No SDK configured; set the property 'com.google.dart.sdk' on the co mmand line"); | 330 "No SDK configured; set the property 'com.google.dart.sdk' on the co mmand line"); |
| 329 return new DirectoryBasedDartSdk(sdkDirectory); | 331 return new DirectoryBasedDartSdk(sdkDirectory); |
| 330 } | 332 } |
| 331 } | 333 } |
| 332 | 334 |
| 333 @deprecated | 335 @deprecated |
| 334 @reflectiveTest | 336 @reflectiveTest |
| 335 class DirectoryBasedSourceContainerTest { | 337 class DirectoryBasedSourceContainerTest { |
| 336 void test_contains() { | 338 test_contains() async { |
| 337 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | 339 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 338 File file1 = resourceProvider.getFile('/does/not/exist/some.dart'); | 340 File file1 = resourceProvider.getFile('/does/not/exist/some.dart'); |
| 339 File file2 = resourceProvider.getFile('/does/not/exist/folder/some2.dart'); | 341 File file2 = resourceProvider.getFile('/does/not/exist/folder/some2.dart'); |
| 340 File file3 = resourceProvider.getFile('/does/not/exist3/some3.dart'); | 342 File file3 = resourceProvider.getFile('/does/not/exist3/some3.dart'); |
| 341 Source source1 = new FileSource(file1); | 343 Source source1 = new FileSource(file1); |
| 342 Source source2 = new FileSource(file2); | 344 Source source2 = new FileSource(file2); |
| 343 Source source3 = new FileSource(file3); | 345 Source source3 = new FileSource(file3); |
| 344 DirectoryBasedSourceContainer container = | 346 DirectoryBasedSourceContainer container = |
| 345 new DirectoryBasedSourceContainer.con2('/does/not/exist'); | 347 new DirectoryBasedSourceContainer.con2('/does/not/exist'); |
| 346 expect(container.contains(source1), isTrue); | 348 expect(container.contains(source1), isTrue); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 359 fail("Test this case"); | 361 fail("Test this case"); |
| 360 } | 362 } |
| 361 | 363 |
| 362 @override | 364 @override |
| 363 void reset() { | 365 void reset() { |
| 364 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 366 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 365 analysisOptions.hint = false; | 367 analysisOptions.hint = false; |
| 366 resetWithOptions(analysisOptions); | 368 resetWithOptions(analysisOptions); |
| 367 } | 369 } |
| 368 | 370 |
| 369 void test_locate_AssignmentExpression() { | 371 test_locate_AssignmentExpression() async { |
| 370 AstNode id = _findNodeIn( | 372 AstNode id = await _findNodeIn( |
| 371 "+=", | 373 "+=", |
| 372 r''' | 374 r''' |
| 373 int x = 0; | 375 int x = 0; |
| 374 void main() { | 376 void main() { |
| 375 x += 1; | 377 x += 1; |
| 376 }'''); | 378 }'''); |
| 377 Element element = ElementLocator.locate(id); | 379 Element element = ElementLocator.locate(id); |
| 378 EngineTestCase.assertInstanceOf( | 380 EngineTestCase.assertInstanceOf( |
| 379 (obj) => obj is MethodElement, MethodElement, element); | 381 (obj) => obj is MethodElement, MethodElement, element); |
| 380 } | 382 } |
| 381 | 383 |
| 382 void test_locate_BinaryExpression() { | 384 test_locate_BinaryExpression() async { |
| 383 AstNode id = _findNodeIn("+", "var x = 3 + 4;"); | 385 AstNode id = await _findNodeIn("+", "var x = 3 + 4;"); |
| 384 Element element = ElementLocator.locate(id); | 386 Element element = ElementLocator.locate(id); |
| 385 EngineTestCase.assertInstanceOf( | 387 EngineTestCase.assertInstanceOf( |
| 386 (obj) => obj is MethodElement, MethodElement, element); | 388 (obj) => obj is MethodElement, MethodElement, element); |
| 387 } | 389 } |
| 388 | 390 |
| 389 void test_locate_ClassDeclaration() { | 391 test_locate_ClassDeclaration() async { |
| 390 AstNode id = _findNodeIn("class", "class A { }"); | 392 AstNode id = await _findNodeIn("class", "class A { }"); |
| 391 Element element = ElementLocator.locate(id); | 393 Element element = ElementLocator.locate(id); |
| 392 EngineTestCase.assertInstanceOf( | 394 EngineTestCase.assertInstanceOf( |
| 393 (obj) => obj is ClassElement, ClassElement, element); | 395 (obj) => obj is ClassElement, ClassElement, element); |
| 394 } | 396 } |
| 395 | 397 |
| 396 void test_locate_CompilationUnit() { | 398 test_locate_CompilationUnit() async { |
| 397 CompilationUnit cu = _resolveContents("// only comment"); | 399 CompilationUnit cu = await _resolveContents("// only comment"); |
| 398 expect(cu.element, isNotNull); | 400 expect(cu.element, isNotNull); |
| 399 Element element = ElementLocator.locate(cu); | 401 Element element = ElementLocator.locate(cu); |
| 400 expect(element, same(cu.element)); | 402 expect(element, same(cu.element)); |
| 401 } | 403 } |
| 402 | 404 |
| 403 void test_locate_ConstructorDeclaration() { | 405 test_locate_ConstructorDeclaration() async { |
| 404 AstNode id = _findNodeIndexedIn( | 406 AstNode id = await _findNodeIndexedIn( |
| 405 "bar", | 407 "bar", |
| 406 0, | 408 0, |
| 407 r''' | 409 r''' |
| 408 class A { | 410 class A { |
| 409 A.bar() {} | 411 A.bar() {} |
| 410 }'''); | 412 }'''); |
| 411 ConstructorDeclaration declaration = | 413 ConstructorDeclaration declaration = |
| 412 id.getAncestor((node) => node is ConstructorDeclaration); | 414 id.getAncestor((node) => node is ConstructorDeclaration); |
| 413 Element element = ElementLocator.locate(declaration); | 415 Element element = ElementLocator.locate(declaration); |
| 414 EngineTestCase.assertInstanceOf( | 416 EngineTestCase.assertInstanceOf( |
| 415 (obj) => obj is ConstructorElement, ConstructorElement, element); | 417 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 416 } | 418 } |
| 417 | 419 |
| 418 void test_locate_ExportDirective() { | 420 test_locate_ExportDirective() async { |
| 419 AstNode id = _findNodeIn("export", "export 'dart:core';"); | 421 AstNode id = await _findNodeIn("export", "export 'dart:core';"); |
| 420 Element element = ElementLocator.locate(id); | 422 Element element = ElementLocator.locate(id); |
| 421 EngineTestCase.assertInstanceOf( | 423 EngineTestCase.assertInstanceOf( |
| 422 (obj) => obj is ExportElement, ExportElement, element); | 424 (obj) => obj is ExportElement, ExportElement, element); |
| 423 } | 425 } |
| 424 | 426 |
| 425 void test_locate_FunctionDeclaration() { | 427 test_locate_FunctionDeclaration() async { |
| 426 AstNode id = _findNodeIn("f", "int f() => 3;"); | 428 AstNode id = await _findNodeIn("f", "int f() => 3;"); |
| 427 FunctionDeclaration declaration = | 429 FunctionDeclaration declaration = |
| 428 id.getAncestor((node) => node is FunctionDeclaration); | 430 id.getAncestor((node) => node is FunctionDeclaration); |
| 429 Element element = ElementLocator.locate(declaration); | 431 Element element = ElementLocator.locate(declaration); |
| 430 EngineTestCase.assertInstanceOf( | 432 EngineTestCase.assertInstanceOf( |
| 431 (obj) => obj is FunctionElement, FunctionElement, element); | 433 (obj) => obj is FunctionElement, FunctionElement, element); |
| 432 } | 434 } |
| 433 | 435 |
| 434 void | 436 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalParamet er() async { |
| 435 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPar ameter() { | 437 AstNode id = await _findNodeIndexedIn( |
| 436 AstNode id = _findNodeIndexedIn( | |
| 437 "Class", | 438 "Class", |
| 438 2, | 439 2, |
| 439 r''' | 440 r''' |
| 440 class Class { | 441 class Class { |
| 441 const Class.name(); | 442 const Class.name(); |
| 442 } | 443 } |
| 443 void main(@Class.name() parameter) { | 444 void main(@Class.name() parameter) { |
| 444 }'''); | 445 }'''); |
| 445 Element element = ElementLocator.locate(id); | 446 Element element = ElementLocator.locate(id); |
| 446 EngineTestCase.assertInstanceOf( | 447 EngineTestCase.assertInstanceOf( |
| 447 (obj) => obj is ClassElement, ClassElement, element); | 448 (obj) => obj is ClassElement, ClassElement, element); |
| 448 } | 449 } |
| 449 | 450 |
| 450 void | 451 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalParam eter() async { |
| 451 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalP arameter() { | 452 AstNode id = await _findNodeIndexedIn( |
| 452 AstNode id = _findNodeIndexedIn( | |
| 453 "Class", | 453 "Class", |
| 454 2, | 454 2, |
| 455 r''' | 455 r''' |
| 456 class Class { | 456 class Class { |
| 457 const Class(); | 457 const Class(); |
| 458 } | 458 } |
| 459 void main(@Class() parameter) { | 459 void main(@Class() parameter) { |
| 460 }'''); | 460 }'''); |
| 461 Element element = ElementLocator.locate(id); | 461 Element element = ElementLocator.locate(id); |
| 462 EngineTestCase.assertInstanceOf( | 462 EngineTestCase.assertInstanceOf( |
| 463 (obj) => obj is ConstructorElement, ConstructorElement, element); | 463 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 464 } | 464 } |
| 465 | 465 |
| 466 void test_locate_Identifier_className() { | 466 test_locate_Identifier_className() async { |
| 467 AstNode id = _findNodeIn("A", "class A { }"); | 467 AstNode id = await _findNodeIn("A", "class A { }"); |
| 468 Element element = ElementLocator.locate(id); | 468 Element element = ElementLocator.locate(id); |
| 469 EngineTestCase.assertInstanceOf( | 469 EngineTestCase.assertInstanceOf( |
| 470 (obj) => obj is ClassElement, ClassElement, element); | 470 (obj) => obj is ClassElement, ClassElement, element); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void test_locate_Identifier_constructor_named() { | 473 test_locate_Identifier_constructor_named() async { |
| 474 AstNode id = _findNodeIndexedIn( | 474 AstNode id = await _findNodeIndexedIn( |
| 475 "bar", | 475 "bar", |
| 476 0, | 476 0, |
| 477 r''' | 477 r''' |
| 478 class A { | 478 class A { |
| 479 A.bar() {} | 479 A.bar() {} |
| 480 }'''); | 480 }'''); |
| 481 Element element = ElementLocator.locate(id); | 481 Element element = ElementLocator.locate(id); |
| 482 EngineTestCase.assertInstanceOf( | 482 EngineTestCase.assertInstanceOf( |
| 483 (obj) => obj is ConstructorElement, ConstructorElement, element); | 483 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 484 } | 484 } |
| 485 | 485 |
| 486 void test_locate_Identifier_constructor_unnamed() { | 486 test_locate_Identifier_constructor_unnamed() async { |
| 487 AstNode id = _findNodeIndexedIn( | 487 AstNode id = await _findNodeIndexedIn( |
| 488 "A", | 488 "A", |
| 489 1, | 489 1, |
| 490 r''' | 490 r''' |
| 491 class A { | 491 class A { |
| 492 A() {} | 492 A() {} |
| 493 }'''); | 493 }'''); |
| 494 Element element = ElementLocator.locate(id); | 494 Element element = ElementLocator.locate(id); |
| 495 EngineTestCase.assertInstanceOf( | 495 EngineTestCase.assertInstanceOf( |
| 496 (obj) => obj is ConstructorElement, ConstructorElement, element); | 496 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 497 } | 497 } |
| 498 | 498 |
| 499 void test_locate_Identifier_fieldName() { | 499 test_locate_Identifier_fieldName() async { |
| 500 AstNode id = _findNodeIn("x", "class A { var x; }"); | 500 AstNode id = await _findNodeIn("x", "class A { var x; }"); |
| 501 Element element = ElementLocator.locate(id); | 501 Element element = ElementLocator.locate(id); |
| 502 EngineTestCase.assertInstanceOf( | 502 EngineTestCase.assertInstanceOf( |
| 503 (obj) => obj is FieldElement, FieldElement, element); | 503 (obj) => obj is FieldElement, FieldElement, element); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void test_locate_Identifier_libraryDirective() { | 506 test_locate_Identifier_libraryDirective() async { |
| 507 AstNode id = _findNodeIn("foo", "library foo.bar;"); | 507 AstNode id = await _findNodeIn("foo", "library foo.bar;"); |
| 508 Element element = ElementLocator.locate(id); | 508 Element element = ElementLocator.locate(id); |
| 509 EngineTestCase.assertInstanceOf( | 509 EngineTestCase.assertInstanceOf( |
| 510 (obj) => obj is LibraryElement, LibraryElement, element); | 510 (obj) => obj is LibraryElement, LibraryElement, element); |
| 511 } | 511 } |
| 512 | 512 |
| 513 void test_locate_Identifier_propertyAccess() { | 513 test_locate_Identifier_propertyAccess() async { |
| 514 AstNode id = _findNodeIn( | 514 AstNode id = await _findNodeIn( |
| 515 "length", | 515 "length", |
| 516 r''' | 516 r''' |
| 517 void main() { | 517 void main() { |
| 518 int x = 'foo'.length; | 518 int x = 'foo'.length; |
| 519 }'''); | 519 }'''); |
| 520 Element element = ElementLocator.locate(id); | 520 Element element = ElementLocator.locate(id); |
| 521 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, | 521 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, |
| 522 PropertyAccessorElement, element); | 522 PropertyAccessorElement, element); |
| 523 } | 523 } |
| 524 | 524 |
| 525 void test_locate_ImportDirective() { | 525 test_locate_ImportDirective() async { |
| 526 AstNode id = _findNodeIn("import", "import 'dart:core';"); | 526 AstNode id = await _findNodeIn("import", "import 'dart:core';"); |
| 527 Element element = ElementLocator.locate(id); | 527 Element element = ElementLocator.locate(id); |
| 528 EngineTestCase.assertInstanceOf( | 528 EngineTestCase.assertInstanceOf( |
| 529 (obj) => obj is ImportElement, ImportElement, element); | 529 (obj) => obj is ImportElement, ImportElement, element); |
| 530 } | 530 } |
| 531 | 531 |
| 532 void test_locate_IndexExpression() { | 532 test_locate_IndexExpression() async { |
| 533 AstNode id = _findNodeIndexedIn( | 533 AstNode id = await _findNodeIndexedIn( |
| 534 "\\[", | 534 "\\[", |
| 535 1, | 535 1, |
| 536 r''' | 536 r''' |
| 537 void main() { | 537 void main() { |
| 538 List x = [1, 2]; | 538 List x = [1, 2]; |
| 539 var y = x[0]; | 539 var y = x[0]; |
| 540 }'''); | 540 }'''); |
| 541 Element element = ElementLocator.locate(id); | 541 Element element = ElementLocator.locate(id); |
| 542 EngineTestCase.assertInstanceOf( | 542 EngineTestCase.assertInstanceOf( |
| 543 (obj) => obj is MethodElement, MethodElement, element); | 543 (obj) => obj is MethodElement, MethodElement, element); |
| 544 } | 544 } |
| 545 | 545 |
| 546 void test_locate_InstanceCreationExpression() { | 546 test_locate_InstanceCreationExpression() async { |
| 547 AstNode node = _findNodeIndexedIn( | 547 AstNode node = await _findNodeIndexedIn( |
| 548 "A(", | 548 "A(", |
| 549 0, | 549 0, |
| 550 r''' | 550 r''' |
| 551 class A {} | 551 class A {} |
| 552 void main() { | 552 void main() { |
| 553 new A(); | 553 new A(); |
| 554 }'''); | 554 }'''); |
| 555 Element element = ElementLocator.locate(node); | 555 Element element = ElementLocator.locate(node); |
| 556 EngineTestCase.assertInstanceOf( | 556 EngineTestCase.assertInstanceOf( |
| 557 (obj) => obj is ConstructorElement, ConstructorElement, element); | 557 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 558 } | 558 } |
| 559 | 559 |
| 560 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { | 560 test_locate_InstanceCreationExpression_type_prefixedIdentifier() async { |
| 561 // prepare: new pref.A() | 561 // prepare: new pref.A() |
| 562 SimpleIdentifier identifier = AstTestFactory.identifier3("A"); | 562 SimpleIdentifier identifier = AstTestFactory.identifier3("A"); |
| 563 PrefixedIdentifier prefixedIdentifier = | 563 PrefixedIdentifier prefixedIdentifier = |
| 564 AstTestFactory.identifier4("pref", identifier); | 564 AstTestFactory.identifier4("pref", identifier); |
| 565 InstanceCreationExpression creation = | 565 InstanceCreationExpression creation = |
| 566 AstTestFactory.instanceCreationExpression2( | 566 AstTestFactory.instanceCreationExpression2( |
| 567 Keyword.NEW, AstTestFactory.typeName3(prefixedIdentifier)); | 567 Keyword.NEW, AstTestFactory.typeName3(prefixedIdentifier)); |
| 568 // set ClassElement | 568 // set ClassElement |
| 569 ClassElement classElement = ElementFactory.classElement2("A"); | 569 ClassElement classElement = ElementFactory.classElement2("A"); |
| 570 identifier.staticElement = classElement; | 570 identifier.staticElement = classElement; |
| 571 // set ConstructorElement | 571 // set ConstructorElement |
| 572 ConstructorElement constructorElement = | 572 ConstructorElement constructorElement = |
| 573 ElementFactory.constructorElement2(classElement, null); | 573 ElementFactory.constructorElement2(classElement, null); |
| 574 creation.constructorName.staticElement = constructorElement; | 574 creation.constructorName.staticElement = constructorElement; |
| 575 // verify that "A" is resolved to ConstructorElement | 575 // verify that "A" is resolved to ConstructorElement |
| 576 Element element = ElementLocator.locate(identifier); | 576 Element element = ElementLocator.locate(identifier); |
| 577 expect(element, same(classElement)); | 577 expect(element, same(classElement)); |
| 578 } | 578 } |
| 579 | 579 |
| 580 void test_locate_InstanceCreationExpression_type_simpleIdentifier() { | 580 test_locate_InstanceCreationExpression_type_simpleIdentifier() async { |
| 581 // prepare: new A() | 581 // prepare: new A() |
| 582 SimpleIdentifier identifier = AstTestFactory.identifier3("A"); | 582 SimpleIdentifier identifier = AstTestFactory.identifier3("A"); |
| 583 InstanceCreationExpression creation = | 583 InstanceCreationExpression creation = |
| 584 AstTestFactory.instanceCreationExpression2( | 584 AstTestFactory.instanceCreationExpression2( |
| 585 Keyword.NEW, AstTestFactory.typeName3(identifier)); | 585 Keyword.NEW, AstTestFactory.typeName3(identifier)); |
| 586 // set ClassElement | 586 // set ClassElement |
| 587 ClassElement classElement = ElementFactory.classElement2("A"); | 587 ClassElement classElement = ElementFactory.classElement2("A"); |
| 588 identifier.staticElement = classElement; | 588 identifier.staticElement = classElement; |
| 589 // set ConstructorElement | 589 // set ConstructorElement |
| 590 ConstructorElement constructorElement = | 590 ConstructorElement constructorElement = |
| 591 ElementFactory.constructorElement2(classElement, null); | 591 ElementFactory.constructorElement2(classElement, null); |
| 592 creation.constructorName.staticElement = constructorElement; | 592 creation.constructorName.staticElement = constructorElement; |
| 593 // verify that "A" is resolved to ConstructorElement | 593 // verify that "A" is resolved to ConstructorElement |
| 594 Element element = ElementLocator.locate(identifier); | 594 Element element = ElementLocator.locate(identifier); |
| 595 expect(element, same(classElement)); | 595 expect(element, same(classElement)); |
| 596 } | 596 } |
| 597 | 597 |
| 598 void test_locate_LibraryDirective() { | 598 test_locate_LibraryDirective() async { |
| 599 AstNode id = _findNodeIn("library", "library foo;"); | 599 AstNode id = await _findNodeIn("library", "library foo;"); |
| 600 Element element = ElementLocator.locate(id); | 600 Element element = ElementLocator.locate(id); |
| 601 EngineTestCase.assertInstanceOf( | 601 EngineTestCase.assertInstanceOf( |
| 602 (obj) => obj is LibraryElement, LibraryElement, element); | 602 (obj) => obj is LibraryElement, LibraryElement, element); |
| 603 } | 603 } |
| 604 | 604 |
| 605 void test_locate_MethodDeclaration() { | 605 test_locate_MethodDeclaration() async { |
| 606 AstNode id = _findNodeIn( | 606 AstNode id = await _findNodeIn( |
| 607 "m", | 607 "m", |
| 608 r''' | 608 r''' |
| 609 class A { | 609 class A { |
| 610 void m() {} | 610 void m() {} |
| 611 }'''); | 611 }'''); |
| 612 MethodDeclaration declaration = | 612 MethodDeclaration declaration = |
| 613 id.getAncestor((node) => node is MethodDeclaration); | 613 id.getAncestor((node) => node is MethodDeclaration); |
| 614 Element element = ElementLocator.locate(declaration); | 614 Element element = ElementLocator.locate(declaration); |
| 615 EngineTestCase.assertInstanceOf( | 615 EngineTestCase.assertInstanceOf( |
| 616 (obj) => obj is MethodElement, MethodElement, element); | 616 (obj) => obj is MethodElement, MethodElement, element); |
| 617 } | 617 } |
| 618 | 618 |
| 619 void test_locate_MethodInvocation_method() { | 619 test_locate_MethodInvocation_method() async { |
| 620 AstNode id = _findNodeIndexedIn( | 620 AstNode id = await _findNodeIndexedIn( |
| 621 "bar", | 621 "bar", |
| 622 1, | 622 1, |
| 623 r''' | 623 r''' |
| 624 class A { | 624 class A { |
| 625 int bar() => 42; | 625 int bar() => 42; |
| 626 } | 626 } |
| 627 void main() { | 627 void main() { |
| 628 var f = new A().bar(); | 628 var f = new A().bar(); |
| 629 }'''); | 629 }'''); |
| 630 Element element = ElementLocator.locate(id); | 630 Element element = ElementLocator.locate(id); |
| 631 EngineTestCase.assertInstanceOf( | 631 EngineTestCase.assertInstanceOf( |
| 632 (obj) => obj is MethodElement, MethodElement, element); | 632 (obj) => obj is MethodElement, MethodElement, element); |
| 633 } | 633 } |
| 634 | 634 |
| 635 void test_locate_MethodInvocation_topLevel() { | 635 test_locate_MethodInvocation_topLevel() async { |
| 636 String code = r''' | 636 String code = r''' |
| 637 foo(x) {} | 637 foo(x) {} |
| 638 void main() { | 638 void main() { |
| 639 foo(0); | 639 foo(0); |
| 640 }'''; | 640 }'''; |
| 641 CompilationUnit cu = _resolveContents(code); | 641 CompilationUnit cu = await _resolveContents(code); |
| 642 int offset = code.indexOf('foo(0)'); | 642 int offset = code.indexOf('foo(0)'); |
| 643 AstNode node = new NodeLocator(offset).searchWithin(cu); | 643 AstNode node = new NodeLocator(offset).searchWithin(cu); |
| 644 MethodInvocation invocation = | 644 MethodInvocation invocation = |
| 645 node.getAncestor((n) => n is MethodInvocation); | 645 node.getAncestor((n) => n is MethodInvocation); |
| 646 Element element = ElementLocator.locate(invocation); | 646 Element element = ElementLocator.locate(invocation); |
| 647 EngineTestCase.assertInstanceOf( | 647 EngineTestCase.assertInstanceOf( |
| 648 (obj) => obj is FunctionElement, FunctionElement, element); | 648 (obj) => obj is FunctionElement, FunctionElement, element); |
| 649 } | 649 } |
| 650 | 650 |
| 651 void test_locate_PartOfDirective() { | 651 test_locate_PartOfDirective() async { |
| 652 Source librarySource = addNamedSource( | 652 Source librarySource = addNamedSource( |
| 653 '/lib.dart', | 653 '/lib.dart', |
| 654 ''' | 654 ''' |
| 655 library my.lib; | 655 library my.lib; |
| 656 part 'part.dart'; | 656 part 'part.dart'; |
| 657 '''); | 657 '''); |
| 658 Source unitSource = addNamedSource( | 658 Source unitSource = addNamedSource( |
| 659 '/part.dart', | 659 '/part.dart', |
| 660 ''' | 660 ''' |
| 661 part of my.lib; | 661 part of my.lib; |
| 662 '''); | 662 '''); |
| 663 CompilationUnit unit = | 663 CompilationUnit unit = |
| 664 analysisContext.resolveCompilationUnit2(unitSource, librarySource); | 664 analysisContext.resolveCompilationUnit2(unitSource, librarySource); |
| 665 PartOfDirective partOf = unit.directives.first; | 665 PartOfDirective partOf = unit.directives.first; |
| 666 Element element = ElementLocator.locate(partOf); | 666 Element element = ElementLocator.locate(partOf); |
| 667 EngineTestCase.assertInstanceOf( | 667 EngineTestCase.assertInstanceOf( |
| 668 (obj) => obj is LibraryElement, LibraryElement, element); | 668 (obj) => obj is LibraryElement, LibraryElement, element); |
| 669 } | 669 } |
| 670 | 670 |
| 671 void test_locate_PostfixExpression() { | 671 test_locate_PostfixExpression() async { |
| 672 AstNode id = _findNodeIn("++", "int addOne(int x) => x++;"); | 672 AstNode id = await _findNodeIn("++", "int addOne(int x) => x++;"); |
| 673 Element element = ElementLocator.locate(id); | 673 Element element = ElementLocator.locate(id); |
| 674 EngineTestCase.assertInstanceOf( | 674 EngineTestCase.assertInstanceOf( |
| 675 (obj) => obj is MethodElement, MethodElement, element); | 675 (obj) => obj is MethodElement, MethodElement, element); |
| 676 } | 676 } |
| 677 | 677 |
| 678 void test_locate_PrefixedIdentifier() { | 678 test_locate_PrefixedIdentifier() async { |
| 679 AstNode id = _findNodeIn( | 679 AstNode id = await _findNodeIn( |
| 680 "int", | 680 "int", |
| 681 r''' | 681 r''' |
| 682 import 'dart:core' as core; | 682 import 'dart:core' as core; |
| 683 core.int value;'''); | 683 core.int value;'''); |
| 684 PrefixedIdentifier identifier = | 684 PrefixedIdentifier identifier = |
| 685 id.getAncestor((node) => node is PrefixedIdentifier); | 685 id.getAncestor((node) => node is PrefixedIdentifier); |
| 686 Element element = ElementLocator.locate(identifier); | 686 Element element = ElementLocator.locate(identifier); |
| 687 EngineTestCase.assertInstanceOf( | 687 EngineTestCase.assertInstanceOf( |
| 688 (obj) => obj is ClassElement, ClassElement, element); | 688 (obj) => obj is ClassElement, ClassElement, element); |
| 689 } | 689 } |
| 690 | 690 |
| 691 void test_locate_PrefixExpression() { | 691 test_locate_PrefixExpression() async { |
| 692 AstNode id = _findNodeIn("++", "int addOne(int x) => ++x;"); | 692 AstNode id = await _findNodeIn("++", "int addOne(int x) => ++x;"); |
| 693 Element element = ElementLocator.locate(id); | 693 Element element = ElementLocator.locate(id); |
| 694 EngineTestCase.assertInstanceOf( | 694 EngineTestCase.assertInstanceOf( |
| 695 (obj) => obj is MethodElement, MethodElement, element); | 695 (obj) => obj is MethodElement, MethodElement, element); |
| 696 } | 696 } |
| 697 | 697 |
| 698 void test_locate_StringLiteral_exportUri() { | 698 test_locate_StringLiteral_exportUri() async { |
| 699 addNamedSource("/foo.dart", "library foo;"); | 699 addNamedSource("/foo.dart", "library foo;"); |
| 700 AstNode id = _findNodeIn("'foo.dart'", "export 'foo.dart';"); | 700 AstNode id = await _findNodeIn("'foo.dart'", "export 'foo.dart';"); |
| 701 Element element = ElementLocator.locate(id); | 701 Element element = ElementLocator.locate(id); |
| 702 EngineTestCase.assertInstanceOf( | 702 EngineTestCase.assertInstanceOf( |
| 703 (obj) => obj is LibraryElement, LibraryElement, element); | 703 (obj) => obj is LibraryElement, LibraryElement, element); |
| 704 } | 704 } |
| 705 | 705 |
| 706 void test_locate_StringLiteral_expression() { | 706 test_locate_StringLiteral_expression() async { |
| 707 AstNode id = _findNodeIn("abc", "var x = 'abc';"); | 707 AstNode id = await _findNodeIn("abc", "var x = 'abc';"); |
| 708 Element element = ElementLocator.locate(id); | 708 Element element = ElementLocator.locate(id); |
| 709 expect(element, isNull); | 709 expect(element, isNull); |
| 710 } | 710 } |
| 711 | 711 |
| 712 void test_locate_StringLiteral_importUri() { | 712 test_locate_StringLiteral_importUri() async { |
| 713 addNamedSource("/foo.dart", "library foo; class A {}"); | 713 addNamedSource("/foo.dart", "library foo; class A {}"); |
| 714 AstNode id = | 714 AstNode id = await _findNodeIn( |
| 715 _findNodeIn("'foo.dart'", "import 'foo.dart'; class B extends A {}"); | 715 "'foo.dart'", "import 'foo.dart'; class B extends A {}"); |
| 716 Element element = ElementLocator.locate(id); | 716 Element element = ElementLocator.locate(id); |
| 717 EngineTestCase.assertInstanceOf( | 717 EngineTestCase.assertInstanceOf( |
| 718 (obj) => obj is LibraryElement, LibraryElement, element); | 718 (obj) => obj is LibraryElement, LibraryElement, element); |
| 719 } | 719 } |
| 720 | 720 |
| 721 void test_locate_StringLiteral_partUri() { | 721 test_locate_StringLiteral_partUri() async { |
| 722 addNamedSource("/foo.dart", "part of app;"); | 722 addNamedSource("/foo.dart", "part of app;"); |
| 723 AstNode id = _findNodeIn("'foo.dart'", "library app; part 'foo.dart';"); | 723 AstNode id = |
| 724 await _findNodeIn("'foo.dart'", "library app; part 'foo.dart';"); | |
| 724 Element element = ElementLocator.locate(id); | 725 Element element = ElementLocator.locate(id); |
| 725 EngineTestCase.assertInstanceOf((obj) => obj is CompilationUnitElement, | 726 EngineTestCase.assertInstanceOf((obj) => obj is CompilationUnitElement, |
| 726 CompilationUnitElement, element); | 727 CompilationUnitElement, element); |
| 727 } | 728 } |
| 728 | 729 |
| 729 void test_locate_VariableDeclaration() { | 730 test_locate_VariableDeclaration() async { |
| 730 AstNode id = _findNodeIn("x", "var x = 'abc';"); | 731 AstNode id = await _findNodeIn("x", "var x = 'abc';"); |
| 731 VariableDeclaration declaration = | 732 VariableDeclaration declaration = |
| 732 id.getAncestor((node) => node is VariableDeclaration); | 733 id.getAncestor((node) => node is VariableDeclaration); |
| 733 Element element = ElementLocator.locate(declaration); | 734 Element element = ElementLocator.locate(declaration); |
| 734 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, | 735 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, |
| 735 TopLevelVariableElement, element); | 736 TopLevelVariableElement, element); |
| 736 } | 737 } |
| 737 | 738 |
| 738 /** | 739 /** |
| 739 * Find the first AST node matching a pattern in the resolved AST for the give n source. | 740 * Find the first AST node matching a pattern in the resolved AST for the give n source. |
| 740 * | 741 * |
| 741 * [nodePattern] the (unique) pattern used to identify the node of interest. | 742 * [nodePattern] the (unique) pattern used to identify the node of interest. |
| 742 * [code] the code to resolve. | 743 * [code] the code to resolve. |
| 743 * Returns the matched node in the resolved AST for the given source lines. | 744 * Returns the matched node in the resolved AST for the given source lines. |
| 744 */ | 745 */ |
| 745 AstNode _findNodeIn(String nodePattern, String code) { | 746 Future<AstNode> _findNodeIn(String nodePattern, String code) async { |
| 746 return _findNodeIndexedIn(nodePattern, 0, code); | 747 return await _findNodeIndexedIn(nodePattern, 0, code); |
| 747 } | 748 } |
| 748 | 749 |
| 749 /** | 750 /** |
| 750 * Find the AST node matching the given indexed occurrence of a pattern in the resolved AST for | 751 * Find the AST node matching the given indexed occurrence of a pattern in the resolved AST for |
| 751 * the given source. | 752 * the given source. |
| 752 * | 753 * |
| 753 * [nodePattern] the pattern used to identify the node of interest. | 754 * [nodePattern] the pattern used to identify the node of interest. |
| 754 * [index] the index of the pattern match of interest. | 755 * [index] the index of the pattern match of interest. |
| 755 * [code] the code to resolve. | 756 * [code] the code to resolve. |
| 756 * Returns the matched node in the resolved AST for the given source lines | 757 * Returns the matched node in the resolved AST for the given source lines |
| 757 */ | 758 */ |
| 758 AstNode _findNodeIndexedIn(String nodePattern, int index, String code) { | 759 Future<AstNode> _findNodeIndexedIn( |
| 759 CompilationUnit cu = _resolveContents(code); | 760 String nodePattern, int index, String code) async { |
| 761 CompilationUnit cu = await _resolveContents(code); | |
| 760 int start = _getOffsetOfMatch(code, nodePattern, index); | 762 int start = _getOffsetOfMatch(code, nodePattern, index); |
| 761 int end = start + nodePattern.length; | 763 int end = start + nodePattern.length; |
| 762 return new NodeLocator(start, end).searchWithin(cu); | 764 return new NodeLocator(start, end).searchWithin(cu); |
| 763 } | 765 } |
| 764 | 766 |
| 765 int _getOffsetOfMatch(String contents, String pattern, int matchIndex) { | 767 int _getOffsetOfMatch(String contents, String pattern, int matchIndex) { |
| 766 if (matchIndex == 0) { | 768 if (matchIndex == 0) { |
| 767 return contents.indexOf(pattern); | 769 return contents.indexOf(pattern); |
| 768 } | 770 } |
| 769 Iterable<Match> matches = new RegExp(pattern).allMatches(contents); | 771 Iterable<Match> matches = new RegExp(pattern).allMatches(contents); |
| 770 Match match = matches.toList()[matchIndex]; | 772 Match match = matches.toList()[matchIndex]; |
| 771 return match.start; | 773 return match.start; |
| 772 } | 774 } |
| 773 | 775 |
| 774 /** | 776 /** |
| 775 * Parse, resolve and verify the given source lines to produce a fully | 777 * Parse, resolve and verify the given source lines to produce a fully |
| 776 * resolved AST. | 778 * resolved AST. |
| 777 * | 779 * |
| 778 * [code] the code to resolve. | 780 * [code] the code to resolve. |
| 779 * | 781 * |
| 780 * Returns the result of resolving the AST structure representing the content | 782 * Returns the result of resolving the AST structure representing the content |
| 781 * of the source. | 783 * of the source. |
| 782 * | 784 * |
| 783 * Throws if source cannot be verified. | 785 * Throws if source cannot be verified. |
| 784 */ | 786 */ |
| 785 CompilationUnit _resolveContents(String code) { | 787 Future<CompilationUnit> _resolveContents(String code) async { |
| 786 Source source = addSource(code); | 788 Source source = addSource(code); |
| 787 LibraryElement library = resolve2(source); | 789 LibraryElement library = resolve2(source); |
| 788 assertNoErrors(source); | 790 await assertNoErrors(source); |
| 789 verify([source]); | 791 verify([source]); |
| 790 return analysisContext.resolveCompilationUnit(source, library); | 792 return analysisContext.resolveCompilationUnit(source, library); |
| 791 } | 793 } |
| 792 } | 794 } |
| 793 | 795 |
| 794 @reflectiveTest | 796 @reflectiveTest |
| 795 class EnumMemberBuilderTest extends EngineTestCase { | 797 class EnumMemberBuilderTest extends EngineTestCase { |
| 796 void test_visitEnumDeclaration_multiple() { | 798 test_visitEnumDeclaration_multiple() async { |
| 797 String firstName = "ONE"; | 799 String firstName = "ONE"; |
| 798 String secondName = "TWO"; | 800 String secondName = "TWO"; |
| 799 String thirdName = "THREE"; | 801 String thirdName = "THREE"; |
| 800 EnumDeclaration enumDeclaration = AstTestFactory | 802 EnumDeclaration enumDeclaration = AstTestFactory |
| 801 .enumDeclaration2("E", [firstName, secondName, thirdName]); | 803 .enumDeclaration2("E", [firstName, secondName, thirdName]); |
| 802 | 804 |
| 803 ClassElement enumElement = _buildElement(enumDeclaration); | 805 ClassElement enumElement = _buildElement(enumDeclaration); |
| 804 List<FieldElement> fields = enumElement.fields; | 806 List<FieldElement> fields = enumElement.fields; |
| 805 expect(fields, hasLength(5)); | 807 expect(fields, hasLength(5)); |
| 806 | 808 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 819 _assertGetter(constant); | 821 _assertGetter(constant); |
| 820 | 822 |
| 821 constant = fields[4]; | 823 constant = fields[4]; |
| 822 expect(constant, isNotNull); | 824 expect(constant, isNotNull); |
| 823 expect(constant.name, thirdName); | 825 expect(constant.name, thirdName); |
| 824 expect(constant.isStatic, isTrue); | 826 expect(constant.isStatic, isTrue); |
| 825 expect((constant as FieldElementImpl).evaluationResult, isNotNull); | 827 expect((constant as FieldElementImpl).evaluationResult, isNotNull); |
| 826 _assertGetter(constant); | 828 _assertGetter(constant); |
| 827 } | 829 } |
| 828 | 830 |
| 829 void test_visitEnumDeclaration_single() { | 831 test_visitEnumDeclaration_single() async { |
| 830 String firstName = "ONE"; | 832 String firstName = "ONE"; |
| 831 EnumDeclaration enumDeclaration = | 833 EnumDeclaration enumDeclaration = |
| 832 AstTestFactory.enumDeclaration2("E", [firstName]); | 834 AstTestFactory.enumDeclaration2("E", [firstName]); |
| 833 enumDeclaration.constants[0].documentationComment = AstTestFactory | 835 enumDeclaration.constants[0].documentationComment = AstTestFactory |
| 834 .documentationComment( | 836 .documentationComment( |
| 835 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 837 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 836 | 838 |
| 837 ClassElement enumElement = _buildElement(enumDeclaration); | 839 ClassElement enumElement = _buildElement(enumDeclaration); |
| 838 List<FieldElement> fields = enumElement.fields; | 840 List<FieldElement> fields = enumElement.fields; |
| 839 expect(fields, hasLength(3)); | 841 expect(fields, hasLength(3)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 * @param typeName the name of the type to be created | 896 * @param typeName the name of the type to be created |
| 895 * @return the type that was created | 897 * @return the type that was created |
| 896 */ | 898 */ |
| 897 InterfaceType createType(String fileName, String typeName) { | 899 InterfaceType createType(String fileName, String typeName) { |
| 898 CompilationUnitElementImpl unit = ElementFactory.compilationUnit(fileName); | 900 CompilationUnitElementImpl unit = ElementFactory.compilationUnit(fileName); |
| 899 ClassElementImpl element = ElementFactory.classElement2(typeName); | 901 ClassElementImpl element = ElementFactory.classElement2(typeName); |
| 900 unit.types = <ClassElement>[element]; | 902 unit.types = <ClassElement>[element]; |
| 901 return element.type; | 903 return element.type; |
| 902 } | 904 } |
| 903 | 905 |
| 904 void test_creation() { | 906 test_creation() async { |
| 905 GatheringErrorListener listener = new GatheringErrorListener(); | 907 GatheringErrorListener listener = new GatheringErrorListener(); |
| 906 TestSource source = new TestSource(); | 908 TestSource source = new TestSource(); |
| 907 expect(new ErrorReporter(listener, source), isNotNull); | 909 expect(new ErrorReporter(listener, source), isNotNull); |
| 908 } | 910 } |
| 909 | 911 |
| 910 void test_reportErrorForElement_named() { | 912 test_reportErrorForElement_named() async { |
| 911 DartType type = createType("/test1.dart", "A"); | 913 DartType type = createType("/test1.dart", "A"); |
| 912 ClassElement element = type.element; | 914 ClassElement element = type.element; |
| 913 GatheringErrorListener listener = new GatheringErrorListener(); | 915 GatheringErrorListener listener = new GatheringErrorListener(); |
| 914 ErrorReporter reporter = new ErrorReporter(listener, element.source); | 916 ErrorReporter reporter = new ErrorReporter(listener, element.source); |
| 915 reporter.reportErrorForElement( | 917 reporter.reportErrorForElement( |
| 916 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, | 918 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, |
| 917 element, | 919 element, |
| 918 ['A']); | 920 ['A']); |
| 919 AnalysisError error = listener.errors[0]; | 921 AnalysisError error = listener.errors[0]; |
| 920 expect(error.offset, element.nameOffset); | 922 expect(error.offset, element.nameOffset); |
| 921 } | 923 } |
| 922 | 924 |
| 923 void test_reportErrorForElement_unnamed() { | 925 test_reportErrorForElement_unnamed() async { |
| 924 ImportElementImpl element = | 926 ImportElementImpl element = |
| 925 ElementFactory.importFor(ElementFactory.library(null, ''), null); | 927 ElementFactory.importFor(ElementFactory.library(null, ''), null); |
| 926 GatheringErrorListener listener = new GatheringErrorListener(); | 928 GatheringErrorListener listener = new GatheringErrorListener(); |
| 927 ErrorReporter reporter = new ErrorReporter( | 929 ErrorReporter reporter = new ErrorReporter( |
| 928 listener, | 930 listener, |
| 929 new NonExistingSource( | 931 new NonExistingSource( |
| 930 '/test.dart', path.toUri('/test.dart'), UriKind.FILE_URI)); | 932 '/test.dart', path.toUri('/test.dart'), UriKind.FILE_URI)); |
| 931 reporter.reportErrorForElement( | 933 reporter.reportErrorForElement( |
| 932 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, | 934 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, |
| 933 element, | 935 element, |
| 934 ['A']); | 936 ['A']); |
| 935 AnalysisError error = listener.errors[0]; | 937 AnalysisError error = listener.errors[0]; |
| 936 expect(error.offset, element.nameOffset); | 938 expect(error.offset, element.nameOffset); |
| 937 } | 939 } |
| 938 | 940 |
| 939 void test_reportErrorForSpan() { | 941 test_reportErrorForSpan() async { |
| 940 GatheringErrorListener listener = new GatheringErrorListener(); | 942 GatheringErrorListener listener = new GatheringErrorListener(); |
| 941 ErrorReporter reporter = new ErrorReporter(listener, new TestSource()); | 943 ErrorReporter reporter = new ErrorReporter(listener, new TestSource()); |
| 942 | 944 |
| 943 var src = ''' | 945 var src = ''' |
| 944 foo: bar | 946 foo: bar |
| 945 zap: baz | 947 zap: baz |
| 946 '''; | 948 '''; |
| 947 | 949 |
| 948 int offset = src.indexOf('baz'); | 950 int offset = src.indexOf('baz'); |
| 949 int length = 'baz'.length; | 951 int length = 'baz'.length; |
| 950 | 952 |
| 951 SourceSpan span = new SourceFile(src).span(offset, offset + length); | 953 SourceSpan span = new SourceFile(src).span(offset, offset + length); |
| 952 | 954 |
| 953 reporter.reportErrorForSpan( | 955 reporter.reportErrorForSpan( |
| 954 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE, | 956 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE, |
| 955 span, | 957 span, |
| 956 ['test', 'zip', 'zap']); | 958 ['test', 'zip', 'zap']); |
| 957 expect(listener.errors, hasLength(1)); | 959 expect(listener.errors, hasLength(1)); |
| 958 expect(listener.errors.first.offset, offset); | 960 expect(listener.errors.first.offset, offset); |
| 959 expect(listener.errors.first.length, length); | 961 expect(listener.errors.first.length, length); |
| 960 } | 962 } |
| 961 | 963 |
| 962 void test_reportTypeErrorForNode_differentNames() { | 964 test_reportTypeErrorForNode_differentNames() async { |
| 963 DartType firstType = createType("/test1.dart", "A"); | 965 DartType firstType = createType("/test1.dart", "A"); |
| 964 DartType secondType = createType("/test2.dart", "B"); | 966 DartType secondType = createType("/test2.dart", "B"); |
| 965 GatheringErrorListener listener = new GatheringErrorListener(); | 967 GatheringErrorListener listener = new GatheringErrorListener(); |
| 966 ErrorReporter reporter = | 968 ErrorReporter reporter = |
| 967 new ErrorReporter(listener, firstType.element.source); | 969 new ErrorReporter(listener, firstType.element.source); |
| 968 reporter.reportTypeErrorForNode( | 970 reporter.reportTypeErrorForNode( |
| 969 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, | 971 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, |
| 970 AstTestFactory.identifier3("x"), | 972 AstTestFactory.identifier3("x"), |
| 971 [firstType, secondType]); | 973 [firstType, secondType]); |
| 972 AnalysisError error = listener.errors[0]; | 974 AnalysisError error = listener.errors[0]; |
| 973 expect(error.message.indexOf("(") < 0, isTrue); | 975 expect(error.message.indexOf("(") < 0, isTrue); |
| 974 } | 976 } |
| 975 | 977 |
| 976 void test_reportTypeErrorForNode_sameName() { | 978 test_reportTypeErrorForNode_sameName() async { |
| 977 String typeName = "A"; | 979 String typeName = "A"; |
| 978 DartType firstType = createType("/test1.dart", typeName); | 980 DartType firstType = createType("/test1.dart", typeName); |
| 979 DartType secondType = createType("/test2.dart", typeName); | 981 DartType secondType = createType("/test2.dart", typeName); |
| 980 GatheringErrorListener listener = new GatheringErrorListener(); | 982 GatheringErrorListener listener = new GatheringErrorListener(); |
| 981 ErrorReporter reporter = | 983 ErrorReporter reporter = |
| 982 new ErrorReporter(listener, firstType.element.source); | 984 new ErrorReporter(listener, firstType.element.source); |
| 983 reporter.reportTypeErrorForNode( | 985 reporter.reportTypeErrorForNode( |
| 984 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, | 986 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, |
| 985 AstTestFactory.identifier3("x"), | 987 AstTestFactory.identifier3("x"), |
| 986 [firstType, secondType]); | 988 [firstType, secondType]); |
| 987 AnalysisError error = listener.errors[0]; | 989 AnalysisError error = listener.errors[0]; |
| 988 expect(error.message.indexOf("(") >= 0, isTrue); | 990 expect(error.message.indexOf("(") >= 0, isTrue); |
| 989 } | 991 } |
| 990 } | 992 } |
| 991 | 993 |
| 992 @reflectiveTest | 994 @reflectiveTest |
| 993 class ErrorSeverityTest extends EngineTestCase { | 995 class ErrorSeverityTest extends EngineTestCase { |
| 994 void test_max_error_error() { | 996 test_max_error_error() async { |
| 995 expect(ErrorSeverity.ERROR.max(ErrorSeverity.ERROR), | 997 expect(ErrorSeverity.ERROR.max(ErrorSeverity.ERROR), |
| 996 same(ErrorSeverity.ERROR)); | 998 same(ErrorSeverity.ERROR)); |
| 997 } | 999 } |
| 998 | 1000 |
| 999 void test_max_error_none() { | 1001 test_max_error_none() async { |
| 1000 expect( | 1002 expect( |
| 1001 ErrorSeverity.ERROR.max(ErrorSeverity.NONE), same(ErrorSeverity.ERROR)); | 1003 ErrorSeverity.ERROR.max(ErrorSeverity.NONE), same(ErrorSeverity.ERROR)); |
| 1002 } | 1004 } |
| 1003 | 1005 |
| 1004 void test_max_error_warning() { | 1006 test_max_error_warning() async { |
| 1005 expect(ErrorSeverity.ERROR.max(ErrorSeverity.WARNING), | 1007 expect(ErrorSeverity.ERROR.max(ErrorSeverity.WARNING), |
| 1006 same(ErrorSeverity.ERROR)); | 1008 same(ErrorSeverity.ERROR)); |
| 1007 } | 1009 } |
| 1008 | 1010 |
| 1009 void test_max_none_error() { | 1011 test_max_none_error() async { |
| 1010 expect( | 1012 expect( |
| 1011 ErrorSeverity.NONE.max(ErrorSeverity.ERROR), same(ErrorSeverity.ERROR)); | 1013 ErrorSeverity.NONE.max(ErrorSeverity.ERROR), same(ErrorSeverity.ERROR)); |
| 1012 } | 1014 } |
| 1013 | 1015 |
| 1014 void test_max_none_none() { | 1016 test_max_none_none() async { |
| 1015 expect( | 1017 expect( |
| 1016 ErrorSeverity.NONE.max(ErrorSeverity.NONE), same(ErrorSeverity.NONE)); | 1018 ErrorSeverity.NONE.max(ErrorSeverity.NONE), same(ErrorSeverity.NONE)); |
| 1017 } | 1019 } |
| 1018 | 1020 |
| 1019 void test_max_none_warning() { | 1021 test_max_none_warning() async { |
| 1020 expect(ErrorSeverity.NONE.max(ErrorSeverity.WARNING), | 1022 expect(ErrorSeverity.NONE.max(ErrorSeverity.WARNING), |
| 1021 same(ErrorSeverity.WARNING)); | 1023 same(ErrorSeverity.WARNING)); |
| 1022 } | 1024 } |
| 1023 | 1025 |
| 1024 void test_max_warning_error() { | 1026 test_max_warning_error() async { |
| 1025 expect(ErrorSeverity.WARNING.max(ErrorSeverity.ERROR), | 1027 expect(ErrorSeverity.WARNING.max(ErrorSeverity.ERROR), |
| 1026 same(ErrorSeverity.ERROR)); | 1028 same(ErrorSeverity.ERROR)); |
| 1027 } | 1029 } |
| 1028 | 1030 |
| 1029 void test_max_warning_none() { | 1031 test_max_warning_none() async { |
| 1030 expect(ErrorSeverity.WARNING.max(ErrorSeverity.NONE), | 1032 expect(ErrorSeverity.WARNING.max(ErrorSeverity.NONE), |
| 1031 same(ErrorSeverity.WARNING)); | 1033 same(ErrorSeverity.WARNING)); |
| 1032 } | 1034 } |
| 1033 | 1035 |
| 1034 void test_max_warning_warning() { | 1036 test_max_warning_warning() async { |
| 1035 expect(ErrorSeverity.WARNING.max(ErrorSeverity.WARNING), | 1037 expect(ErrorSeverity.WARNING.max(ErrorSeverity.WARNING), |
| 1036 same(ErrorSeverity.WARNING)); | 1038 same(ErrorSeverity.WARNING)); |
| 1037 } | 1039 } |
| 1038 } | 1040 } |
| 1039 | 1041 |
| 1040 /** | 1042 /** |
| 1041 * Tests for the [ExitDetector] that do not require that the AST be resolved. | 1043 * Tests for the [ExitDetector] that do not require that the AST be resolved. |
| 1042 * | 1044 * |
| 1043 * See [ExitDetectorTest2] for tests that require the AST to be resolved. | 1045 * See [ExitDetectorTest2] for tests that require the AST to be resolved. |
| 1044 */ | 1046 */ |
| 1045 @reflectiveTest | 1047 @reflectiveTest |
| 1046 class ExitDetectorTest extends ParserTestCase { | 1048 class ExitDetectorTest extends ParserTestCase { |
| 1047 void test_asExpression() { | 1049 test_asExpression() async { |
| 1048 _assertFalse("a as Object;"); | 1050 _assertFalse("a as Object;"); |
| 1049 } | 1051 } |
| 1050 | 1052 |
| 1051 void test_asExpression_throw() { | 1053 test_asExpression_throw() async { |
| 1052 _assertTrue("throw '' as Object;"); | 1054 _assertTrue("throw '' as Object;"); |
| 1053 } | 1055 } |
| 1054 | 1056 |
| 1055 void test_assertStatement() { | 1057 test_assertStatement() async { |
| 1056 _assertFalse("assert(a);"); | 1058 _assertFalse("assert(a);"); |
| 1057 } | 1059 } |
| 1058 | 1060 |
| 1059 void test_assertStatement_throw() { | 1061 test_assertStatement_throw() async { |
| 1060 _assertFalse("assert((throw 0));"); | 1062 _assertFalse("assert((throw 0));"); |
| 1061 } | 1063 } |
| 1062 | 1064 |
| 1063 void test_assignmentExpression() { | 1065 test_assignmentExpression() async { |
| 1064 _assertFalse("v = 1;"); | 1066 _assertFalse("v = 1;"); |
| 1065 } | 1067 } |
| 1066 | 1068 |
| 1067 void test_assignmentExpression_compound_lazy() { | 1069 test_assignmentExpression_compound_lazy() async { |
| 1068 enableLazyAssignmentOperators = true; | 1070 enableLazyAssignmentOperators = true; |
| 1069 _assertFalse("v ||= false;"); | 1071 _assertFalse("v ||= false;"); |
| 1070 } | 1072 } |
| 1071 | 1073 |
| 1072 void test_assignmentExpression_lhs_throw() { | 1074 test_assignmentExpression_lhs_throw() async { |
| 1073 _assertTrue("a[throw ''] = 0;"); | 1075 _assertTrue("a[throw ''] = 0;"); |
| 1074 } | 1076 } |
| 1075 | 1077 |
| 1076 void test_assignmentExpression_rhs_throw() { | 1078 test_assignmentExpression_rhs_throw() async { |
| 1077 _assertTrue("v = throw '';"); | 1079 _assertTrue("v = throw '';"); |
| 1078 } | 1080 } |
| 1079 | 1081 |
| 1080 void test_await_false() { | 1082 test_await_false() async { |
| 1081 _assertFalse("await x;"); | 1083 _assertFalse("await x;"); |
| 1082 } | 1084 } |
| 1083 | 1085 |
| 1084 void test_await_throw_true() { | 1086 test_await_throw_true() async { |
| 1085 _assertTrue("bool b = await (throw '' || true);"); | 1087 _assertTrue("bool b = await (throw '' || true);"); |
| 1086 } | 1088 } |
| 1087 | 1089 |
| 1088 void test_binaryExpression_and() { | 1090 test_binaryExpression_and() async { |
| 1089 _assertFalse("a && b;"); | 1091 _assertFalse("a && b;"); |
| 1090 } | 1092 } |
| 1091 | 1093 |
| 1092 void test_binaryExpression_and_lhs() { | 1094 test_binaryExpression_and_lhs() async { |
| 1093 _assertTrue("throw '' && b;"); | 1095 _assertTrue("throw '' && b;"); |
| 1094 } | 1096 } |
| 1095 | 1097 |
| 1096 void test_binaryExpression_and_rhs() { | 1098 test_binaryExpression_and_rhs() async { |
| 1097 _assertFalse("a && (throw '');"); | 1099 _assertFalse("a && (throw '');"); |
| 1098 } | 1100 } |
| 1099 | 1101 |
| 1100 void test_binaryExpression_and_rhs2() { | 1102 test_binaryExpression_and_rhs2() async { |
| 1101 _assertFalse("false && (throw '');"); | 1103 _assertFalse("false && (throw '');"); |
| 1102 } | 1104 } |
| 1103 | 1105 |
| 1104 void test_binaryExpression_and_rhs3() { | 1106 test_binaryExpression_and_rhs3() async { |
| 1105 _assertTrue("true && (throw '');"); | 1107 _assertTrue("true && (throw '');"); |
| 1106 } | 1108 } |
| 1107 | 1109 |
| 1108 void test_binaryExpression_ifNull() { | 1110 test_binaryExpression_ifNull() async { |
| 1109 _assertFalse("a ?? b;"); | 1111 _assertFalse("a ?? b;"); |
| 1110 } | 1112 } |
| 1111 | 1113 |
| 1112 void test_binaryExpression_ifNull_lhs() { | 1114 test_binaryExpression_ifNull_lhs() async { |
| 1113 _assertTrue("throw '' ?? b;"); | 1115 _assertTrue("throw '' ?? b;"); |
| 1114 } | 1116 } |
| 1115 | 1117 |
| 1116 void test_binaryExpression_ifNull_rhs() { | 1118 test_binaryExpression_ifNull_rhs() async { |
| 1117 _assertFalse("a ?? (throw '');"); | 1119 _assertFalse("a ?? (throw '');"); |
| 1118 } | 1120 } |
| 1119 | 1121 |
| 1120 void test_binaryExpression_ifNull_rhs2() { | 1122 test_binaryExpression_ifNull_rhs2() async { |
| 1121 _assertFalse("null ?? (throw '');"); | 1123 _assertFalse("null ?? (throw '');"); |
| 1122 } | 1124 } |
| 1123 | 1125 |
| 1124 void test_binaryExpression_or() { | 1126 test_binaryExpression_or() async { |
| 1125 _assertFalse("a || b;"); | 1127 _assertFalse("a || b;"); |
| 1126 } | 1128 } |
| 1127 | 1129 |
| 1128 void test_binaryExpression_or_lhs() { | 1130 test_binaryExpression_or_lhs() async { |
| 1129 _assertTrue("throw '' || b;"); | 1131 _assertTrue("throw '' || b;"); |
| 1130 } | 1132 } |
| 1131 | 1133 |
| 1132 void test_binaryExpression_or_rhs() { | 1134 test_binaryExpression_or_rhs() async { |
| 1133 _assertFalse("a || (throw '');"); | 1135 _assertFalse("a || (throw '');"); |
| 1134 } | 1136 } |
| 1135 | 1137 |
| 1136 void test_binaryExpression_or_rhs2() { | 1138 test_binaryExpression_or_rhs2() async { |
| 1137 _assertFalse("true || (throw '');"); | 1139 _assertFalse("true || (throw '');"); |
| 1138 } | 1140 } |
| 1139 | 1141 |
| 1140 void test_binaryExpression_or_rhs3() { | 1142 test_binaryExpression_or_rhs3() async { |
| 1141 _assertTrue("false || (throw '');"); | 1143 _assertTrue("false || (throw '');"); |
| 1142 } | 1144 } |
| 1143 | 1145 |
| 1144 void test_block_empty() { | 1146 test_block_empty() async { |
| 1145 _assertFalse("{}"); | 1147 _assertFalse("{}"); |
| 1146 } | 1148 } |
| 1147 | 1149 |
| 1148 void test_block_noReturn() { | 1150 test_block_noReturn() async { |
| 1149 _assertFalse("{ int i = 0; }"); | 1151 _assertFalse("{ int i = 0; }"); |
| 1150 } | 1152 } |
| 1151 | 1153 |
| 1152 void test_block_return() { | 1154 test_block_return() async { |
| 1153 _assertTrue("{ return 0; }"); | 1155 _assertTrue("{ return 0; }"); |
| 1154 } | 1156 } |
| 1155 | 1157 |
| 1156 void test_block_returnNotLast() { | 1158 test_block_returnNotLast() async { |
| 1157 _assertTrue("{ return 0; throw 'a'; }"); | 1159 _assertTrue("{ return 0; throw 'a'; }"); |
| 1158 } | 1160 } |
| 1159 | 1161 |
| 1160 void test_block_throwNotLast() { | 1162 test_block_throwNotLast() async { |
| 1161 _assertTrue("{ throw 0; x = null; }"); | 1163 _assertTrue("{ throw 0; x = null; }"); |
| 1162 } | 1164 } |
| 1163 | 1165 |
| 1164 void test_cascadeExpression_argument() { | 1166 test_cascadeExpression_argument() async { |
| 1165 _assertTrue("a..b(throw '');"); | 1167 _assertTrue("a..b(throw '');"); |
| 1166 } | 1168 } |
| 1167 | 1169 |
| 1168 void test_cascadeExpression_index() { | 1170 test_cascadeExpression_index() async { |
| 1169 _assertTrue("a..[throw ''];"); | 1171 _assertTrue("a..[throw ''];"); |
| 1170 } | 1172 } |
| 1171 | 1173 |
| 1172 void test_cascadeExpression_target() { | 1174 test_cascadeExpression_target() async { |
| 1173 _assertTrue("throw ''..b();"); | 1175 _assertTrue("throw ''..b();"); |
| 1174 } | 1176 } |
| 1175 | 1177 |
| 1176 void test_conditional_ifElse_bothThrows() { | 1178 test_conditional_ifElse_bothThrows() async { |
| 1177 _assertTrue("c ? throw '' : throw '';"); | 1179 _assertTrue("c ? throw '' : throw '';"); |
| 1178 } | 1180 } |
| 1179 | 1181 |
| 1180 void test_conditional_ifElse_elseThrows() { | 1182 test_conditional_ifElse_elseThrows() async { |
| 1181 _assertFalse("c ? i : throw '';"); | 1183 _assertFalse("c ? i : throw '';"); |
| 1182 } | 1184 } |
| 1183 | 1185 |
| 1184 void test_conditional_ifElse_noThrow() { | 1186 test_conditional_ifElse_noThrow() async { |
| 1185 _assertFalse("c ? i : j;"); | 1187 _assertFalse("c ? i : j;"); |
| 1186 } | 1188 } |
| 1187 | 1189 |
| 1188 void test_conditional_ifElse_thenThrow() { | 1190 test_conditional_ifElse_thenThrow() async { |
| 1189 _assertFalse("c ? throw '' : j;"); | 1191 _assertFalse("c ? throw '' : j;"); |
| 1190 } | 1192 } |
| 1191 | 1193 |
| 1192 void test_conditionalAccess() { | 1194 test_conditionalAccess() async { |
| 1193 _assertFalse("a?.b;"); | 1195 _assertFalse("a?.b;"); |
| 1194 } | 1196 } |
| 1195 | 1197 |
| 1196 void test_conditionalAccess_lhs() { | 1198 test_conditionalAccess_lhs() async { |
| 1197 _assertTrue("(throw '')?.b;"); | 1199 _assertTrue("(throw '')?.b;"); |
| 1198 } | 1200 } |
| 1199 | 1201 |
| 1200 void test_conditionalAccessAssign() { | 1202 test_conditionalAccessAssign() async { |
| 1201 _assertFalse("a?.b = c;"); | 1203 _assertFalse("a?.b = c;"); |
| 1202 } | 1204 } |
| 1203 | 1205 |
| 1204 void test_conditionalAccessAssign_lhs() { | 1206 test_conditionalAccessAssign_lhs() async { |
| 1205 _assertTrue("(throw '')?.b = c;"); | 1207 _assertTrue("(throw '')?.b = c;"); |
| 1206 } | 1208 } |
| 1207 | 1209 |
| 1208 void test_conditionalAccessAssign_rhs() { | 1210 test_conditionalAccessAssign_rhs() async { |
| 1209 _assertFalse("a?.b = throw '';"); | 1211 _assertFalse("a?.b = throw '';"); |
| 1210 } | 1212 } |
| 1211 | 1213 |
| 1212 void test_conditionalAccessAssign_rhs2() { | 1214 test_conditionalAccessAssign_rhs2() async { |
| 1213 _assertFalse("null?.b = throw '';"); | 1215 _assertFalse("null?.b = throw '';"); |
| 1214 } | 1216 } |
| 1215 | 1217 |
| 1216 void test_conditionalAccessIfNullAssign() { | 1218 test_conditionalAccessIfNullAssign() async { |
| 1217 _assertFalse("a?.b ??= c;"); | 1219 _assertFalse("a?.b ??= c;"); |
| 1218 } | 1220 } |
| 1219 | 1221 |
| 1220 void test_conditionalAccessIfNullAssign_lhs() { | 1222 test_conditionalAccessIfNullAssign_lhs() async { |
| 1221 _assertTrue("(throw '')?.b ??= c;"); | 1223 _assertTrue("(throw '')?.b ??= c;"); |
| 1222 } | 1224 } |
| 1223 | 1225 |
| 1224 void test_conditionalAccessIfNullAssign_rhs() { | 1226 test_conditionalAccessIfNullAssign_rhs() async { |
| 1225 _assertFalse("a?.b ??= throw '';"); | 1227 _assertFalse("a?.b ??= throw '';"); |
| 1226 } | 1228 } |
| 1227 | 1229 |
| 1228 void test_conditionalAccessIfNullAssign_rhs2() { | 1230 test_conditionalAccessIfNullAssign_rhs2() async { |
| 1229 _assertFalse("null?.b ??= throw '';"); | 1231 _assertFalse("null?.b ??= throw '';"); |
| 1230 } | 1232 } |
| 1231 | 1233 |
| 1232 void test_conditionalCall() { | 1234 test_conditionalCall() async { |
| 1233 _assertFalse("a?.b(c);"); | 1235 _assertFalse("a?.b(c);"); |
| 1234 } | 1236 } |
| 1235 | 1237 |
| 1236 void test_conditionalCall_lhs() { | 1238 test_conditionalCall_lhs() async { |
| 1237 _assertTrue("(throw '')?.b(c);"); | 1239 _assertTrue("(throw '')?.b(c);"); |
| 1238 } | 1240 } |
| 1239 | 1241 |
| 1240 void test_conditionalCall_rhs() { | 1242 test_conditionalCall_rhs() async { |
| 1241 _assertFalse("a?.b(throw '');"); | 1243 _assertFalse("a?.b(throw '');"); |
| 1242 } | 1244 } |
| 1243 | 1245 |
| 1244 void test_conditionalCall_rhs2() { | 1246 test_conditionalCall_rhs2() async { |
| 1245 _assertFalse("null?.b(throw '');"); | 1247 _assertFalse("null?.b(throw '');"); |
| 1246 } | 1248 } |
| 1247 | 1249 |
| 1248 void test_creation() { | 1250 test_creation() async { |
| 1249 expect(new ExitDetector(), isNotNull); | 1251 expect(new ExitDetector(), isNotNull); |
| 1250 } | 1252 } |
| 1251 | 1253 |
| 1252 void test_doStatement_break_and_throw() { | 1254 test_doStatement_break_and_throw() async { |
| 1253 _assertFalse("{ do { if (1==1) break; throw 'T'; } while (0==1); }"); | 1255 _assertFalse("{ do { if (1==1) break; throw 'T'; } while (0==1); }"); |
| 1254 } | 1256 } |
| 1255 | 1257 |
| 1256 void test_doStatement_continue_and_throw() { | 1258 test_doStatement_continue_and_throw() async { |
| 1257 _assertFalse("{ do { if (1==1) continue; throw 'T'; } while (0==1); }"); | 1259 _assertFalse("{ do { if (1==1) continue; throw 'T'; } while (0==1); }"); |
| 1258 } | 1260 } |
| 1259 | 1261 |
| 1260 void test_doStatement_continueDoInSwitch_and_throw() { | 1262 test_doStatement_continueDoInSwitch_and_throw() async { |
| 1261 _assertFalse(''' | 1263 _assertFalse(''' |
| 1262 { | 1264 { |
| 1263 D: do { | 1265 D: do { |
| 1264 switch (1) { | 1266 switch (1) { |
| 1265 L: case 0: continue D; | 1267 L: case 0: continue D; |
| 1266 M: case 1: break; | 1268 M: case 1: break; |
| 1267 } | 1269 } |
| 1268 throw 'T'; | 1270 throw 'T'; |
| 1269 } while (0 == 1); | 1271 } while (0 == 1); |
| 1270 }'''); | 1272 }'''); |
| 1271 } | 1273 } |
| 1272 | 1274 |
| 1273 void test_doStatement_continueInSwitch_and_throw() { | 1275 test_doStatement_continueInSwitch_and_throw() async { |
| 1274 _assertFalse(''' | 1276 _assertFalse(''' |
| 1275 { | 1277 { |
| 1276 do { | 1278 do { |
| 1277 switch (1) { | 1279 switch (1) { |
| 1278 L: case 0: continue; | 1280 L: case 0: continue; |
| 1279 M: case 1: break; | 1281 M: case 1: break; |
| 1280 } | 1282 } |
| 1281 throw 'T'; | 1283 throw 'T'; |
| 1282 } while (0 == 1); | 1284 } while (0 == 1); |
| 1283 }'''); | 1285 }'''); |
| 1284 } | 1286 } |
| 1285 | 1287 |
| 1286 void test_doStatement_return() { | 1288 test_doStatement_return() async { |
| 1287 _assertTrue("{ do { return null; } while (1 == 2); }"); | 1289 _assertTrue("{ do { return null; } while (1 == 2); }"); |
| 1288 } | 1290 } |
| 1289 | 1291 |
| 1290 void test_doStatement_throwCondition() { | 1292 test_doStatement_throwCondition() async { |
| 1291 _assertTrue("{ do {} while (throw ''); }"); | 1293 _assertTrue("{ do {} while (throw ''); }"); |
| 1292 } | 1294 } |
| 1293 | 1295 |
| 1294 void test_doStatement_true_break() { | 1296 test_doStatement_true_break() async { |
| 1295 _assertFalse("{ do { break; } while (true); }"); | 1297 _assertFalse("{ do { break; } while (true); }"); |
| 1296 } | 1298 } |
| 1297 | 1299 |
| 1298 void test_doStatement_true_continue() { | 1300 test_doStatement_true_continue() async { |
| 1299 _assertTrue("{ do { continue; } while (true); }"); | 1301 _assertTrue("{ do { continue; } while (true); }"); |
| 1300 } | 1302 } |
| 1301 | 1303 |
| 1302 void test_doStatement_true_continueWithLabel() { | 1304 test_doStatement_true_continueWithLabel() async { |
| 1303 _assertTrue("{ x: do { continue x; } while (true); }"); | 1305 _assertTrue("{ x: do { continue x; } while (true); }"); |
| 1304 } | 1306 } |
| 1305 | 1307 |
| 1306 void test_doStatement_true_if_return() { | 1308 test_doStatement_true_if_return() async { |
| 1307 _assertTrue("{ do { if (true) {return null;} } while (true); }"); | 1309 _assertTrue("{ do { if (true) {return null;} } while (true); }"); |
| 1308 } | 1310 } |
| 1309 | 1311 |
| 1310 void test_doStatement_true_noBreak() { | 1312 test_doStatement_true_noBreak() async { |
| 1311 _assertTrue("{ do {} while (true); }"); | 1313 _assertTrue("{ do {} while (true); }"); |
| 1312 } | 1314 } |
| 1313 | 1315 |
| 1314 void test_doStatement_true_return() { | 1316 test_doStatement_true_return() async { |
| 1315 _assertTrue("{ do { return null; } while (true); }"); | 1317 _assertTrue("{ do { return null; } while (true); }"); |
| 1316 } | 1318 } |
| 1317 | 1319 |
| 1318 void test_emptyStatement() { | 1320 test_emptyStatement() async { |
| 1319 _assertFalse(";"); | 1321 _assertFalse(";"); |
| 1320 } | 1322 } |
| 1321 | 1323 |
| 1322 void test_forEachStatement() { | 1324 test_forEachStatement() async { |
| 1323 _assertFalse("for (element in list) {}"); | 1325 _assertFalse("for (element in list) {}"); |
| 1324 } | 1326 } |
| 1325 | 1327 |
| 1326 void test_forEachStatement_throw() { | 1328 test_forEachStatement_throw() async { |
| 1327 _assertTrue("for (element in throw '') {}"); | 1329 _assertTrue("for (element in throw '') {}"); |
| 1328 } | 1330 } |
| 1329 | 1331 |
| 1330 void test_forStatement_condition() { | 1332 test_forStatement_condition() async { |
| 1331 _assertTrue("for (; throw 0;) {}"); | 1333 _assertTrue("for (; throw 0;) {}"); |
| 1332 } | 1334 } |
| 1333 | 1335 |
| 1334 void test_forStatement_implicitTrue() { | 1336 test_forStatement_implicitTrue() async { |
| 1335 _assertTrue("for (;;) {}"); | 1337 _assertTrue("for (;;) {}"); |
| 1336 } | 1338 } |
| 1337 | 1339 |
| 1338 void test_forStatement_implicitTrue_break() { | 1340 test_forStatement_implicitTrue_break() async { |
| 1339 _assertFalse("for (;;) { break; }"); | 1341 _assertFalse("for (;;) { break; }"); |
| 1340 } | 1342 } |
| 1341 | 1343 |
| 1342 void test_forStatement_implicitTrue_if_break() { | 1344 test_forStatement_implicitTrue_if_break() async { |
| 1343 _assertFalse("{ for (;;) { if (1==2) { var a = 1; } else { break; } } }"); | 1345 _assertFalse("{ for (;;) { if (1==2) { var a = 1; } else { break; } } }"); |
| 1344 } | 1346 } |
| 1345 | 1347 |
| 1346 void test_forStatement_initialization() { | 1348 test_forStatement_initialization() async { |
| 1347 _assertTrue("for (i = throw 0;;) {}"); | 1349 _assertTrue("for (i = throw 0;;) {}"); |
| 1348 } | 1350 } |
| 1349 | 1351 |
| 1350 void test_forStatement_true() { | 1352 test_forStatement_true() async { |
| 1351 _assertTrue("for (; true; ) {}"); | 1353 _assertTrue("for (; true; ) {}"); |
| 1352 } | 1354 } |
| 1353 | 1355 |
| 1354 void test_forStatement_true_break() { | 1356 test_forStatement_true_break() async { |
| 1355 _assertFalse("{ for (; true; ) { break; } }"); | 1357 _assertFalse("{ for (; true; ) { break; } }"); |
| 1356 } | 1358 } |
| 1357 | 1359 |
| 1358 void test_forStatement_true_continue() { | 1360 test_forStatement_true_continue() async { |
| 1359 _assertTrue("{ for (; true; ) { continue; } }"); | 1361 _assertTrue("{ for (; true; ) { continue; } }"); |
| 1360 } | 1362 } |
| 1361 | 1363 |
| 1362 void test_forStatement_true_if_return() { | 1364 test_forStatement_true_if_return() async { |
| 1363 _assertTrue("{ for (; true; ) { if (true) {return null;} } }"); | 1365 _assertTrue("{ for (; true; ) { if (true) {return null;} } }"); |
| 1364 } | 1366 } |
| 1365 | 1367 |
| 1366 void test_forStatement_true_noBreak() { | 1368 test_forStatement_true_noBreak() async { |
| 1367 _assertTrue("{ for (; true; ) {} }"); | 1369 _assertTrue("{ for (; true; ) {} }"); |
| 1368 } | 1370 } |
| 1369 | 1371 |
| 1370 void test_forStatement_updaters() { | 1372 test_forStatement_updaters() async { |
| 1371 _assertTrue("for (;; i++, throw 0) {}"); | 1373 _assertTrue("for (;; i++, throw 0) {}"); |
| 1372 } | 1374 } |
| 1373 | 1375 |
| 1374 void test_forStatement_variableDeclaration() { | 1376 test_forStatement_variableDeclaration() async { |
| 1375 _assertTrue("for (int i = throw 0;;) {}"); | 1377 _assertTrue("for (int i = throw 0;;) {}"); |
| 1376 } | 1378 } |
| 1377 | 1379 |
| 1378 void test_functionExpression() { | 1380 test_functionExpression() async { |
| 1379 _assertFalse("(){};"); | 1381 _assertFalse("(){};"); |
| 1380 } | 1382 } |
| 1381 | 1383 |
| 1382 void test_functionExpression_bodyThrows() { | 1384 test_functionExpression_bodyThrows() async { |
| 1383 _assertFalse("(int i) => throw '';"); | 1385 _assertFalse("(int i) => throw '';"); |
| 1384 } | 1386 } |
| 1385 | 1387 |
| 1386 void test_functionExpressionInvocation() { | 1388 test_functionExpressionInvocation() async { |
| 1387 _assertFalse("f(g);"); | 1389 _assertFalse("f(g);"); |
| 1388 } | 1390 } |
| 1389 | 1391 |
| 1390 void test_functionExpressionInvocation_argumentThrows() { | 1392 test_functionExpressionInvocation_argumentThrows() async { |
| 1391 _assertTrue("f(throw '');"); | 1393 _assertTrue("f(throw '');"); |
| 1392 } | 1394 } |
| 1393 | 1395 |
| 1394 void test_functionExpressionInvocation_targetThrows() { | 1396 test_functionExpressionInvocation_targetThrows() async { |
| 1395 _assertTrue("throw ''(g);"); | 1397 _assertTrue("throw ''(g);"); |
| 1396 } | 1398 } |
| 1397 | 1399 |
| 1398 void test_identifier_prefixedIdentifier() { | 1400 test_identifier_prefixedIdentifier() async { |
| 1399 _assertFalse("a.b;"); | 1401 _assertFalse("a.b;"); |
| 1400 } | 1402 } |
| 1401 | 1403 |
| 1402 void test_identifier_simpleIdentifier() { | 1404 test_identifier_simpleIdentifier() async { |
| 1403 _assertFalse("a;"); | 1405 _assertFalse("a;"); |
| 1404 } | 1406 } |
| 1405 | 1407 |
| 1406 void test_if_false_else_return() { | 1408 test_if_false_else_return() async { |
| 1407 _assertTrue("if (false) {} else { return 0; }"); | 1409 _assertTrue("if (false) {} else { return 0; }"); |
| 1408 } | 1410 } |
| 1409 | 1411 |
| 1410 void test_if_false_noReturn() { | 1412 test_if_false_noReturn() async { |
| 1411 _assertFalse("if (false) {}"); | 1413 _assertFalse("if (false) {}"); |
| 1412 } | 1414 } |
| 1413 | 1415 |
| 1414 void test_if_false_return() { | 1416 test_if_false_return() async { |
| 1415 _assertFalse("if (false) { return 0; }"); | 1417 _assertFalse("if (false) { return 0; }"); |
| 1416 } | 1418 } |
| 1417 | 1419 |
| 1418 void test_if_noReturn() { | 1420 test_if_noReturn() async { |
| 1419 _assertFalse("if (c) i++;"); | 1421 _assertFalse("if (c) i++;"); |
| 1420 } | 1422 } |
| 1421 | 1423 |
| 1422 void test_if_return() { | 1424 test_if_return() async { |
| 1423 _assertFalse("if (c) return 0;"); | 1425 _assertFalse("if (c) return 0;"); |
| 1424 } | 1426 } |
| 1425 | 1427 |
| 1426 void test_if_true_noReturn() { | 1428 test_if_true_noReturn() async { |
| 1427 _assertFalse("if (true) {}"); | 1429 _assertFalse("if (true) {}"); |
| 1428 } | 1430 } |
| 1429 | 1431 |
| 1430 void test_if_true_return() { | 1432 test_if_true_return() async { |
| 1431 _assertTrue("if (true) { return 0; }"); | 1433 _assertTrue("if (true) { return 0; }"); |
| 1432 } | 1434 } |
| 1433 | 1435 |
| 1434 void test_ifElse_bothReturn() { | 1436 test_ifElse_bothReturn() async { |
| 1435 _assertTrue("if (c) return 0; else return 1;"); | 1437 _assertTrue("if (c) return 0; else return 1;"); |
| 1436 } | 1438 } |
| 1437 | 1439 |
| 1438 void test_ifElse_elseReturn() { | 1440 test_ifElse_elseReturn() async { |
| 1439 _assertFalse("if (c) i++; else return 1;"); | 1441 _assertFalse("if (c) i++; else return 1;"); |
| 1440 } | 1442 } |
| 1441 | 1443 |
| 1442 void test_ifElse_noReturn() { | 1444 test_ifElse_noReturn() async { |
| 1443 _assertFalse("if (c) i++; else j++;"); | 1445 _assertFalse("if (c) i++; else j++;"); |
| 1444 } | 1446 } |
| 1445 | 1447 |
| 1446 void test_ifElse_thenReturn() { | 1448 test_ifElse_thenReturn() async { |
| 1447 _assertFalse("if (c) return 0; else j++;"); | 1449 _assertFalse("if (c) return 0; else j++;"); |
| 1448 } | 1450 } |
| 1449 | 1451 |
| 1450 void test_ifNullAssign() { | 1452 test_ifNullAssign() async { |
| 1451 _assertFalse("a ??= b;"); | 1453 _assertFalse("a ??= b;"); |
| 1452 } | 1454 } |
| 1453 | 1455 |
| 1454 void test_ifNullAssign_rhs() { | 1456 test_ifNullAssign_rhs() async { |
| 1455 _assertFalse("a ??= throw '';"); | 1457 _assertFalse("a ??= throw '';"); |
| 1456 } | 1458 } |
| 1457 | 1459 |
| 1458 void test_indexExpression() { | 1460 test_indexExpression() async { |
| 1459 _assertFalse("a[b];"); | 1461 _assertFalse("a[b];"); |
| 1460 } | 1462 } |
| 1461 | 1463 |
| 1462 void test_indexExpression_index() { | 1464 test_indexExpression_index() async { |
| 1463 _assertTrue("a[throw ''];"); | 1465 _assertTrue("a[throw ''];"); |
| 1464 } | 1466 } |
| 1465 | 1467 |
| 1466 void test_indexExpression_target() { | 1468 test_indexExpression_target() async { |
| 1467 _assertTrue("throw ''[b];"); | 1469 _assertTrue("throw ''[b];"); |
| 1468 } | 1470 } |
| 1469 | 1471 |
| 1470 void test_instanceCreationExpression() { | 1472 test_instanceCreationExpression() async { |
| 1471 _assertFalse("new A(b);"); | 1473 _assertFalse("new A(b);"); |
| 1472 } | 1474 } |
| 1473 | 1475 |
| 1474 void test_instanceCreationExpression_argumentThrows() { | 1476 test_instanceCreationExpression_argumentThrows() async { |
| 1475 _assertTrue("new A(throw '');"); | 1477 _assertTrue("new A(throw '');"); |
| 1476 } | 1478 } |
| 1477 | 1479 |
| 1478 void test_isExpression() { | 1480 test_isExpression() async { |
| 1479 _assertFalse("A is B;"); | 1481 _assertFalse("A is B;"); |
| 1480 } | 1482 } |
| 1481 | 1483 |
| 1482 void test_isExpression_throws() { | 1484 test_isExpression_throws() async { |
| 1483 _assertTrue("throw '' is B;"); | 1485 _assertTrue("throw '' is B;"); |
| 1484 } | 1486 } |
| 1485 | 1487 |
| 1486 void test_labeledStatement() { | 1488 test_labeledStatement() async { |
| 1487 _assertFalse("label: a;"); | 1489 _assertFalse("label: a;"); |
| 1488 } | 1490 } |
| 1489 | 1491 |
| 1490 void test_labeledStatement_throws() { | 1492 test_labeledStatement_throws() async { |
| 1491 _assertTrue("label: throw '';"); | 1493 _assertTrue("label: throw '';"); |
| 1492 } | 1494 } |
| 1493 | 1495 |
| 1494 void test_literal_boolean() { | 1496 test_literal_boolean() async { |
| 1495 _assertFalse("true;"); | 1497 _assertFalse("true;"); |
| 1496 } | 1498 } |
| 1497 | 1499 |
| 1498 void test_literal_double() { | 1500 test_literal_double() async { |
| 1499 _assertFalse("1.1;"); | 1501 _assertFalse("1.1;"); |
| 1500 } | 1502 } |
| 1501 | 1503 |
| 1502 void test_literal_integer() { | 1504 test_literal_integer() async { |
| 1503 _assertFalse("1;"); | 1505 _assertFalse("1;"); |
| 1504 } | 1506 } |
| 1505 | 1507 |
| 1506 void test_literal_null() { | 1508 test_literal_null() async { |
| 1507 _assertFalse("null;"); | 1509 _assertFalse("null;"); |
| 1508 } | 1510 } |
| 1509 | 1511 |
| 1510 void test_literal_String() { | 1512 test_literal_String() async { |
| 1511 _assertFalse("'str';"); | 1513 _assertFalse("'str';"); |
| 1512 } | 1514 } |
| 1513 | 1515 |
| 1514 void test_methodInvocation() { | 1516 test_methodInvocation() async { |
| 1515 _assertFalse("a.b(c);"); | 1517 _assertFalse("a.b(c);"); |
| 1516 } | 1518 } |
| 1517 | 1519 |
| 1518 void test_methodInvocation_argument() { | 1520 test_methodInvocation_argument() async { |
| 1519 _assertTrue("a.b(throw '');"); | 1521 _assertTrue("a.b(throw '');"); |
| 1520 } | 1522 } |
| 1521 | 1523 |
| 1522 void test_methodInvocation_target() { | 1524 test_methodInvocation_target() async { |
| 1523 _assertTrue("throw ''.b(c);"); | 1525 _assertTrue("throw ''.b(c);"); |
| 1524 } | 1526 } |
| 1525 | 1527 |
| 1526 void test_parenthesizedExpression() { | 1528 test_parenthesizedExpression() async { |
| 1527 _assertFalse("(a);"); | 1529 _assertFalse("(a);"); |
| 1528 } | 1530 } |
| 1529 | 1531 |
| 1530 void test_parenthesizedExpression_throw() { | 1532 test_parenthesizedExpression_throw() async { |
| 1531 _assertTrue("(throw '');"); | 1533 _assertTrue("(throw '');"); |
| 1532 } | 1534 } |
| 1533 | 1535 |
| 1534 void test_propertyAccess() { | 1536 test_propertyAccess() async { |
| 1535 _assertFalse("new Object().a;"); | 1537 _assertFalse("new Object().a;"); |
| 1536 } | 1538 } |
| 1537 | 1539 |
| 1538 void test_propertyAccess_throws() { | 1540 test_propertyAccess_throws() async { |
| 1539 _assertTrue("(throw '').a;"); | 1541 _assertTrue("(throw '').a;"); |
| 1540 } | 1542 } |
| 1541 | 1543 |
| 1542 void test_rethrow() { | 1544 test_rethrow() async { |
| 1543 _assertTrue("rethrow;"); | 1545 _assertTrue("rethrow;"); |
| 1544 } | 1546 } |
| 1545 | 1547 |
| 1546 void test_return() { | 1548 test_return() async { |
| 1547 _assertTrue("return 0;"); | 1549 _assertTrue("return 0;"); |
| 1548 } | 1550 } |
| 1549 | 1551 |
| 1550 void test_superExpression() { | 1552 test_superExpression() async { |
| 1551 _assertFalse("super.a;"); | 1553 _assertFalse("super.a;"); |
| 1552 } | 1554 } |
| 1553 | 1555 |
| 1554 void test_switch_allReturn() { | 1556 test_switch_allReturn() async { |
| 1555 _assertTrue("switch (i) { case 0: return 0; default: return 1; }"); | 1557 _assertTrue("switch (i) { case 0: return 0; default: return 1; }"); |
| 1556 } | 1558 } |
| 1557 | 1559 |
| 1558 void test_switch_defaultWithNoStatements() { | 1560 test_switch_defaultWithNoStatements() async { |
| 1559 _assertFalse("switch (i) { case 0: return 0; default: }"); | 1561 _assertFalse("switch (i) { case 0: return 0; default: }"); |
| 1560 } | 1562 } |
| 1561 | 1563 |
| 1562 void test_switch_fallThroughToNotReturn() { | 1564 test_switch_fallThroughToNotReturn() async { |
| 1563 _assertFalse("switch (i) { case 0: case 1: break; default: return 1; }"); | 1565 _assertFalse("switch (i) { case 0: case 1: break; default: return 1; }"); |
| 1564 } | 1566 } |
| 1565 | 1567 |
| 1566 void test_switch_fallThroughToReturn() { | 1568 test_switch_fallThroughToReturn() async { |
| 1567 _assertTrue("switch (i) { case 0: case 1: return 0; default: return 1; }"); | 1569 _assertTrue("switch (i) { case 0: case 1: return 0; default: return 1; }"); |
| 1568 } | 1570 } |
| 1569 | 1571 |
| 1570 // The ExitDetector could conceivably follow switch continue labels and | 1572 // The ExitDetector could conceivably follow switch continue labels and |
| 1571 // determine that `case 0` exits, `case 1` continues to an exiting case, and | 1573 // determine that `case 0` exits, `case 1` continues to an exiting case, and |
| 1572 // `default` exits, so the switch exits. | 1574 // `default` exits, so the switch exits. |
| 1573 @failingTest | 1575 @failingTest |
| 1574 void test_switch_includesContinue() { | 1576 test_switch_includesContinue() async { |
| 1575 _assertTrue(''' | 1577 _assertTrue(''' |
| 1576 switch (i) { | 1578 switch (i) { |
| 1577 zero: case 0: return 0; | 1579 zero: case 0: return 0; |
| 1578 case 1: continue zero; | 1580 case 1: continue zero; |
| 1579 default: return 1; | 1581 default: return 1; |
| 1580 }'''); | 1582 }'''); |
| 1581 } | 1583 } |
| 1582 | 1584 |
| 1583 void test_switch_noDefault() { | 1585 test_switch_noDefault() async { |
| 1584 _assertFalse("switch (i) { case 0: return 0; }"); | 1586 _assertFalse("switch (i) { case 0: return 0; }"); |
| 1585 } | 1587 } |
| 1586 | 1588 |
| 1587 void test_switch_nonReturn() { | 1589 test_switch_nonReturn() async { |
| 1588 _assertFalse("switch (i) { case 0: i++; default: return 1; }"); | 1590 _assertFalse("switch (i) { case 0: i++; default: return 1; }"); |
| 1589 } | 1591 } |
| 1590 | 1592 |
| 1591 void test_thisExpression() { | 1593 test_thisExpression() async { |
| 1592 _assertFalse("this.a;"); | 1594 _assertFalse("this.a;"); |
| 1593 } | 1595 } |
| 1594 | 1596 |
| 1595 void test_throwExpression() { | 1597 test_throwExpression() async { |
| 1596 _assertTrue("throw new Object();"); | 1598 _assertTrue("throw new Object();"); |
| 1597 } | 1599 } |
| 1598 | 1600 |
| 1599 void test_tryStatement_noReturn() { | 1601 test_tryStatement_noReturn() async { |
| 1600 _assertFalse("try {} catch (e, s) {} finally {}"); | 1602 _assertFalse("try {} catch (e, s) {} finally {}"); |
| 1601 } | 1603 } |
| 1602 | 1604 |
| 1603 void test_tryStatement_noReturn_noFinally() { | 1605 test_tryStatement_noReturn_noFinally() async { |
| 1604 _assertFalse("try {} catch (e, s) {}"); | 1606 _assertFalse("try {} catch (e, s) {}"); |
| 1605 } | 1607 } |
| 1606 | 1608 |
| 1607 void test_tryStatement_return_catch() { | 1609 test_tryStatement_return_catch() async { |
| 1608 _assertFalse("try {} catch (e, s) { return 1; } finally {}"); | 1610 _assertFalse("try {} catch (e, s) { return 1; } finally {}"); |
| 1609 } | 1611 } |
| 1610 | 1612 |
| 1611 void test_tryStatement_return_catch_noFinally() { | 1613 test_tryStatement_return_catch_noFinally() async { |
| 1612 _assertFalse("try {} catch (e, s) { return 1; }"); | 1614 _assertFalse("try {} catch (e, s) { return 1; }"); |
| 1613 } | 1615 } |
| 1614 | 1616 |
| 1615 void test_tryStatement_return_finally() { | 1617 test_tryStatement_return_finally() async { |
| 1616 _assertTrue("try {} catch (e, s) {} finally { return 1; }"); | 1618 _assertTrue("try {} catch (e, s) {} finally { return 1; }"); |
| 1617 } | 1619 } |
| 1618 | 1620 |
| 1619 void test_tryStatement_return_try_noCatch() { | 1621 test_tryStatement_return_try_noCatch() async { |
| 1620 _assertTrue("try { return 1; } finally {}"); | 1622 _assertTrue("try { return 1; } finally {}"); |
| 1621 } | 1623 } |
| 1622 | 1624 |
| 1623 void test_tryStatement_return_try_oneCatchDoesNotExit() { | 1625 test_tryStatement_return_try_oneCatchDoesNotExit() async { |
| 1624 _assertFalse("try { return 1; } catch (e, s) {} finally {}"); | 1626 _assertFalse("try { return 1; } catch (e, s) {} finally {}"); |
| 1625 } | 1627 } |
| 1626 | 1628 |
| 1627 void test_tryStatement_return_try_oneCatchDoesNotExit_noFinally() { | 1629 test_tryStatement_return_try_oneCatchDoesNotExit_noFinally() async { |
| 1628 _assertFalse("try { return 1; } catch (e, s) {}"); | 1630 _assertFalse("try { return 1; } catch (e, s) {}"); |
| 1629 } | 1631 } |
| 1630 | 1632 |
| 1631 void test_tryStatement_return_try_oneCatchExits() { | 1633 test_tryStatement_return_try_oneCatchExits() async { |
| 1632 _assertTrue("try { return 1; } catch (e, s) { return 1; } finally {}"); | 1634 _assertTrue("try { return 1; } catch (e, s) { return 1; } finally {}"); |
| 1633 } | 1635 } |
| 1634 | 1636 |
| 1635 void test_tryStatement_return_try_oneCatchExits_noFinally() { | 1637 test_tryStatement_return_try_oneCatchExits_noFinally() async { |
| 1636 _assertTrue("try { return 1; } catch (e, s) { return 1; }"); | 1638 _assertTrue("try { return 1; } catch (e, s) { return 1; }"); |
| 1637 } | 1639 } |
| 1638 | 1640 |
| 1639 void test_tryStatement_return_try_twoCatchesDoExit() { | 1641 test_tryStatement_return_try_twoCatchesDoExit() async { |
| 1640 _assertTrue(''' | 1642 _assertTrue(''' |
| 1641 try { return 1; } | 1643 try { return 1; } |
| 1642 on int catch (e, s) { return 1; } | 1644 on int catch (e, s) { return 1; } |
| 1643 on String catch (e, s) { return 1; } | 1645 on String catch (e, s) { return 1; } |
| 1644 finally {}'''); | 1646 finally {}'''); |
| 1645 } | 1647 } |
| 1646 | 1648 |
| 1647 void test_tryStatement_return_try_twoCatchesDoExit_noFinally() { | 1649 test_tryStatement_return_try_twoCatchesDoExit_noFinally() async { |
| 1648 _assertTrue(''' | 1650 _assertTrue(''' |
| 1649 try { return 1; } | 1651 try { return 1; } |
| 1650 on int catch (e, s) { return 1; } | 1652 on int catch (e, s) { return 1; } |
| 1651 on String catch (e, s) { return 1; }'''); | 1653 on String catch (e, s) { return 1; }'''); |
| 1652 } | 1654 } |
| 1653 | 1655 |
| 1654 void test_tryStatement_return_try_twoCatchesDoNotExit() { | 1656 test_tryStatement_return_try_twoCatchesDoNotExit() async { |
| 1655 _assertFalse(''' | 1657 _assertFalse(''' |
| 1656 try { return 1; } | 1658 try { return 1; } |
| 1657 on int catch (e, s) {} | 1659 on int catch (e, s) {} |
| 1658 on String catch (e, s) {} | 1660 on String catch (e, s) {} |
| 1659 finally {}'''); | 1661 finally {}'''); |
| 1660 } | 1662 } |
| 1661 | 1663 |
| 1662 void test_tryStatement_return_try_twoCatchesDoNotExit_noFinally() { | 1664 test_tryStatement_return_try_twoCatchesDoNotExit_noFinally() async { |
| 1663 _assertFalse(''' | 1665 _assertFalse(''' |
| 1664 try { return 1; } | 1666 try { return 1; } |
| 1665 on int catch (e, s) {} | 1667 on int catch (e, s) {} |
| 1666 on String catch (e, s) {}'''); | 1668 on String catch (e, s) {}'''); |
| 1667 } | 1669 } |
| 1668 | 1670 |
| 1669 void test_tryStatement_return_try_twoCatchesMixed() { | 1671 test_tryStatement_return_try_twoCatchesMixed() async { |
| 1670 _assertFalse(''' | 1672 _assertFalse(''' |
| 1671 try { return 1; } | 1673 try { return 1; } |
| 1672 on int catch (e, s) {} | 1674 on int catch (e, s) {} |
| 1673 on String catch (e, s) { return 1; } | 1675 on String catch (e, s) { return 1; } |
| 1674 finally {}'''); | 1676 finally {}'''); |
| 1675 } | 1677 } |
| 1676 | 1678 |
| 1677 void test_tryStatement_return_try_twoCatchesMixed_noFinally() { | 1679 test_tryStatement_return_try_twoCatchesMixed_noFinally() async { |
| 1678 _assertFalse(''' | 1680 _assertFalse(''' |
| 1679 try { return 1; } | 1681 try { return 1; } |
| 1680 on int catch (e, s) {} | 1682 on int catch (e, s) {} |
| 1681 on String catch (e, s) { return 1; }'''); | 1683 on String catch (e, s) { return 1; }'''); |
| 1682 } | 1684 } |
| 1683 | 1685 |
| 1684 void test_variableDeclarationStatement_noInitializer() { | 1686 test_variableDeclarationStatement_noInitializer() async { |
| 1685 _assertFalse("int i;"); | 1687 _assertFalse("int i;"); |
| 1686 } | 1688 } |
| 1687 | 1689 |
| 1688 void test_variableDeclarationStatement_noThrow() { | 1690 test_variableDeclarationStatement_noThrow() async { |
| 1689 _assertFalse("int i = 0;"); | 1691 _assertFalse("int i = 0;"); |
| 1690 } | 1692 } |
| 1691 | 1693 |
| 1692 void test_variableDeclarationStatement_throw() { | 1694 test_variableDeclarationStatement_throw() async { |
| 1693 _assertTrue("int i = throw new Object();"); | 1695 _assertTrue("int i = throw new Object();"); |
| 1694 } | 1696 } |
| 1695 | 1697 |
| 1696 void test_whileStatement_false_nonReturn() { | 1698 test_whileStatement_false_nonReturn() async { |
| 1697 _assertFalse("{ while (false) {} }"); | 1699 _assertFalse("{ while (false) {} }"); |
| 1698 } | 1700 } |
| 1699 | 1701 |
| 1700 void test_whileStatement_throwCondition() { | 1702 test_whileStatement_throwCondition() async { |
| 1701 _assertTrue("{ while (throw '') {} }"); | 1703 _assertTrue("{ while (throw '') {} }"); |
| 1702 } | 1704 } |
| 1703 | 1705 |
| 1704 void test_whileStatement_true_break() { | 1706 test_whileStatement_true_break() async { |
| 1705 _assertFalse("{ while (true) { break; } }"); | 1707 _assertFalse("{ while (true) { break; } }"); |
| 1706 } | 1708 } |
| 1707 | 1709 |
| 1708 void test_whileStatement_true_break_and_throw() { | 1710 test_whileStatement_true_break_and_throw() async { |
| 1709 _assertFalse("{ while (true) { if (1==1) break; throw 'T'; } }"); | 1711 _assertFalse("{ while (true) { if (1==1) break; throw 'T'; } }"); |
| 1710 } | 1712 } |
| 1711 | 1713 |
| 1712 void test_whileStatement_true_continue() { | 1714 test_whileStatement_true_continue() async { |
| 1713 _assertTrue("{ while (true) { continue; } }"); | 1715 _assertTrue("{ while (true) { continue; } }"); |
| 1714 } | 1716 } |
| 1715 | 1717 |
| 1716 void test_whileStatement_true_continueWithLabel() { | 1718 test_whileStatement_true_continueWithLabel() async { |
| 1717 _assertTrue("{ x: while (true) { continue x; } }"); | 1719 _assertTrue("{ x: while (true) { continue x; } }"); |
| 1718 } | 1720 } |
| 1719 | 1721 |
| 1720 void test_whileStatement_true_doStatement_scopeRequired() { | 1722 test_whileStatement_true_doStatement_scopeRequired() async { |
| 1721 _assertTrue("{ while (true) { x: do { continue x; } while (true); } }"); | 1723 _assertTrue("{ while (true) { x: do { continue x; } while (true); } }"); |
| 1722 } | 1724 } |
| 1723 | 1725 |
| 1724 void test_whileStatement_true_if_return() { | 1726 test_whileStatement_true_if_return() async { |
| 1725 _assertTrue("{ while (true) { if (true) {return null;} } }"); | 1727 _assertTrue("{ while (true) { if (true) {return null;} } }"); |
| 1726 } | 1728 } |
| 1727 | 1729 |
| 1728 void test_whileStatement_true_noBreak() { | 1730 test_whileStatement_true_noBreak() async { |
| 1729 _assertTrue("{ while (true) {} }"); | 1731 _assertTrue("{ while (true) {} }"); |
| 1730 } | 1732 } |
| 1731 | 1733 |
| 1732 void test_whileStatement_true_return() { | 1734 test_whileStatement_true_return() async { |
| 1733 _assertTrue("{ while (true) { return null; } }"); | 1735 _assertTrue("{ while (true) { return null; } }"); |
| 1734 } | 1736 } |
| 1735 | 1737 |
| 1736 void test_whileStatement_true_throw() { | 1738 test_whileStatement_true_throw() async { |
| 1737 _assertTrue("{ while (true) { throw ''; } }"); | 1739 _assertTrue("{ while (true) { throw ''; } }"); |
| 1738 } | 1740 } |
| 1739 | 1741 |
| 1740 void _assertFalse(String source) { | 1742 void _assertFalse(String source) { |
| 1741 _assertHasReturn(false, source); | 1743 _assertHasReturn(false, source); |
| 1742 } | 1744 } |
| 1743 | 1745 |
| 1744 void _assertHasReturn(bool expectedResult, String source) { | 1746 void _assertHasReturn(bool expectedResult, String source) { |
| 1745 Statement statement = ParserTestCase.parseStatement( | 1747 Statement statement = ParserTestCase.parseStatement( |
| 1746 source, [], enableLazyAssignmentOperators); | 1748 source, [], enableLazyAssignmentOperators); |
| 1747 expect(ExitDetector.exits(statement), expectedResult); | 1749 expect(ExitDetector.exits(statement), expectedResult); |
| 1748 } | 1750 } |
| 1749 | 1751 |
| 1750 void _assertTrue(String source) { | 1752 void _assertTrue(String source) { |
| 1751 _assertHasReturn(true, source); | 1753 _assertHasReturn(true, source); |
| 1752 } | 1754 } |
| 1753 } | 1755 } |
| 1754 | 1756 |
| 1755 /** | 1757 /** |
| 1756 * Tests for the [ExitDetector] that require that the AST be resolved. | 1758 * Tests for the [ExitDetector] that require that the AST be resolved. |
| 1757 * | 1759 * |
| 1758 * See [ExitDetectorTest] for tests that do not require the AST to be resolved. | 1760 * See [ExitDetectorTest] for tests that do not require the AST to be resolved. |
| 1759 */ | 1761 */ |
| 1760 @reflectiveTest | 1762 @reflectiveTest |
| 1761 class ExitDetectorTest2 extends ResolverTestCase { | 1763 class ExitDetectorTest2 extends ResolverTestCase { |
| 1762 void test_forStatement_implicitTrue_breakWithLabel() { | 1764 test_forStatement_implicitTrue_breakWithLabel() async { |
| 1763 Source source = addSource(r''' | 1765 Source source = addSource(r''' |
| 1764 void f() { | 1766 void f() { |
| 1765 x: for (;;) { | 1767 x: for (;;) { |
| 1766 if (1 < 2) { | 1768 if (1 < 2) { |
| 1767 break x; | 1769 break x; |
| 1768 } | 1770 } |
| 1769 return; | 1771 return; |
| 1770 } | 1772 } |
| 1771 } | 1773 } |
| 1772 '''); | 1774 '''); |
| 1773 _assertNthStatementDoesNotExit(source, 0); | 1775 _assertNthStatementDoesNotExit(source, 0); |
| 1774 } | 1776 } |
| 1775 | 1777 |
| 1776 void test_switch_withEnum_false_noDefault() { | 1778 test_switch_withEnum_false_noDefault() async { |
| 1777 Source source = addSource(r''' | 1779 Source source = addSource(r''' |
| 1778 enum E { A, B } | 1780 enum E { A, B } |
| 1779 String f(E e) { | 1781 String f(E e) { |
| 1780 var x; | 1782 var x; |
| 1781 switch (e) { | 1783 switch (e) { |
| 1782 case A: | 1784 case A: |
| 1783 x = 'A'; | 1785 x = 'A'; |
| 1784 case B: | 1786 case B: |
| 1785 x = 'B'; | 1787 x = 'B'; |
| 1786 } | 1788 } |
| 1787 return x; | 1789 return x; |
| 1788 } | 1790 } |
| 1789 '''); | 1791 '''); |
| 1790 _assertNthStatementDoesNotExit(source, 1); | 1792 _assertNthStatementDoesNotExit(source, 1); |
| 1791 } | 1793 } |
| 1792 | 1794 |
| 1793 void test_switch_withEnum_false_withDefault() { | 1795 test_switch_withEnum_false_withDefault() async { |
| 1794 Source source = addSource(r''' | 1796 Source source = addSource(r''' |
| 1795 enum E { A, B } | 1797 enum E { A, B } |
| 1796 String f(E e) { | 1798 String f(E e) { |
| 1797 var x; | 1799 var x; |
| 1798 switch (e) { | 1800 switch (e) { |
| 1799 case A: | 1801 case A: |
| 1800 x = 'A'; | 1802 x = 'A'; |
| 1801 default: | 1803 default: |
| 1802 x = '?'; | 1804 x = '?'; |
| 1803 } | 1805 } |
| 1804 return x; | 1806 return x; |
| 1805 } | 1807 } |
| 1806 '''); | 1808 '''); |
| 1807 _assertNthStatementDoesNotExit(source, 1); | 1809 _assertNthStatementDoesNotExit(source, 1); |
| 1808 } | 1810 } |
| 1809 | 1811 |
| 1810 void test_switch_withEnum_true_noDefault() { | 1812 test_switch_withEnum_true_noDefault() async { |
| 1811 Source source = addSource(r''' | 1813 Source source = addSource(r''' |
| 1812 enum E { A, B } | 1814 enum E { A, B } |
| 1813 String f(E e) { | 1815 String f(E e) { |
| 1814 switch (e) { | 1816 switch (e) { |
| 1815 case A: | 1817 case A: |
| 1816 return 'A'; | 1818 return 'A'; |
| 1817 case B: | 1819 case B: |
| 1818 return 'B'; | 1820 return 'B'; |
| 1819 } | 1821 } |
| 1820 } | 1822 } |
| 1821 '''); | 1823 '''); |
| 1822 _assertNthStatementDoesNotExit(source, 0); | 1824 _assertNthStatementDoesNotExit(source, 0); |
| 1823 } | 1825 } |
| 1824 | 1826 |
| 1825 void test_switch_withEnum_true_withExitingDefault() { | 1827 test_switch_withEnum_true_withExitingDefault() async { |
| 1826 Source source = addSource(r''' | 1828 Source source = addSource(r''' |
| 1827 enum E { A, B } | 1829 enum E { A, B } |
| 1828 String f(E e) { | 1830 String f(E e) { |
| 1829 switch (e) { | 1831 switch (e) { |
| 1830 case A: | 1832 case A: |
| 1831 return 'A'; | 1833 return 'A'; |
| 1832 default: | 1834 default: |
| 1833 return '?'; | 1835 return '?'; |
| 1834 } | 1836 } |
| 1835 } | 1837 } |
| 1836 '''); | 1838 '''); |
| 1837 _assertNthStatementExits(source, 0); | 1839 _assertNthStatementExits(source, 0); |
| 1838 } | 1840 } |
| 1839 | 1841 |
| 1840 void test_switch_withEnum_true_withNonExitingDefault() { | 1842 test_switch_withEnum_true_withNonExitingDefault() async { |
| 1841 Source source = addSource(r''' | 1843 Source source = addSource(r''' |
| 1842 enum E { A, B } | 1844 enum E { A, B } |
| 1843 String f(E e) { | 1845 String f(E e) { |
| 1844 var x; | 1846 var x; |
| 1845 switch (e) { | 1847 switch (e) { |
| 1846 case A: | 1848 case A: |
| 1847 return 'A'; | 1849 return 'A'; |
| 1848 default: | 1850 default: |
| 1849 x = '?'; | 1851 x = '?'; |
| 1850 } | 1852 } |
| 1851 } | 1853 } |
| 1852 '''); | 1854 '''); |
| 1853 _assertNthStatementDoesNotExit(source, 1); | 1855 _assertNthStatementDoesNotExit(source, 1); |
| 1854 } | 1856 } |
| 1855 | 1857 |
| 1856 void test_whileStatement_breakWithLabel() { | 1858 test_whileStatement_breakWithLabel() async { |
| 1857 Source source = addSource(r''' | 1859 Source source = addSource(r''' |
| 1858 void f() { | 1860 void f() { |
| 1859 x: while (true) { | 1861 x: while (true) { |
| 1860 if (1 < 2) { | 1862 if (1 < 2) { |
| 1861 break x; | 1863 break x; |
| 1862 } | 1864 } |
| 1863 return; | 1865 return; |
| 1864 } | 1866 } |
| 1865 } | 1867 } |
| 1866 '''); | 1868 '''); |
| 1867 _assertNthStatementDoesNotExit(source, 0); | 1869 _assertNthStatementDoesNotExit(source, 0); |
| 1868 } | 1870 } |
| 1869 | 1871 |
| 1870 void test_whileStatement_breakWithLabel_afterExiting() { | 1872 test_whileStatement_breakWithLabel_afterExiting() async { |
| 1871 Source source = addSource(r''' | 1873 Source source = addSource(r''' |
| 1872 void f() { | 1874 void f() { |
| 1873 x: while (true) { | 1875 x: while (true) { |
| 1874 return; | 1876 return; |
| 1875 if (1 < 2) { | 1877 if (1 < 2) { |
| 1876 break x; | 1878 break x; |
| 1877 } | 1879 } |
| 1878 } | 1880 } |
| 1879 } | 1881 } |
| 1880 '''); | 1882 '''); |
| 1881 _assertNthStatementExits(source, 0); | 1883 _assertNthStatementExits(source, 0); |
| 1882 } | 1884 } |
| 1883 | 1885 |
| 1884 void test_whileStatement_switchWithBreakWithLabel() { | 1886 test_whileStatement_switchWithBreakWithLabel() async { |
| 1885 Source source = addSource(r''' | 1887 Source source = addSource(r''' |
| 1886 void f() { | 1888 void f() { |
| 1887 x: while (true) { | 1889 x: while (true) { |
| 1888 switch (true) { | 1890 switch (true) { |
| 1889 case false: break; | 1891 case false: break; |
| 1890 case true: break x; | 1892 case true: break x; |
| 1891 } | 1893 } |
| 1892 } | 1894 } |
| 1893 } | 1895 } |
| 1894 '''); | 1896 '''); |
| 1895 _assertNthStatementDoesNotExit(source, 0); | 1897 _assertNthStatementDoesNotExit(source, 0); |
| 1896 } | 1898 } |
| 1897 | 1899 |
| 1898 void test_yieldStatement_plain() { | 1900 test_yieldStatement_plain() async { |
| 1899 Source source = addSource(r''' | 1901 Source source = addSource(r''' |
| 1900 void f() sync* { | 1902 void f() sync* { |
| 1901 yield 1; | 1903 yield 1; |
| 1902 } | 1904 } |
| 1903 '''); | 1905 '''); |
| 1904 _assertNthStatementDoesNotExit(source, 0); | 1906 _assertNthStatementDoesNotExit(source, 0); |
| 1905 } | 1907 } |
| 1906 | 1908 |
| 1907 void test_yieldStatement_star_plain() { | 1909 test_yieldStatement_star_plain() async { |
| 1908 Source source = addSource(r''' | 1910 Source source = addSource(r''' |
| 1909 void f() sync* { | 1911 void f() sync* { |
| 1910 yield* 1; | 1912 yield* 1; |
| 1911 } | 1913 } |
| 1912 '''); | 1914 '''); |
| 1913 _assertNthStatementDoesNotExit(source, 0); | 1915 _assertNthStatementDoesNotExit(source, 0); |
| 1914 } | 1916 } |
| 1915 | 1917 |
| 1916 void test_yieldStatement_star_throw() { | 1918 test_yieldStatement_star_throw() async { |
| 1917 Source source = addSource(r''' | 1919 Source source = addSource(r''' |
| 1918 void f() sync* { | 1920 void f() sync* { |
| 1919 yield* throw ''; | 1921 yield* throw ''; |
| 1920 } | 1922 } |
| 1921 '''); | 1923 '''); |
| 1922 _assertNthStatementExits(source, 0); | 1924 _assertNthStatementExits(source, 0); |
| 1923 } | 1925 } |
| 1924 | 1926 |
| 1925 void test_yieldStatement_throw() { | 1927 test_yieldStatement_throw() async { |
| 1926 Source source = addSource(r''' | 1928 Source source = addSource(r''' |
| 1927 void f() sync* { | 1929 void f() sync* { |
| 1928 yield throw ''; | 1930 yield throw ''; |
| 1929 } | 1931 } |
| 1930 '''); | 1932 '''); |
| 1931 _assertNthStatementExits(source, 0); | 1933 _assertNthStatementExits(source, 0); |
| 1932 } | 1934 } |
| 1933 | 1935 |
| 1934 void _assertHasReturn(bool expectedResult, Source source, int n) { | 1936 void _assertHasReturn(bool expectedResult, Source source, int n) { |
| 1935 LibraryElement element = resolve2(source); | 1937 LibraryElement element = resolve2(source); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1948 | 1950 |
| 1949 // Assert that the [n]th statement in the last function declaration of | 1951 // Assert that the [n]th statement in the last function declaration of |
| 1950 // [source] does not exit. | 1952 // [source] does not exit. |
| 1951 void _assertNthStatementExits(Source source, int n) { | 1953 void _assertNthStatementExits(Source source, int n) { |
| 1952 _assertHasReturn(true, source, n); | 1954 _assertHasReturn(true, source, n); |
| 1953 } | 1955 } |
| 1954 } | 1956 } |
| 1955 | 1957 |
| 1956 @reflectiveTest | 1958 @reflectiveTest |
| 1957 class FileBasedSourceTest { | 1959 class FileBasedSourceTest { |
| 1958 void test_equals_false_differentFiles() { | 1960 test_equals_false_differentFiles() async { |
| 1959 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart"); | 1961 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart"); |
| 1960 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart"); | 1962 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart"); |
| 1961 FileBasedSource source1 = new FileBasedSource(file1); | 1963 FileBasedSource source1 = new FileBasedSource(file1); |
| 1962 FileBasedSource source2 = new FileBasedSource(file2); | 1964 FileBasedSource source2 = new FileBasedSource(file2); |
| 1963 expect(source1 == source2, isFalse); | 1965 expect(source1 == source2, isFalse); |
| 1964 } | 1966 } |
| 1965 | 1967 |
| 1966 void test_equals_false_null() { | 1968 test_equals_false_null() async { |
| 1967 JavaFile file = FileUtilities2.createFile("/does/not/exist1.dart"); | 1969 JavaFile file = FileUtilities2.createFile("/does/not/exist1.dart"); |
| 1968 FileBasedSource source1 = new FileBasedSource(file); | 1970 FileBasedSource source1 = new FileBasedSource(file); |
| 1969 expect(source1 == null, isFalse); | 1971 expect(source1 == null, isFalse); |
| 1970 } | 1972 } |
| 1971 | 1973 |
| 1972 void test_equals_true() { | 1974 test_equals_true() async { |
| 1973 JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart"); | 1975 JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart"); |
| 1974 JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart"); | 1976 JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart"); |
| 1975 FileBasedSource source1 = new FileBasedSource(file1); | 1977 FileBasedSource source1 = new FileBasedSource(file1); |
| 1976 FileBasedSource source2 = new FileBasedSource(file2); | 1978 FileBasedSource source2 = new FileBasedSource(file2); |
| 1977 expect(source1 == source2, isTrue); | 1979 expect(source1 == source2, isTrue); |
| 1978 } | 1980 } |
| 1979 | 1981 |
| 1980 void test_fileReadMode() { | 1982 test_fileReadMode() async { |
| 1981 expect(FileBasedSource.fileReadMode('a'), 'a'); | 1983 expect(FileBasedSource.fileReadMode('a'), 'a'); |
| 1982 expect(FileBasedSource.fileReadMode('a\n'), 'a\n'); | 1984 expect(FileBasedSource.fileReadMode('a\n'), 'a\n'); |
| 1983 expect(FileBasedSource.fileReadMode('ab'), 'ab'); | 1985 expect(FileBasedSource.fileReadMode('ab'), 'ab'); |
| 1984 expect(FileBasedSource.fileReadMode('abc'), 'abc'); | 1986 expect(FileBasedSource.fileReadMode('abc'), 'abc'); |
| 1985 expect(FileBasedSource.fileReadMode('a\nb'), 'a\nb'); | 1987 expect(FileBasedSource.fileReadMode('a\nb'), 'a\nb'); |
| 1986 expect(FileBasedSource.fileReadMode('a\rb'), 'a\rb'); | 1988 expect(FileBasedSource.fileReadMode('a\rb'), 'a\rb'); |
| 1987 expect(FileBasedSource.fileReadMode('a\r\nb'), 'a\r\nb'); | 1989 expect(FileBasedSource.fileReadMode('a\r\nb'), 'a\r\nb'); |
| 1988 } | 1990 } |
| 1989 | 1991 |
| 1990 void test_fileReadMode_changed() { | 1992 test_fileReadMode_changed() async { |
| 1991 FileBasedSource.fileReadMode = (String s) => s + 'xyz'; | 1993 FileBasedSource.fileReadMode = (String s) => s + 'xyz'; |
| 1992 expect(FileBasedSource.fileReadMode('a'), 'axyz'); | 1994 expect(FileBasedSource.fileReadMode('a'), 'axyz'); |
| 1993 expect(FileBasedSource.fileReadMode('a\n'), 'a\nxyz'); | 1995 expect(FileBasedSource.fileReadMode('a\n'), 'a\nxyz'); |
| 1994 expect(FileBasedSource.fileReadMode('ab'), 'abxyz'); | 1996 expect(FileBasedSource.fileReadMode('ab'), 'abxyz'); |
| 1995 expect(FileBasedSource.fileReadMode('abc'), 'abcxyz'); | 1997 expect(FileBasedSource.fileReadMode('abc'), 'abcxyz'); |
| 1996 FileBasedSource.fileReadMode = (String s) => s; | 1998 FileBasedSource.fileReadMode = (String s) => s; |
| 1997 } | 1999 } |
| 1998 | 2000 |
| 1999 void test_fileReadMode_normalize_eol_always() { | 2001 test_fileReadMode_normalize_eol_always() async { |
| 2000 FileBasedSource.fileReadMode = | 2002 FileBasedSource.fileReadMode = |
| 2001 PhysicalResourceProvider.NORMALIZE_EOL_ALWAYS; | 2003 PhysicalResourceProvider.NORMALIZE_EOL_ALWAYS; |
| 2002 expect(FileBasedSource.fileReadMode('a'), 'a'); | 2004 expect(FileBasedSource.fileReadMode('a'), 'a'); |
| 2003 | 2005 |
| 2004 // '\n' -> '\n' as first, last and only character | 2006 // '\n' -> '\n' as first, last and only character |
| 2005 expect(FileBasedSource.fileReadMode('\n'), '\n'); | 2007 expect(FileBasedSource.fileReadMode('\n'), '\n'); |
| 2006 expect(FileBasedSource.fileReadMode('a\n'), 'a\n'); | 2008 expect(FileBasedSource.fileReadMode('a\n'), 'a\n'); |
| 2007 expect(FileBasedSource.fileReadMode('\na'), '\na'); | 2009 expect(FileBasedSource.fileReadMode('\na'), '\na'); |
| 2008 | 2010 |
| 2009 // '\r\n' -> '\n' as first, last and only character | 2011 // '\r\n' -> '\n' as first, last and only character |
| 2010 expect(FileBasedSource.fileReadMode('\r\n'), '\n'); | 2012 expect(FileBasedSource.fileReadMode('\r\n'), '\n'); |
| 2011 expect(FileBasedSource.fileReadMode('a\r\n'), 'a\n'); | 2013 expect(FileBasedSource.fileReadMode('a\r\n'), 'a\n'); |
| 2012 expect(FileBasedSource.fileReadMode('\r\na'), '\na'); | 2014 expect(FileBasedSource.fileReadMode('\r\na'), '\na'); |
| 2013 | 2015 |
| 2014 // '\r' -> '\n' as first, last and only character | 2016 // '\r' -> '\n' as first, last and only character |
| 2015 expect(FileBasedSource.fileReadMode('\r'), '\n'); | 2017 expect(FileBasedSource.fileReadMode('\r'), '\n'); |
| 2016 expect(FileBasedSource.fileReadMode('a\r'), 'a\n'); | 2018 expect(FileBasedSource.fileReadMode('a\r'), 'a\n'); |
| 2017 expect(FileBasedSource.fileReadMode('\ra'), '\na'); | 2019 expect(FileBasedSource.fileReadMode('\ra'), '\na'); |
| 2018 | 2020 |
| 2019 FileBasedSource.fileReadMode = (String s) => s; | 2021 FileBasedSource.fileReadMode = (String s) => s; |
| 2020 } | 2022 } |
| 2021 | 2023 |
| 2022 void test_getEncoding() { | 2024 test_getEncoding() async { |
| 2023 SourceFactory factory = new SourceFactory( | 2025 SourceFactory factory = new SourceFactory( |
| 2024 [new ResourceUriResolver(PhysicalResourceProvider.INSTANCE)]); | 2026 [new ResourceUriResolver(PhysicalResourceProvider.INSTANCE)]); |
| 2025 String fullPath = "/does/not/exist.dart"; | 2027 String fullPath = "/does/not/exist.dart"; |
| 2026 JavaFile file = FileUtilities2.createFile(fullPath); | 2028 JavaFile file = FileUtilities2.createFile(fullPath); |
| 2027 FileBasedSource source = new FileBasedSource(file); | 2029 FileBasedSource source = new FileBasedSource(file); |
| 2028 expect(factory.fromEncoding(source.encoding), source); | 2030 expect(factory.fromEncoding(source.encoding), source); |
| 2029 } | 2031 } |
| 2030 | 2032 |
| 2031 void test_getFullName() { | 2033 test_getFullName() async { |
| 2032 String fullPath = "/does/not/exist.dart"; | 2034 String fullPath = "/does/not/exist.dart"; |
| 2033 JavaFile file = FileUtilities2.createFile(fullPath); | 2035 JavaFile file = FileUtilities2.createFile(fullPath); |
| 2034 FileBasedSource source = new FileBasedSource(file); | 2036 FileBasedSource source = new FileBasedSource(file); |
| 2035 expect(source.fullName, file.getAbsolutePath()); | 2037 expect(source.fullName, file.getAbsolutePath()); |
| 2036 } | 2038 } |
| 2037 | 2039 |
| 2038 void test_getShortName() { | 2040 test_getShortName() async { |
| 2039 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); | 2041 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); |
| 2040 FileBasedSource source = new FileBasedSource(file); | 2042 FileBasedSource source = new FileBasedSource(file); |
| 2041 expect(source.shortName, "exist.dart"); | 2043 expect(source.shortName, "exist.dart"); |
| 2042 } | 2044 } |
| 2043 | 2045 |
| 2044 void test_hashCode() { | 2046 test_hashCode() async { |
| 2045 JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart"); | 2047 JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart"); |
| 2046 JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart"); | 2048 JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart"); |
| 2047 FileBasedSource source1 = new FileBasedSource(file1); | 2049 FileBasedSource source1 = new FileBasedSource(file1); |
| 2048 FileBasedSource source2 = new FileBasedSource(file2); | 2050 FileBasedSource source2 = new FileBasedSource(file2); |
| 2049 expect(source2.hashCode, source1.hashCode); | 2051 expect(source2.hashCode, source1.hashCode); |
| 2050 } | 2052 } |
| 2051 | 2053 |
| 2052 void test_isInSystemLibrary_contagious() { | 2054 test_isInSystemLibrary_contagious() async { |
| 2053 DartSdk sdk = _createSdk(); | 2055 DartSdk sdk = _createSdk(); |
| 2054 UriResolver resolver = new DartUriResolver(sdk); | 2056 UriResolver resolver = new DartUriResolver(sdk); |
| 2055 SourceFactory factory = new SourceFactory([resolver]); | 2057 SourceFactory factory = new SourceFactory([resolver]); |
| 2056 // resolve dart:core | 2058 // resolve dart:core |
| 2057 Source result = resolver.resolveAbsolute(Uri.parse("dart:core")); | 2059 Source result = resolver.resolveAbsolute(Uri.parse("dart:core")); |
| 2058 expect(result, isNotNull); | 2060 expect(result, isNotNull); |
| 2059 expect(result.isInSystemLibrary, isTrue); | 2061 expect(result.isInSystemLibrary, isTrue); |
| 2060 // system libraries reference only other system libraries | 2062 // system libraries reference only other system libraries |
| 2061 Source partSource = factory.resolveUri(result, "num.dart"); | 2063 Source partSource = factory.resolveUri(result, "num.dart"); |
| 2062 expect(partSource, isNotNull); | 2064 expect(partSource, isNotNull); |
| 2063 expect(partSource.isInSystemLibrary, isTrue); | 2065 expect(partSource.isInSystemLibrary, isTrue); |
| 2064 } | 2066 } |
| 2065 | 2067 |
| 2066 void test_isInSystemLibrary_false() { | 2068 test_isInSystemLibrary_false() async { |
| 2067 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); | 2069 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); |
| 2068 FileBasedSource source = new FileBasedSource(file); | 2070 FileBasedSource source = new FileBasedSource(file); |
| 2069 expect(source, isNotNull); | 2071 expect(source, isNotNull); |
| 2070 expect(source.fullName, file.getAbsolutePath()); | 2072 expect(source.fullName, file.getAbsolutePath()); |
| 2071 expect(source.isInSystemLibrary, isFalse); | 2073 expect(source.isInSystemLibrary, isFalse); |
| 2072 } | 2074 } |
| 2073 | 2075 |
| 2074 void test_issue14500() { | 2076 test_issue14500() async { |
| 2075 // see https://code.google.com/p/dart/issues/detail?id=14500 | 2077 // see https://code.google.com/p/dart/issues/detail?id=14500 |
| 2076 FileBasedSource source = new FileBasedSource( | 2078 FileBasedSource source = new FileBasedSource( |
| 2077 FileUtilities2.createFile("/some/packages/foo:bar.dart")); | 2079 FileUtilities2.createFile("/some/packages/foo:bar.dart")); |
| 2078 expect(source, isNotNull); | 2080 expect(source, isNotNull); |
| 2079 expect(source.exists(), isFalse); | 2081 expect(source.exists(), isFalse); |
| 2080 } | 2082 } |
| 2081 | 2083 |
| 2082 void test_resolveRelative_file_fileName() { | 2084 test_resolveRelative_file_fileName() async { |
| 2083 if (OSUtilities.isWindows()) { | 2085 if (OSUtilities.isWindows()) { |
| 2084 // On Windows, the URI that is produced includes a drive letter, | 2086 // On Windows, the URI that is produced includes a drive letter, |
| 2085 // which I believe is not consistent across all machines that might run | 2087 // which I believe is not consistent across all machines that might run |
| 2086 // this test. | 2088 // this test. |
| 2087 return; | 2089 return; |
| 2088 } | 2090 } |
| 2089 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | 2091 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); |
| 2090 FileBasedSource source = new FileBasedSource(file); | 2092 FileBasedSource source = new FileBasedSource(file); |
| 2091 expect(source, isNotNull); | 2093 expect(source, isNotNull); |
| 2092 Uri relative = resolveRelativeUri(source.uri, Uri.parse("lib.dart")); | 2094 Uri relative = resolveRelativeUri(source.uri, Uri.parse("lib.dart")); |
| 2093 expect(relative, isNotNull); | 2095 expect(relative, isNotNull); |
| 2094 expect(relative.toString(), "file:///a/b/lib.dart"); | 2096 expect(relative.toString(), "file:///a/b/lib.dart"); |
| 2095 } | 2097 } |
| 2096 | 2098 |
| 2097 void test_resolveRelative_file_filePath() { | 2099 test_resolveRelative_file_filePath() async { |
| 2098 if (OSUtilities.isWindows()) { | 2100 if (OSUtilities.isWindows()) { |
| 2099 // On Windows, the URI that is produced includes a drive letter, | 2101 // On Windows, the URI that is produced includes a drive letter, |
| 2100 // which I believe is not consistent across all machines that might run | 2102 // which I believe is not consistent across all machines that might run |
| 2101 // this test. | 2103 // this test. |
| 2102 return; | 2104 return; |
| 2103 } | 2105 } |
| 2104 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | 2106 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); |
| 2105 FileBasedSource source = new FileBasedSource(file); | 2107 FileBasedSource source = new FileBasedSource(file); |
| 2106 expect(source, isNotNull); | 2108 expect(source, isNotNull); |
| 2107 Uri relative = resolveRelativeUri(source.uri, Uri.parse("c/lib.dart")); | 2109 Uri relative = resolveRelativeUri(source.uri, Uri.parse("c/lib.dart")); |
| 2108 expect(relative, isNotNull); | 2110 expect(relative, isNotNull); |
| 2109 expect(relative.toString(), "file:///a/b/c/lib.dart"); | 2111 expect(relative.toString(), "file:///a/b/c/lib.dart"); |
| 2110 } | 2112 } |
| 2111 | 2113 |
| 2112 void test_resolveRelative_file_filePathWithParent() { | 2114 test_resolveRelative_file_filePathWithParent() async { |
| 2113 if (OSUtilities.isWindows()) { | 2115 if (OSUtilities.isWindows()) { |
| 2114 // On Windows, the URI that is produced includes a drive letter, which I | 2116 // On Windows, the URI that is produced includes a drive letter, which I |
| 2115 // believe is not consistent across all machines that might run this test. | 2117 // believe is not consistent across all machines that might run this test. |
| 2116 return; | 2118 return; |
| 2117 } | 2119 } |
| 2118 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | 2120 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); |
| 2119 FileBasedSource source = new FileBasedSource(file); | 2121 FileBasedSource source = new FileBasedSource(file); |
| 2120 expect(source, isNotNull); | 2122 expect(source, isNotNull); |
| 2121 Uri relative = resolveRelativeUri(source.uri, Uri.parse("../c/lib.dart")); | 2123 Uri relative = resolveRelativeUri(source.uri, Uri.parse("../c/lib.dart")); |
| 2122 expect(relative, isNotNull); | 2124 expect(relative, isNotNull); |
| 2123 expect(relative.toString(), "file:///a/c/lib.dart"); | 2125 expect(relative.toString(), "file:///a/c/lib.dart"); |
| 2124 } | 2126 } |
| 2125 | 2127 |
| 2126 void test_system() { | 2128 test_system() async { |
| 2127 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); | 2129 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); |
| 2128 FileBasedSource source = new FileBasedSource(file, Uri.parse("dart:core")); | 2130 FileBasedSource source = new FileBasedSource(file, Uri.parse("dart:core")); |
| 2129 expect(source, isNotNull); | 2131 expect(source, isNotNull); |
| 2130 expect(source.fullName, file.getAbsolutePath()); | 2132 expect(source.fullName, file.getAbsolutePath()); |
| 2131 expect(source.isInSystemLibrary, isTrue); | 2133 expect(source.isInSystemLibrary, isTrue); |
| 2132 } | 2134 } |
| 2133 } | 2135 } |
| 2134 | 2136 |
| 2135 @reflectiveTest | 2137 @reflectiveTest |
| 2136 class ResolveRelativeUriTest { | 2138 class ResolveRelativeUriTest { |
| 2137 void test_resolveRelative_dart_dartUri() { | 2139 test_resolveRelative_dart_dartUri() async { |
| 2138 _assertResolve('dart:foo', 'dart:bar', 'dart:bar'); | 2140 _assertResolve('dart:foo', 'dart:bar', 'dart:bar'); |
| 2139 } | 2141 } |
| 2140 | 2142 |
| 2141 void test_resolveRelative_dart_fileName() { | 2143 test_resolveRelative_dart_fileName() async { |
| 2142 _assertResolve('dart:test', 'lib.dart', 'dart:test/lib.dart'); | 2144 _assertResolve('dart:test', 'lib.dart', 'dart:test/lib.dart'); |
| 2143 } | 2145 } |
| 2144 | 2146 |
| 2145 void test_resolveRelative_dart_filePath() { | 2147 test_resolveRelative_dart_filePath() async { |
| 2146 _assertResolve('dart:test', 'c/lib.dart', 'dart:test/c/lib.dart'); | 2148 _assertResolve('dart:test', 'c/lib.dart', 'dart:test/c/lib.dart'); |
| 2147 } | 2149 } |
| 2148 | 2150 |
| 2149 void test_resolveRelative_dart_filePathWithParent() { | 2151 test_resolveRelative_dart_filePathWithParent() async { |
| 2150 _assertResolve( | 2152 _assertResolve( |
| 2151 'dart:test/b/test.dart', '../c/lib.dart', 'dart:test/c/lib.dart'); | 2153 'dart:test/b/test.dart', '../c/lib.dart', 'dart:test/c/lib.dart'); |
| 2152 } | 2154 } |
| 2153 | 2155 |
| 2154 void test_resolveRelative_package_dartUri() { | 2156 test_resolveRelative_package_dartUri() async { |
| 2155 _assertResolve('package:foo/bar.dart', 'dart:test', 'dart:test'); | 2157 _assertResolve('package:foo/bar.dart', 'dart:test', 'dart:test'); |
| 2156 } | 2158 } |
| 2157 | 2159 |
| 2158 void test_resolveRelative_package_emptyPath() { | 2160 test_resolveRelative_package_emptyPath() async { |
| 2159 _assertResolve('package:foo/bar.dart', '', 'package:foo/bar.dart'); | 2161 _assertResolve('package:foo/bar.dart', '', 'package:foo/bar.dart'); |
| 2160 } | 2162 } |
| 2161 | 2163 |
| 2162 void test_resolveRelative_package_fileName() { | 2164 test_resolveRelative_package_fileName() async { |
| 2163 _assertResolve('package:b/test.dart', 'lib.dart', 'package:b/lib.dart'); | 2165 _assertResolve('package:b/test.dart', 'lib.dart', 'package:b/lib.dart'); |
| 2164 } | 2166 } |
| 2165 | 2167 |
| 2166 void test_resolveRelative_package_fileNameWithoutPackageName() { | 2168 test_resolveRelative_package_fileNameWithoutPackageName() async { |
| 2167 _assertResolve('package:test.dart', 'lib.dart', 'package:lib.dart'); | 2169 _assertResolve('package:test.dart', 'lib.dart', 'package:lib.dart'); |
| 2168 } | 2170 } |
| 2169 | 2171 |
| 2170 void test_resolveRelative_package_filePath() { | 2172 test_resolveRelative_package_filePath() async { |
| 2171 _assertResolve('package:b/test.dart', 'c/lib.dart', 'package:b/c/lib.dart'); | 2173 _assertResolve('package:b/test.dart', 'c/lib.dart', 'package:b/c/lib.dart'); |
| 2172 } | 2174 } |
| 2173 | 2175 |
| 2174 void test_resolveRelative_package_filePathWithParent() { | 2176 test_resolveRelative_package_filePathWithParent() async { |
| 2175 _assertResolve( | 2177 _assertResolve( |
| 2176 'package:a/b/test.dart', '../c/lib.dart', 'package:a/c/lib.dart'); | 2178 'package:a/b/test.dart', '../c/lib.dart', 'package:a/c/lib.dart'); |
| 2177 } | 2179 } |
| 2178 | 2180 |
| 2179 void _assertResolve(String baseStr, String containedStr, String expectedStr) { | 2181 void _assertResolve(String baseStr, String containedStr, String expectedStr) { |
| 2180 Uri base = Uri.parse(baseStr); | 2182 Uri base = Uri.parse(baseStr); |
| 2181 Uri contained = Uri.parse(containedStr); | 2183 Uri contained = Uri.parse(containedStr); |
| 2182 Uri result = resolveRelativeUri(base, contained); | 2184 Uri result = resolveRelativeUri(base, contained); |
| 2183 expect(result, isNotNull); | 2185 expect(result, isNotNull); |
| 2184 expect(result.toString(), expectedStr); | 2186 expect(result.toString(), expectedStr); |
| 2185 } | 2187 } |
| 2186 } | 2188 } |
| 2187 | 2189 |
| 2188 @deprecated | 2190 @deprecated |
| 2189 @reflectiveTest | 2191 @reflectiveTest |
| 2190 class SDKLibrariesReaderTest extends EngineTestCase { | 2192 class SDKLibrariesReaderTest extends EngineTestCase { |
| 2191 void test_readFrom_dart2js() { | 2193 test_readFrom_dart2js() async { |
| 2192 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile( | 2194 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile( |
| 2193 FileUtilities2.createFile("/libs.dart"), | 2195 FileUtilities2.createFile("/libs.dart"), |
| 2194 r''' | 2196 r''' |
| 2195 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 2197 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
| 2196 'first' : const LibraryInfo( | 2198 'first' : const LibraryInfo( |
| 2197 'first/first.dart', | 2199 'first/first.dart', |
| 2198 categories: 'Client', | 2200 categories: 'Client', |
| 2199 documented: true, | 2201 documented: true, |
| 2200 platforms: VM_PLATFORM, | 2202 platforms: VM_PLATFORM, |
| 2201 dart2jsPath: 'first/first_dart2js.dart'), | 2203 dart2jsPath: 'first/first_dart2js.dart'), |
| 2202 };'''); | 2204 };'''); |
| 2203 expect(libraryMap, isNotNull); | 2205 expect(libraryMap, isNotNull); |
| 2204 expect(libraryMap.size(), 1); | 2206 expect(libraryMap.size(), 1); |
| 2205 SdkLibrary first = libraryMap.getLibrary("dart:first"); | 2207 SdkLibrary first = libraryMap.getLibrary("dart:first"); |
| 2206 expect(first, isNotNull); | 2208 expect(first, isNotNull); |
| 2207 expect(first.category, "Client"); | 2209 expect(first.category, "Client"); |
| 2208 expect(first.path, "first/first_dart2js.dart"); | 2210 expect(first.path, "first/first_dart2js.dart"); |
| 2209 expect(first.shortName, "dart:first"); | 2211 expect(first.shortName, "dart:first"); |
| 2210 expect(first.isDart2JsLibrary, false); | 2212 expect(first.isDart2JsLibrary, false); |
| 2211 expect(first.isDocumented, true); | 2213 expect(first.isDocumented, true); |
| 2212 expect(first.isImplementation, false); | 2214 expect(first.isImplementation, false); |
| 2213 expect(first.isVmLibrary, true); | 2215 expect(first.isVmLibrary, true); |
| 2214 } | 2216 } |
| 2215 | 2217 |
| 2216 void test_readFrom_empty() { | 2218 test_readFrom_empty() async { |
| 2217 LibraryMap libraryMap = new SdkLibrariesReader(false) | 2219 LibraryMap libraryMap = new SdkLibrariesReader(false) |
| 2218 .readFromFile(FileUtilities2.createFile("/libs.dart"), ""); | 2220 .readFromFile(FileUtilities2.createFile("/libs.dart"), ""); |
| 2219 expect(libraryMap, isNotNull); | 2221 expect(libraryMap, isNotNull); |
| 2220 expect(libraryMap.size(), 0); | 2222 expect(libraryMap.size(), 0); |
| 2221 } | 2223 } |
| 2222 | 2224 |
| 2223 void test_readFrom_normal() { | 2225 test_readFrom_normal() async { |
| 2224 LibraryMap libraryMap = new SdkLibrariesReader(false).readFromFile( | 2226 LibraryMap libraryMap = new SdkLibrariesReader(false).readFromFile( |
| 2225 FileUtilities2.createFile("/libs.dart"), | 2227 FileUtilities2.createFile("/libs.dart"), |
| 2226 r''' | 2228 r''' |
| 2227 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 2229 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
| 2228 'first' : const LibraryInfo( | 2230 'first' : const LibraryInfo( |
| 2229 'first/first.dart', | 2231 'first/first.dart', |
| 2230 categories: 'Client', | 2232 categories: 'Client', |
| 2231 documented: true, | 2233 documented: true, |
| 2232 platforms: VM_PLATFORM), | 2234 platforms: VM_PLATFORM), |
| 2233 | 2235 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 2256 expect(second.shortName, "dart:second"); | 2258 expect(second.shortName, "dart:second"); |
| 2257 expect(second.isDart2JsLibrary, false); | 2259 expect(second.isDart2JsLibrary, false); |
| 2258 expect(second.isDocumented, false); | 2260 expect(second.isDocumented, false); |
| 2259 expect(second.isImplementation, true); | 2261 expect(second.isImplementation, true); |
| 2260 expect(second.isVmLibrary, false); | 2262 expect(second.isVmLibrary, false); |
| 2261 } | 2263 } |
| 2262 } | 2264 } |
| 2263 | 2265 |
| 2264 @reflectiveTest | 2266 @reflectiveTest |
| 2265 class UriKindTest { | 2267 class UriKindTest { |
| 2266 void test_fromEncoding() { | 2268 test_fromEncoding() async { |
| 2267 expect(UriKind.fromEncoding(0x64), same(UriKind.DART_URI)); | 2269 expect(UriKind.fromEncoding(0x64), same(UriKind.DART_URI)); |
| 2268 expect(UriKind.fromEncoding(0x66), same(UriKind.FILE_URI)); | 2270 expect(UriKind.fromEncoding(0x66), same(UriKind.FILE_URI)); |
| 2269 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); | 2271 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); |
| 2270 expect(UriKind.fromEncoding(0x58), same(null)); | 2272 expect(UriKind.fromEncoding(0x58), same(null)); |
| 2271 } | 2273 } |
| 2272 | 2274 |
| 2273 void test_getEncoding() { | 2275 test_getEncoding() async { |
| 2274 expect(UriKind.DART_URI.encoding, 0x64); | 2276 expect(UriKind.DART_URI.encoding, 0x64); |
| 2275 expect(UriKind.FILE_URI.encoding, 0x66); | 2277 expect(UriKind.FILE_URI.encoding, 0x66); |
| 2276 expect(UriKind.PACKAGE_URI.encoding, 0x70); | 2278 expect(UriKind.PACKAGE_URI.encoding, 0x70); |
| 2277 } | 2279 } |
| 2278 } | 2280 } |
| OLD | NEW |