| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.resolver.package; | 5 library test.resolver.package; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/package_uri_resolver.dart'; | 9 import 'package:analysis_server/src/package_uri_resolver.dart'; |
| 10 import 'package:analysis_server/src/resource.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
| 12 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 13 | 14 |
| 14 import 'reflective_tests.dart'; | 15 import 'reflective_tests.dart'; |
| 15 | 16 |
| 16 main() { | 17 main() { |
| 17 groupSep = ' | '; | 18 groupSep = ' | '; |
| 18 | 19 |
| 19 group('PackageMapUriResolver', () { | 20 group('PackageMapUriResolver', () { |
| 20 runReflectiveTests(_PackageMapUriResolverTest); | 21 runReflectiveTests(_PackageMapUriResolverTest); |
| 21 }); | 22 }); |
| 22 } | 23 } |
| 23 | 24 |
| 24 | 25 |
| 25 @ReflectiveTestCase() | 26 @ReflectiveTestCase() |
| 26 class _PackageMapUriResolverTest { | 27 class _PackageMapUriResolverTest { |
| 27 static HashMap EMPTY_MAP = new HashMap<String, List<Folder>>(); | 28 static HashMap EMPTY_MAP = new HashMap<String, List<Folder>>(); |
| 28 MemoryResourceProvider provider = new MemoryResourceProvider(); | 29 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 29 | 30 |
| 30 setUp() { | 31 setUp() { |
| 31 } | 32 } |
| 32 | 33 |
| 33 tearDown() { | 34 tearDown() { |
| 34 } | 35 } |
| 35 | 36 |
| 36 void test_isPackageUri() { | |
| 37 Uri uri = Uri.parse('package:test/test.dart'); | |
| 38 expect(uri.scheme, 'package'); | |
| 39 expect(PackageMapUriResolver.isPackageUri(uri), isTrue); | |
| 40 } | |
| 41 | |
| 42 void test_fromEncoding_nonPackage() { | 37 void test_fromEncoding_nonPackage() { |
| 43 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP); | 38 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP); |
| 44 Uri uri = Uri.parse('file:/does/not/exist.dart'); | 39 Uri uri = Uri.parse('file:/does/not/exist.dart'); |
| 45 Source result = resolver.fromEncoding(UriKind.DART_URI, uri); | 40 Source result = resolver.fromEncoding(UriKind.DART_URI, uri); |
| 46 expect(result, isNull); | 41 expect(result, isNull); |
| 47 } | 42 } |
| 48 | 43 |
| 49 void test_fromEncoding_package() { | 44 void test_fromEncoding_package() { |
| 50 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP); | 45 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP); |
| 51 Uri uri = Uri.parse('package:/does/not/exist.dart'); | 46 Uri uri = Uri.parse('package:/does/not/exist.dart'); |
| 52 Source result = resolver.fromEncoding(UriKind.PACKAGE_URI, uri); | 47 Source result = resolver.fromEncoding(UriKind.PACKAGE_URI, uri); |
| 53 expect(result, isNotNull); | 48 expect(result, isNotNull); |
| 54 expect(result.fullName, '/does/not/exist.dart'); | 49 expect(result.fullName, '/does/not/exist.dart'); |
| 55 } | 50 } |
| 56 | 51 |
| 52 void test_isPackageUri() { |
| 53 Uri uri = Uri.parse('package:test/test.dart'); |
| 54 expect(uri.scheme, 'package'); |
| 55 expect(PackageMapUriResolver.isPackageUri(uri), isTrue); |
| 56 } |
| 57 |
| 57 void test_isPackageUri_null_scheme() { | 58 void test_isPackageUri_null_scheme() { |
| 58 Uri uri = Uri.parse('foo.dart'); | 59 Uri uri = Uri.parse('foo.dart'); |
| 59 expect(uri.scheme, ''); | 60 expect(uri.scheme, ''); |
| 60 expect(PackageMapUriResolver.isPackageUri(uri), isFalse); | 61 expect(PackageMapUriResolver.isPackageUri(uri), isFalse); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void test_isPackageUri_other_scheme() { | 64 void test_isPackageUri_other_scheme() { |
| 64 Uri uri = Uri.parse('memfs:/foo.dart'); | 65 Uri uri = Uri.parse('memfs:/foo.dart'); |
| 65 expect(uri.scheme, 'memfs'); | 66 expect(uri.scheme, 'memfs'); |
| 66 expect(PackageMapUriResolver.isPackageUri(uri), isFalse); | 67 expect(PackageMapUriResolver.isPackageUri(uri), isFalse); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 153 |
| 153 void test_resolve_package_notInMap() { | 154 void test_resolve_package_notInMap() { |
| 154 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP); | 155 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP); |
| 155 Uri uri = Uri.parse('package:analyzer/analyzer.dart'); | 156 Uri uri = Uri.parse('package:analyzer/analyzer.dart'); |
| 156 Source result = resolver.resolveAbsolute(uri); | 157 Source result = resolver.resolveAbsolute(uri); |
| 157 expect(result, isNotNull); | 158 expect(result, isNotNull); |
| 158 expect(result.exists(), isFalse); | 159 expect(result.exists(), isFalse); |
| 159 expect(result.fullName, 'package:analyzer/analyzer.dart'); | 160 expect(result.fullName, 'package:analyzer/analyzer.dart'); |
| 160 } | 161 } |
| 161 } | 162 } |
| OLD | NEW |