| 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.source.package_map_resolver; | 5 library test.source.package_map_resolver; |
| 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/source/package_map_resolver.dart'; | 9 import 'package:analyzer/source/package_map_resolver.dart'; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 | 12 |
| 13 import '../reflective_tests.dart'; |
| 14 |
| 13 | 15 |
| 14 main() { | 16 main() { |
| 15 groupSep = ' | '; | 17 groupSep = ' | '; |
| 16 group('PackageMapUriResolverTest', () { | 18 runReflectiveTests(_PackageMapUriResolverTest); |
| 17 test('isPackageUri', () { | |
| 18 new _PackageMapUriResolverTest().test_isPackageUri(); | |
| 19 }); | |
| 20 test('isPackageUri_null_scheme', () { | |
| 21 new _PackageMapUriResolverTest().test_isPackageUri_null_scheme(); | |
| 22 }); | |
| 23 test('isPackageUri_other_scheme', () { | |
| 24 new _PackageMapUriResolverTest().test_isPackageUri_other_scheme(); | |
| 25 }); | |
| 26 test('resolve_multiple_folders', () { | |
| 27 new _PackageMapUriResolverTest().test_resolve_multiple_folders(); | |
| 28 }); | |
| 29 test('resolve_nonPackage', () { | |
| 30 new _PackageMapUriResolverTest().test_resolve_nonPackage(); | |
| 31 }); | |
| 32 test('resolve_OK', () { | |
| 33 new _PackageMapUriResolverTest().test_resolve_OK(); | |
| 34 }); | |
| 35 test('resolve_package_invalid_leadingSlash', () { | |
| 36 var inst = new _PackageMapUriResolverTest(); | |
| 37 inst.test_resolve_package_invalid_leadingSlash(); | |
| 38 }); | |
| 39 test('resolve_package_invalid_noSlash', () { | |
| 40 new _PackageMapUriResolverTest().test_resolve_package_invalid_noSlash(); | |
| 41 }); | |
| 42 test('resolve_package_invalid_onlySlash', () { | |
| 43 new _PackageMapUriResolverTest().test_resolve_package_invalid_onlySlash(); | |
| 44 }); | |
| 45 test('resolve_package_notInMap', () { | |
| 46 new _PackageMapUriResolverTest().test_resolve_package_notInMap(); | |
| 47 }); | |
| 48 test('restoreAbsolute_OK', () { | |
| 49 new _PackageMapUriResolverTest().test_restoreAbsolute(); | |
| 50 }); | |
| 51 }); | |
| 52 } | 19 } |
| 53 | 20 |
| 54 | 21 |
| 22 @reflectiveTest |
| 55 class _PackageMapUriResolverTest { | 23 class _PackageMapUriResolverTest { |
| 56 static const Map EMPTY_MAP = const <String, List<Folder>>{}; | 24 static const Map EMPTY_MAP = const <String, List<Folder>>{}; |
| 57 MemoryResourceProvider provider = new MemoryResourceProvider(); | 25 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 58 | 26 |
| 59 void test_isPackageUri() { | 27 void test_isPackageUri() { |
| 60 Uri uri = Uri.parse('package:test/test.dart'); | 28 Uri uri = Uri.parse('package:test/test.dart'); |
| 61 expect(uri.scheme, 'package'); | 29 expect(uri.scheme, 'package'); |
| 62 expect(PackageMapUriResolver.isPackageUri(uri), isTrue); | 30 expect(PackageMapUriResolver.isPackageUri(uri), isTrue); |
| 63 } | 31 } |
| 64 | 32 |
| 65 void test_isPackageUri_null_scheme() { | 33 void test_isPackageUri_null_scheme() { |
| 66 Uri uri = Uri.parse('foo.dart'); | 34 Uri uri = Uri.parse('foo.dart'); |
| 67 expect(uri.scheme, ''); | 35 expect(uri.scheme, ''); |
| 68 expect(PackageMapUriResolver.isPackageUri(uri), isFalse); | 36 expect(PackageMapUriResolver.isPackageUri(uri), isFalse); |
| 69 } | 37 } |
| 70 | 38 |
| 71 void test_isPackageUri_other_scheme() { | 39 void test_isPackageUri_other_scheme() { |
| 72 Uri uri = Uri.parse('memfs:/foo.dart'); | 40 Uri uri = Uri.parse('memfs:/foo.dart'); |
| 73 expect(uri.scheme, 'memfs'); | 41 expect(uri.scheme, 'memfs'); |
| 74 expect(PackageMapUriResolver.isPackageUri(uri), isFalse); | 42 expect(PackageMapUriResolver.isPackageUri(uri), isFalse); |
| 75 } | 43 } |
| 76 | 44 |
| 45 void test_new_null_packageMap() { |
| 46 expect(() { |
| 47 new PackageMapUriResolver(provider, null); |
| 48 }, throws); |
| 49 } |
| 50 |
| 51 void test_new_null_resourceProvider() { |
| 52 expect(() { |
| 53 new PackageMapUriResolver(null, <String, List<Folder>>{}); |
| 54 }, throws); |
| 55 } |
| 56 |
| 77 void test_resolve_multiple_folders() { | 57 void test_resolve_multiple_folders() { |
| 78 const pkgFileA = '/part1/lib/libA.dart'; | 58 const pkgFileA = '/part1/lib/libA.dart'; |
| 79 const pkgFileB = '/part2/lib/libB.dart'; | 59 const pkgFileB = '/part2/lib/libB.dart'; |
| 80 provider.newFile(pkgFileA, 'library lib_a'); | 60 provider.newFile(pkgFileA, 'library lib_a'); |
| 81 provider.newFile(pkgFileB, 'library lib_b'); | 61 provider.newFile(pkgFileB, 'library lib_b'); |
| 82 PackageMapUriResolver resolver = | 62 PackageMapUriResolver resolver = |
| 83 new PackageMapUriResolver(provider, <String, List<Folder>>{ | 63 new PackageMapUriResolver(provider, <String, List<Folder>>{ |
| 84 'pkg': [ | 64 'pkg': [ |
| 85 provider.getResource('/part1/lib/'), | 65 provider.getResource('/part1/lib/'), |
| 86 provider.getResource('/part2/lib/')] | 66 provider.getResource('/part2/lib/')] |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 Source source = _createFileSource('/no/such/file'); | 174 Source source = _createFileSource('/no/such/file'); |
| 195 Uri uri = resolver.restoreAbsolute(source); | 175 Uri uri = resolver.restoreAbsolute(source); |
| 196 expect(uri, isNull); | 176 expect(uri, isNull); |
| 197 } | 177 } |
| 198 } | 178 } |
| 199 | 179 |
| 200 Source _createFileSource(String path) { | 180 Source _createFileSource(String path) { |
| 201 return new NonExistingSource(path, UriKind.FILE_URI); | 181 return new NonExistingSource(path, UriKind.FILE_URI); |
| 202 } | 182 } |
| 203 } | 183 } |
| OLD | NEW |