| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.src.context.context_builder_test; | 5 library analyzer.test.src.context.context_builder_test; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/plugin/options.dart'; | 9 import 'package:analyzer/plugin/options.dart'; |
| 10 import 'package:analyzer/source/package_map_resolver.dart'; | |
| 11 import 'package:analyzer/src/context/builder.dart'; | 10 import 'package:analyzer/src/context/builder.dart'; |
| 12 import 'package:analyzer/src/context/source.dart'; | 11 import 'package:analyzer/src/context/source.dart'; |
| 12 import 'package:analyzer/src/generated/bazel.dart'; |
| 13 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 14 import 'package:analyzer/src/generated/sdk.dart'; | 14 import 'package:analyzer/src/generated/sdk.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/plugin/options_plugin.dart'; | 16 import 'package:analyzer/src/plugin/options_plugin.dart'; |
| 17 import 'package:package_config/packages.dart'; | 17 import 'package:package_config/packages.dart'; |
| 18 import 'package:package_config/src/packages_impl.dart'; | 18 import 'package:package_config/src/packages_impl.dart'; |
| 19 import 'package:path/path.dart' as path; | 19 import 'package:path/path.dart' as path; |
| 20 import 'package:plugin/src/plugin_impl.dart'; | 20 import 'package:plugin/src/plugin_impl.dart'; |
| 21 import 'package:test/test.dart'; | 21 import 'package:test/test.dart'; |
| 22 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 22 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 expect(map['bar'], barUri); | 266 expect(map['bar'], barUri); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void test_createPackageMap_none() { | 269 void test_createPackageMap_none() { |
| 270 String rootPath = resourceProvider.convertPath('/root'); | 270 String rootPath = resourceProvider.convertPath('/root'); |
| 271 resourceProvider.newFolder(rootPath); | 271 resourceProvider.newFolder(rootPath); |
| 272 Packages packages = builder.createPackageMap(rootPath); | 272 Packages packages = builder.createPackageMap(rootPath); |
| 273 expect(packages, same(Packages.noPackages)); | 273 expect(packages, same(Packages.noPackages)); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void test_createSourceFactory_fileProvider() { | 276 void test_createSourceFactory_bazelWorkspace_fileProvider() { |
| 277 String rootPath = resourceProvider.convertPath('/root'); | 277 String _p(String path) => resourceProvider.convertPath(path); |
| 278 Folder rootFolder = resourceProvider.getFolder(rootPath); | 278 |
| 279 createDefaultSdk(rootFolder); | 279 String projectPath = _p('/workspace/my/module'); |
| 280 String projectPath = pathContext.join(rootPath, 'project'); | 280 resourceProvider.newFile(_p('/workspace/WORKSPACE'), ''); |
| 281 String packageFilePath = pathContext.join(projectPath, '.packages'); | 281 resourceProvider.newFolder(_p('/workspace/bazel-bin')); |
| 282 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); | 282 resourceProvider.newFolder(_p('/workspace/bazel-genfiles')); |
| 283 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); | 283 resourceProvider.newFolder(projectPath); |
| 284 createFile( | 284 |
| 285 packageFilePath, | |
| 286 ''' | |
| 287 a:${pathContext.toUri(packageA)} | |
| 288 b:${pathContext.toUri(packageB)} | |
| 289 '''); | |
| 290 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 285 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 291 UriResolver resolver = new ResourceUriResolver(resourceProvider); | |
| 292 builder.fileResolverProvider = (folder) => resolver; | |
| 293 SourceFactoryImpl factory = | 286 SourceFactoryImpl factory = |
| 294 builder.createSourceFactory(projectPath, options); | 287 builder.createSourceFactory(projectPath, options); |
| 295 expect(factory.resolvers, contains(same(resolver))); | 288 expect(factory.resolvers, |
| 289 contains(predicate((r) => r is BazelFileUriResolver))); |
| 290 expect(factory.resolvers, |
| 291 contains(predicate((r) => r is BazelPackageUriResolver))); |
| 296 } | 292 } |
| 297 | 293 |
| 298 void test_createSourceFactory_noProvider_packages_embedder_extensions() { | 294 void test_createSourceFactory_noProvider_packages_embedder_extensions() { |
| 299 String rootPath = resourceProvider.convertPath('/root'); | 295 String rootPath = resourceProvider.convertPath('/root'); |
| 300 Folder rootFolder = resourceProvider.getFolder(rootPath); | 296 Folder rootFolder = resourceProvider.getFolder(rootPath); |
| 301 createDefaultSdk(rootFolder); | 297 createDefaultSdk(rootFolder); |
| 302 String projectPath = pathContext.join(rootPath, 'project'); | 298 String projectPath = pathContext.join(rootPath, 'project'); |
| 303 String packageFilePath = pathContext.join(projectPath, '.packages'); | 299 String packageFilePath = pathContext.join(projectPath, '.packages'); |
| 304 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); | 300 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); |
| 305 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); | 301 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 Source dartSource = factory.forUri('dart:core'); | 402 Source dartSource = factory.forUri('dart:core'); |
| 407 expect(dartSource, isNotNull); | 403 expect(dartSource, isNotNull); |
| 408 expect(dartSource.fullName, | 404 expect(dartSource.fullName, |
| 409 pathContext.join(defaultSdkPath, 'lib', 'core', 'core.dart')); | 405 pathContext.join(defaultSdkPath, 'lib', 'core', 'core.dart')); |
| 410 | 406 |
| 411 Source packageSource = factory.forUri('package:a/a.dart'); | 407 Source packageSource = factory.forUri('package:a/a.dart'); |
| 412 expect(packageSource, isNotNull); | 408 expect(packageSource, isNotNull); |
| 413 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart')); | 409 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart')); |
| 414 } | 410 } |
| 415 | 411 |
| 416 void test_createSourceFactory_packageProvider() { | |
| 417 String rootPath = resourceProvider.convertPath('/root'); | |
| 418 Folder rootFolder = resourceProvider.getFolder(rootPath); | |
| 419 createDefaultSdk(rootFolder); | |
| 420 String projectPath = pathContext.join(rootPath, 'project'); | |
| 421 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 422 UriResolver resolver = new PackageMapUriResolver(resourceProvider, {}); | |
| 423 builder.packageResolverProvider = (folder) => resolver; | |
| 424 SourceFactoryImpl factory = | |
| 425 builder.createSourceFactory(projectPath, options); | |
| 426 expect(factory.resolvers, contains(same(resolver))); | |
| 427 } | |
| 428 | |
| 429 void test_declareVariables_emptyMap() { | 412 void test_declareVariables_emptyMap() { |
| 430 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | 413 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 431 Iterable<String> expected = context.declaredVariables.variableNames; | 414 Iterable<String> expected = context.declaredVariables.variableNames; |
| 432 builder.declaredVariables = <String, String>{}; | 415 builder.declaredVariables = <String, String>{}; |
| 433 | 416 |
| 434 builder.declareVariables(context); | 417 builder.declareVariables(context); |
| 435 expect(context.declaredVariables.variableNames, unorderedEquals(expected)); | 418 expect(context.declaredVariables.variableNames, unorderedEquals(expected)); |
| 436 } | 419 } |
| 437 | 420 |
| 438 void test_declareVariables_nonEmptyMap() { | 421 void test_declareVariables_nonEmptyMap() { |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 fail('Unexpected invocation of optionsProcessed'); | 738 fail('Unexpected invocation of optionsProcessed'); |
| 756 } | 739 } |
| 757 expect(options, hasLength(expectedOptions.length)); | 740 expect(options, hasLength(expectedOptions.length)); |
| 758 for (String key in expectedOptions.keys) { | 741 for (String key in expectedOptions.keys) { |
| 759 expect(options.containsKey(key), isTrue, reason: 'missing key $key'); | 742 expect(options.containsKey(key), isTrue, reason: 'missing key $key'); |
| 760 expect(options[key], expectedOptions[key], | 743 expect(options[key], expectedOptions[key], |
| 761 reason: 'values for key $key do not match'); | 744 reason: 'values for key $key do not match'); |
| 762 } | 745 } |
| 763 } | 746 } |
| 764 } | 747 } |
| OLD | NEW |