| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.test.generated.source_factory; | 5 library analyzer.test.generated.test.generated.source_factory; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 11 import 'package:analyzer/source/package_map_resolver.dart'; | 11 import 'package:analyzer/source/package_map_resolver.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine, Logger; |
| 12 import 'package:analyzer/src/generated/java_core.dart'; | 13 import 'package:analyzer/src/generated/java_core.dart'; |
| 13 import 'package:analyzer/src/generated/java_engine_io.dart'; | 14 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 14 import 'package:analyzer/src/generated/java_io.dart'; | 15 import 'package:analyzer/src/generated/java_io.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/generated/source_io.dart'; | 17 import 'package:analyzer/src/generated/source_io.dart'; |
| 17 import 'package:analyzer/src/generated/utilities_dart.dart' as utils; | 18 import 'package:analyzer/src/generated/utilities_dart.dart' as utils; |
| 18 import 'package:package_config/packages.dart'; | 19 import 'package:package_config/packages.dart'; |
| 19 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 20 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
| 20 import 'package:package_config/src/packages_impl.dart'; | 21 import 'package:package_config/src/packages_impl.dart'; |
| 21 import 'package:path/path.dart'; | 22 import 'package:path/path.dart'; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 {String uri, | 58 {String uri, |
| 58 String config, | 59 String config, |
| 59 Source containingSource, | 60 Source containingSource, |
| 60 UriResolver customResolver}) { | 61 UriResolver customResolver}) { |
| 61 Packages packages = createPackageMap(baseUri, config); | 62 Packages packages = createPackageMap(baseUri, config); |
| 62 List<UriResolver> resolvers = testResolvers.toList(); | 63 List<UriResolver> resolvers = testResolvers.toList(); |
| 63 if (customResolver != null) { | 64 if (customResolver != null) { |
| 64 resolvers.add(customResolver); | 65 resolvers.add(customResolver); |
| 65 } | 66 } |
| 66 SourceFactory factory = new SourceFactory(resolvers, packages); | 67 SourceFactory factory = new SourceFactory(resolvers, packages); |
| 67 Source source = factory.resolveUri(containingSource, uri); | 68 |
| 68 return source != null ? source.fullName : null; | 69 expect(AnalysisEngine.instance.logger, Logger.NULL); |
| 70 var logger = new TestLogger(); |
| 71 AnalysisEngine.instance.logger = logger; |
| 72 try { |
| 73 Source source = factory.resolveUri(containingSource, uri); |
| 74 expect(logger.log, []); |
| 75 return source != null ? source.fullName : null; |
| 76 } finally { |
| 77 AnalysisEngine.instance.logger = Logger.NULL; |
| 78 } |
| 69 } | 79 } |
| 70 | 80 |
| 71 Uri restorePackageUri( | 81 Uri restorePackageUri( |
| 72 {Source source, String config, UriResolver customResolver}) { | 82 {Source source, String config, UriResolver customResolver}) { |
| 73 Packages packages = createPackageMap(baseUri, config); | 83 Packages packages = createPackageMap(baseUri, config); |
| 74 List<UriResolver> resolvers = testResolvers.toList(); | 84 List<UriResolver> resolvers = testResolvers.toList(); |
| 75 if (customResolver != null) { | 85 if (customResolver != null) { |
| 76 resolvers.add(customResolver); | 86 resolvers.add(customResolver); |
| 77 } | 87 } |
| 78 SourceFactory factory = new SourceFactory(resolvers, packages); | 88 SourceFactory factory = new SourceFactory(resolvers, packages); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 expect(uri, isNull); | 125 expect(uri, isNull); |
| 116 }); | 126 }); |
| 117 test('Non-package URI', () { | 127 test('Non-package URI', () { |
| 118 var testResolver = new CustomUriResolver(uriPath: 'test_uri'); | 128 var testResolver = new CustomUriResolver(uriPath: 'test_uri'); |
| 119 String uri = resolvePackageUri( | 129 String uri = resolvePackageUri( |
| 120 config: 'unittest:/home/somebody/.pub/cache/unittest-0.9.9/lib/', | 130 config: 'unittest:/home/somebody/.pub/cache/unittest-0.9.9/lib/', |
| 121 uri: 'custom:custom.dart', | 131 uri: 'custom:custom.dart', |
| 122 customResolver: testResolver); | 132 customResolver: testResolver); |
| 123 expect(uri, testResolver.uriPath); | 133 expect(uri, testResolver.uriPath); |
| 124 }); | 134 }); |
| 135 test('Bad package URI', () { |
| 136 String uri = resolvePackageUri(config: '', uri: 'package:foo'); |
| 137 expect(uri, isNull); |
| 138 }); |
| 125 test('Invalid URI', () { | 139 test('Invalid URI', () { |
| 126 // TODO(pquitslund): fix clients to handle errors appropriately | 140 // TODO(pquitslund): fix clients to handle errors appropriately |
| 127 // CLI: print message 'invalid package file format' | 141 // CLI: print message 'invalid package file format' |
| 128 // SERVER: best case tell user somehow and recover... | 142 // SERVER: best case tell user somehow and recover... |
| 129 expect( | 143 expect( |
| 130 () => resolvePackageUri( | 144 () => resolvePackageUri( |
| 131 config: 'foo:<:&%>', uri: 'package:foo/bar.dart'), | 145 config: 'foo:<:&%>', uri: 'package:foo/bar.dart'), |
| 132 throwsA(new isInstanceOf('FormatException'))); | 146 throwsA(new isInstanceOf('FormatException'))); |
| 133 }); | 147 }); |
| 134 test('Valid URI that cannot be further resolved', () { | 148 test('Valid URI that cannot be further resolved', () { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 UriResolver_SourceFactoryTest_test_fromEncoding_valid(this.encoding); | 357 UriResolver_SourceFactoryTest_test_fromEncoding_valid(this.encoding); |
| 344 | 358 |
| 345 @override | 359 @override |
| 346 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 360 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 347 if (uri.toString() == encoding) { | 361 if (uri.toString() == encoding) { |
| 348 return new TestSource(); | 362 return new TestSource(); |
| 349 } | 363 } |
| 350 return null; | 364 return null; |
| 351 } | 365 } |
| 352 } | 366 } |
| OLD | NEW |