fix new pedantic lints
diff --git a/lib/src/async_package_resolver.dart b/lib/src/async_package_resolver.dart index ef75081..03f6bbe 100644 --- a/lib/src/async_package_resolver.dart +++ b/lib/src/async_package_resolver.dart
@@ -12,18 +12,27 @@ AsyncPackageResolver(this._inner); + @override Future<Map<String, Uri>> get packageConfigMap async => _inner.packageConfigMap; + @override Future<Uri> get packageConfigUri async => _inner.packageConfigUri; + @override Future<Uri> get packageRoot async => _inner.packageRoot; + @override Future<SyncPackageResolver> get asSync async => _inner; + @override Future<String> get processArgument async => _inner.processArgument; + @override Future<Uri> resolveUri(packageUri) async => _inner.resolveUri(packageUri); + @override Future<Uri> urlFor(String package, [String path]) async => _inner.urlFor(package, path); + @override Future<Uri> packageUriFor(url) async => _inner.packageUriFor(url); + @override Future<String> packagePath(String package) async => _inner.packagePath(package); }
diff --git a/lib/src/current_isolate_resolver.dart b/lib/src/current_isolate_resolver.dart index e3b9770..f06a19a 100644 --- a/lib/src/current_isolate_resolver.dart +++ b/lib/src/current_isolate_resolver.dart
@@ -16,6 +16,7 @@ PackageResolver currentIsolateResolver() => _CurrentIsolateResolver(); class _CurrentIsolateResolver implements PackageResolver { + @override Future<Map<String, Uri>> get packageConfigMap async { if (_packageConfigMap != null) return _packageConfigMap; @@ -27,11 +28,14 @@ Map<String, Uri> _packageConfigMap; + @override Future<Uri> get packageConfigUri => Isolate.packageConfig; // ignore: deprecated_member_use + @override Future<Uri> get packageRoot => Isolate.packageRoot; + @override Future<SyncPackageResolver> get asSync async { var root = await packageRoot; if (root != null) return PackageRootResolver(root); @@ -46,24 +50,29 @@ return PackageConfigResolver(map, uri: await packageConfigUri); } + @override Future<String> get processArgument async { var configUri = await packageConfigUri; - if (configUri != null) return "--packages=$configUri"; + if (configUri != null) return '--packages=$configUri'; var root = await packageRoot; - if (root != null) return "--package-root=$root"; + if (root != null) return '--package-root=$root'; return null; } + @override Future<Uri> resolveUri(packageUri) => - Isolate.resolvePackageUri(asPackageUri(packageUri, "packageUri")); + Isolate.resolvePackageUri(asPackageUri(packageUri, 'packageUri')); + @override Future<Uri> urlFor(String package, [String path]) => Isolate.resolvePackageUri(Uri.parse("package:$package/${path ?? ''}")); + @override Future<Uri> packageUriFor(url) async => (await asSync).packageUriFor(url); + @override Future<String> packagePath(String package) async { var root = await packageRoot; if (root != null) return PackageRootResolver(root).packagePath(package);
diff --git a/lib/src/no_package_resolver.dart b/lib/src/no_package_resolver.dart index 50ea132..f534bb7 100644 --- a/lib/src/no_package_resolver.dart +++ b/lib/src/no_package_resolver.dart
@@ -9,26 +9,35 @@ /// A package resolution strategy that is unable to resolve any `package:` URIs. class NoPackageResolver implements SyncPackageResolver { + @override Map<String, Uri> get packageConfigMap => null; + @override Uri get packageConfigUri => null; + @override Uri get packageRoot => null; + @override String get processArgument => null; + @override PackageResolver get asAsync => AsyncPackageResolver(this); + @override Uri resolveUri(packageUri) { // Verify that the URI is valid. - asPackageUri(packageUri, "packageUri"); + asPackageUri(packageUri, 'packageUri'); return null; } + @override Uri urlFor(String package, [String path]) => null; + @override Uri packageUriFor(url) { // Verify that the URI is a valid type. - asUri(url, "url"); + asUri(url, 'url'); return null; } + @override String packagePath(String package) => null; }
diff --git a/lib/src/package_config_resolver.dart b/lib/src/package_config_resolver.dart index 9d56b2e..b57e5d0 100644 --- a/lib/src/package_config_resolver.dart +++ b/lib/src/package_config_resolver.dart
@@ -15,30 +15,35 @@ /// A package resolution strategy based on a package config map. class PackageConfigResolver implements SyncPackageResolver { + @override final packageRoot = null; + @override final Map<String, Uri> packageConfigMap; + @override Uri get packageConfigUri { if (_uri != null) return _uri; var buffer = StringBuffer(); - packages_file.write(buffer, packageConfigMap, comment: ""); + packages_file.write(buffer, packageConfigMap, comment: ''); _uri = - UriData.fromString(buffer.toString(), parameters: {"charset": "utf-8"}) + UriData.fromString(buffer.toString(), parameters: {'charset': 'utf-8'}) .uri; return _uri; } Uri _uri; + @override PackageResolver get asAsync => AsyncPackageResolver(this); - String get processArgument => "--packages=$packageConfigUri"; + @override + String get processArgument => '--packages=$packageConfigUri'; PackageConfigResolver(Map<String, Uri> packageConfigMap, {uri}) : packageConfigMap = _normalizeMap(packageConfigMap), - _uri = uri == null ? null : asUri(uri, "uri"); + _uri = uri == null ? null : asUri(uri, 'uri'); /// Normalizes the URIs in [map] to ensure that they all end in a trailing /// slash. @@ -46,8 +51,9 @@ UnmodifiableMapView( mapMap(map, value: (_, uri) => ensureTrailingSlash(uri))); + @override Uri resolveUri(packageUri) { - var uri = asPackageUri(packageUri, "packageUri"); + var uri = asPackageUri(packageUri, 'packageUri'); var baseUri = packageConfigMap[uri.pathSegments.first]; if (baseUri == null) return null; @@ -62,6 +68,7 @@ return baseUri.replace(pathSegments: segments); } + @override Uri urlFor(String package, [String path]) { var baseUri = packageConfigMap[package]; if (baseUri == null) return null; @@ -69,23 +76,25 @@ return baseUri.resolve(path); } + @override Uri packageUriFor(url) { - url = asUri(url, "url").toString(); + url = asUri(url, 'url').toString(); // Make sure isWithin works if [url] is exactly the base. - var nested = p.url.join(url, "_"); + var nested = p.url.join(url, '_'); for (var package in packageConfigMap.keys) { var base = packageConfigMap[package].toString(); if (!p.url.isWithin(base, nested)) continue; var relative = p.url.relative(url, from: base); if (relative == '.') relative = ''; - return Uri.parse("package:$package/$relative"); + return Uri.parse('package:$package/$relative'); } return null; } + @override String packagePath(String package) { var lib = packageConfigMap[package]; if (lib == null) return null;
diff --git a/lib/src/package_root_resolver.dart b/lib/src/package_root_resolver.dart index c0e96c7..d6e6299 100644 --- a/lib/src/package_root_resolver.dart +++ b/lib/src/package_root_resolver.dart
@@ -11,41 +11,50 @@ /// A package resolution strategy based on a package root URI. class PackageRootResolver implements SyncPackageResolver { + @override final packageConfigMap = null; + @override final packageConfigUri = null; + @override final Uri packageRoot; + @override PackageResolver get asAsync => AsyncPackageResolver(this); - String get processArgument => "--package-root=$packageRoot"; + @override + String get processArgument => '--package-root=$packageRoot'; PackageRootResolver(packageRoot) - : packageRoot = ensureTrailingSlash(asUri(packageRoot, "packageRoot")); + : packageRoot = ensureTrailingSlash(asUri(packageRoot, 'packageRoot')); + @override Uri resolveUri(packageUri) { - packageUri = asPackageUri(packageUri, "packageUri"); + packageUri = asPackageUri(packageUri, 'packageUri'); // Following [Isolate.resolvePackageUri], "package:foo" resolves to null. if (packageUri.pathSegments.length == 1) return null; return packageRoot.resolve(packageUri.path); } + @override Uri urlFor(String package, [String path]) { - var result = packageRoot.resolve("$package/"); + var result = packageRoot.resolve('$package/'); return path == null ? result : result.resolve(path); } + @override Uri packageUriFor(url) { var packageRootString = packageRoot.toString(); - url = asUri(url, "url").toString(); + url = asUri(url, 'url').toString(); if (!p.url.isWithin(packageRootString, url)) return null; var relative = p.url.relative(url, from: packageRootString); - if (!relative.contains("/")) relative += "/"; - return Uri.parse("package:$relative"); + if (!relative.contains('/')) relative += '/'; + return Uri.parse('package:$relative'); } + @override String packagePath(String package) => packagePathForRoot(package, packageRoot); }
diff --git a/lib/src/sync_package_resolver.dart b/lib/src/sync_package_resolver.dart index 1b7b47e..796d332 100644 --- a/lib/src/sync_package_resolver.dart +++ b/lib/src/sync_package_resolver.dart
@@ -100,7 +100,7 @@ /// [uri] may be a [String] or a [Uri]. static Future<SyncPackageResolver> loadConfig(uri, {http.Client client}) async { - uri = asUri(uri, "uri"); + uri = asUri(uri, 'uri'); return SyncPackageResolver.config(await loadConfigMap(uri, client: client), uri: uri); }
diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 1609d56..04a174c 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart
@@ -53,10 +53,10 @@ if (uri.scheme != 'package') { throw FormatException( - "Can only resolve a package: URI.", uri.toString(), 0); + 'Can only resolve a package: URI.', uri.toString(), 0); } else if (uri.pathSegments.isEmpty) { throw FormatException( - "Expected package name.", uri.toString(), "package:".length); + 'Expected package name.', uri.toString(), 'package:'.length); } return uri; @@ -70,16 +70,16 @@ if (uri is Uri) return uri; if (uri is String) return Uri.parse(uri); - throw ArgumentError.value(uri, name, "Must be a String or a Uri."); + throw ArgumentError.value(uri, name, 'Must be a String or a Uri.'); } /// Returns a copy of [uri] with a trailing slash. /// /// If [uri] already ends in a slash, returns it as-is. Uri ensureTrailingSlash(Uri uri) { - if (uri.pathSegments.isEmpty) return uri.replace(path: "/"); + if (uri.pathSegments.isEmpty) return uri.replace(path: '/'); if (uri.pathSegments.last.isEmpty) return uri; - return uri.replace(pathSegments: uri.pathSegments.toList()..add("")); + return uri.replace(pathSegments: uri.pathSegments.toList()..add('')); } String packagePathForRoot(String package, Uri root) =>
diff --git a/test/current_isolate_info_test.dart b/test/current_isolate_info_test.dart index 4377ef8..551fe3d 100644 --- a/test/current_isolate_info_test.dart +++ b/test/current_isolate_info_test.dart
@@ -17,18 +17,18 @@ // It's important to test these, because they use PackageConfig.current and // they're used to verify the output of the inner isolate's // PackageConfig.current. - test("_packageResolverLibUri is correct", () async { + test('_packageResolverLibUri is correct', () async { var libPath = p.fromUri(await _packageResolverLibUri); expect(File(p.join(libPath, 'package_resolver.dart')).exists(), completion(isTrue)); }); - test("_pathLibUri is correct", () async { + test('_pathLibUri is correct', () async { var libPath = p.fromUri(await _pathLibUri); expect(File(p.join(libPath, 'path.dart')).exists(), completion(isTrue)); }); - group("with a package config", () { + group('with a package config', () { var resolver; setUp(() async { var map; @@ -49,65 +49,65 @@ // Ensure that we have at least one URI that ends with "/" and one that // doesn't. Both of these cases need to be tested. - expect(map["package_resolver"].path, endsWith("/")); - map["path"] = Uri.parse(p.url.normalize(map["path"].toString())); - expect(map["path"].path, isNot(endsWith("/"))); + expect(map['package_resolver'].path, endsWith('/')); + map['path'] = Uri.parse(p.url.normalize(map['path'].toString())); + expect(map['path'].path, isNot(endsWith('/'))); resolver = PackageResolver.config(map); }); - test("exposes the config map", () async { - expect(await _spawn("""() async { + test('exposes the config map', () async { + expect(await _spawn('''() async { var serializable = {}; (await PackageResolver.current.packageConfigMap) .forEach((package, uri) { serializable[package] = uri.toString(); }); return serializable; - }()""", resolver), - containsPair("package_resolver", await _packageResolverLibUri)); + }()''', resolver), + containsPair('package_resolver', await _packageResolverLibUri)); }); - test("exposes the config URI", () async { + test('exposes the config URI', () async { expect( await _spawn( - "(await PackageResolver.current.packageConfigUri).toString()", + '(await PackageResolver.current.packageConfigUri).toString()', resolver), equals((await resolver.packageConfigUri).toString())); }); - test("exposes a null package root", () async { + test('exposes a null package root', () async { expect( // Use "== null" because if it *is* a URI, it'll crash the isolate // when we try to send it over the port. await _spawn( - "(await PackageResolver.current.packageRoot) == null", resolver), + '(await PackageResolver.current.packageRoot) == null', resolver), isTrue); }); - test("processArgument uses --packages", () async { - expect(await _spawn("PackageResolver.current.processArgument", resolver), + test('processArgument uses --packages', () async { + expect(await _spawn('PackageResolver.current.processArgument', resolver), equals(await resolver.processArgument)); }); - group("resolveUri", () { - test("with a matching package", () async { + group('resolveUri', () { + test('with a matching package', () async { expect(await _spawn("""() async { var uri = await PackageResolver.current.resolveUri( 'package:package_resolver/foo/bar.dart'); return uri.toString(); }()""", resolver), - equals(p.url.join(await _packageResolverLibUri, "foo/bar.dart"))); + equals(p.url.join(await _packageResolverLibUri, 'foo/bar.dart'))); expect(await _spawn("""() async { var uri = await PackageResolver.current.resolveUri( 'package:path/foo/bar.dart'); return uri.toString(); }()""", resolver), - equals(p.url.join(await _pathLibUri, "foo/bar.dart"))); + equals(p.url.join(await _pathLibUri, 'foo/bar.dart'))); }); - test("with a matching package with no path", () async { + test('with a matching package with no path', () async { expect(await _spawn("""() async { var uri = await PackageResolver.current.resolveUri( 'package:package_resolver'); @@ -120,7 +120,7 @@ }()""", resolver), isTrue); }); - test("with a matching package with an empty path", () async { + test('with a matching package with an empty path', () async { expect(await _spawn("""() async { var uri = await PackageResolver.current.resolveUri( 'package:package_resolver/'); @@ -133,7 +133,7 @@ }()""", resolver), (await _pathLibUri).toString()); }); - test("with a URI object", () async { + test('with a URI object', () async { expect(await _spawn("""() async { var uri = await PackageResolver.current.resolveUri( Uri.parse('package:package_resolver/foo/bar.dart')); @@ -142,7 +142,7 @@ equals(p.url.join(await _packageResolverLibUri, 'foo/bar.dart'))); }); - test("with a non-matching package", () async { + test('with a non-matching package', () async { expect(await _spawn("""() async { var uri = await PackageResolver.current.resolveUri( Uri.parse('package:not-a-package/foo/bar.dart')); @@ -150,18 +150,18 @@ }()""", resolver), isTrue); }); - test("with an invalid argument type", () async { - expect(await _spawn("""() async { + test('with an invalid argument type', () async { + expect(await _spawn('''() async { try { await PackageResolver.current.resolveUri(12); return false; } on ArgumentError catch (_) { return true; } - }()""", resolver), isTrue); + }()''', resolver), isTrue); }); - test("with a non-package URI", () async { + test('with a non-package URI', () async { expect(await _spawn("""() async { try { await PackageResolver.current.resolveUri('file:///zip/zap'); @@ -172,15 +172,15 @@ }()""", resolver), isTrue); }); - test("with an invalid package URI", () async { - expect(await _spawn("""() async { + test('with an invalid package URI', () async { + expect(await _spawn('''() async { try { await PackageResolver.current.resolveUri("package:"); return false; } on FormatException catch (_) { return true; } - }()""", resolver), isTrue); + }()''', resolver), isTrue); }); }); }); @@ -215,8 +215,8 @@ message.send(await ($expression)); } """, - mimeType: "application/dart", - parameters: {"charset": "utf-8"}); + mimeType: 'application/dart', + parameters: {'charset': 'utf-8'}); var receivePort = ReceivePort(); var errorPort = ReceivePort();
diff --git a/test/no_package_info_test.dart b/test/no_package_info_test.dart index 1679808..ee9c8b2 100644 --- a/test/no_package_info_test.dart +++ b/test/no_package_info_test.dart
@@ -12,34 +12,34 @@ resolver = SyncPackageResolver.none; }); - test("exposes everything as null", () { + test('exposes everything as null', () { expect(resolver.packageConfigMap, isNull); expect(resolver.packageConfigUri, isNull); expect(resolver.packageRoot, isNull); expect(resolver.processArgument, isNull); - expect(resolver.resolveUri("package:foo/bar.dart"), isNull); - expect(resolver.urlFor("foo"), isNull); - expect(resolver.urlFor("foo", "bar.dart"), isNull); - expect(resolver.packageUriFor("file:///foo/bar.dart"), isNull); - expect(resolver.packagePath("foo"), isNull); + expect(resolver.resolveUri('package:foo/bar.dart'), isNull); + expect(resolver.urlFor('foo'), isNull); + expect(resolver.urlFor('foo', 'bar.dart'), isNull); + expect(resolver.packageUriFor('file:///foo/bar.dart'), isNull); + expect(resolver.packagePath('foo'), isNull); }); - group("resolveUri", () { - test("with an invalid argument type", () { + group('resolveUri', () { + test('with an invalid argument type', () { expect(() => resolver.resolveUri(12), throwsArgumentError); }); - test("with a non-package URI", () { + test('with a non-package URI', () { expect( - () => resolver.resolveUri("file:///zip/zap"), throwsFormatException); + () => resolver.resolveUri('file:///zip/zap'), throwsFormatException); }); - test("with an invalid package URI", () { - expect(() => resolver.resolveUri("package:"), throwsFormatException); + test('with an invalid package URI', () { + expect(() => resolver.resolveUri('package:'), throwsFormatException); }); }); - test("packageUriFor with an invalid argument type", () { + test('packageUriFor with an invalid argument type', () { expect(() => resolver.packageUriFor(12), throwsArgumentError); }); }
diff --git a/test/package_config_info_test.dart b/test/package_config_info_test.dart index a4a1c12..8eb00f4 100644 --- a/test/package_config_info_test.dart +++ b/test/package_config_info_test.dart
@@ -15,168 +15,168 @@ SyncPackageResolver resolver; setUp(() { resolver = SyncPackageResolver.config({ - "foo": Uri.parse("file:///foo/bar/"), - "bar": Uri.parse("http://dartlang.org/bar") - }, uri: "file:///myapp/.packages"); + 'foo': Uri.parse('file:///foo/bar/'), + 'bar': Uri.parse('http://dartlang.org/bar') + }, uri: 'file:///myapp/.packages'); }); - group("constructor", () { - test("with a URI object", () { + group('constructor', () { + test('with a URI object', () { var resolver = SyncPackageResolver.config({}, - uri: Uri.parse("file:///myapp/.packages")); + uri: Uri.parse('file:///myapp/.packages')); expect(resolver.packageConfigUri, - equals(Uri.parse("file:///myapp/.packages"))); + equals(Uri.parse('file:///myapp/.packages'))); }); - test("with an invalid URI type", () { + test('with an invalid URI type', () { expect( () => SyncPackageResolver.config({}, uri: 12), throwsArgumentError); }); }); - test("exposes the config map", () { + test('exposes the config map', () { expect( resolver.packageConfigMap, equals({ - "foo": Uri.parse("file:///foo/bar/"), - "bar": Uri.parse("http://dartlang.org/bar/") + 'foo': Uri.parse('file:///foo/bar/'), + 'bar': Uri.parse('http://dartlang.org/bar/') })); }); - test("exposes the config URI if passed", () { + test('exposes the config URI if passed', () { expect(resolver.packageConfigUri, - equals(Uri.parse("file:///myapp/.packages"))); + equals(Uri.parse('file:///myapp/.packages'))); }); - test("exposes a data: config URI if none is passed", () { + test('exposes a data: config URI if none is passed', () { resolver = SyncPackageResolver.config(resolver.packageConfigMap); expect( resolver.packageConfigUri, - equals(Uri.parse("data:;charset=utf-8," - "foo:file:///foo/bar/%0A" - "bar:http://dartlang.org/bar/%0A"))); + equals(Uri.parse('data:;charset=utf-8,' + 'foo:file:///foo/bar/%0A' + 'bar:http://dartlang.org/bar/%0A'))); }); - test("exposes a null root", () { + test('exposes a null root', () { expect(resolver.packageRoot, isNull); }); - test("processArgument uses --packages", () { + test('processArgument uses --packages', () { expect( - resolver.processArgument, equals("--packages=file:///myapp/.packages")); + resolver.processArgument, equals('--packages=file:///myapp/.packages')); }); - group("resolveUri", () { - test("with a matching package", () { - expect(resolver.resolveUri("package:foo/bang/qux.dart"), - equals(Uri.parse("file:///foo/bar/bang/qux.dart"))); - expect(resolver.resolveUri("package:bar/bang/qux.dart"), - equals(Uri.parse("http://dartlang.org/bar/bang/qux.dart"))); + group('resolveUri', () { + test('with a matching package', () { + expect(resolver.resolveUri('package:foo/bang/qux.dart'), + equals(Uri.parse('file:///foo/bar/bang/qux.dart'))); + expect(resolver.resolveUri('package:bar/bang/qux.dart'), + equals(Uri.parse('http://dartlang.org/bar/bang/qux.dart'))); }); - test("with a matching package with no path", () { - expect(resolver.resolveUri("package:foo"), isNull); + test('with a matching package with no path', () { + expect(resolver.resolveUri('package:foo'), isNull); }); - test("with a matching package with an empty path", () { - expect(resolver.resolveUri("package:bar/"), - equals(Uri.parse("http://dartlang.org/bar/"))); + test('with a matching package with an empty path', () { + expect(resolver.resolveUri('package:bar/'), + equals(Uri.parse('http://dartlang.org/bar/'))); }); - test("with a URI object", () { - expect(resolver.resolveUri(Uri.parse("package:foo/bang/qux.dart")), - equals(Uri.parse("file:///foo/bar/bang/qux.dart"))); + test('with a URI object', () { + expect(resolver.resolveUri(Uri.parse('package:foo/bang/qux.dart')), + equals(Uri.parse('file:///foo/bar/bang/qux.dart'))); }); - test("with a non-matching package", () { - expect(resolver.resolveUri("package:zap/bang/qux.dart"), isNull); + test('with a non-matching package', () { + expect(resolver.resolveUri('package:zap/bang/qux.dart'), isNull); }); - test("with an invalid argument type", () { + test('with an invalid argument type', () { expect(() => resolver.resolveUri(12), throwsArgumentError); }); - test("with a non-package URI", () { + test('with a non-package URI', () { expect( - () => resolver.resolveUri("file:///zip/zap"), throwsFormatException); + () => resolver.resolveUri('file:///zip/zap'), throwsFormatException); }); - test("with an invalid package URI", () { - expect(() => resolver.resolveUri("package:"), throwsFormatException); + test('with an invalid package URI', () { + expect(() => resolver.resolveUri('package:'), throwsFormatException); }); }); - group("urlFor", () { - test("with a matching package and no path", () { - expect(resolver.urlFor("foo"), equals(Uri.parse("file:///foo/bar/"))); - expect(resolver.urlFor("bar"), - equals(Uri.parse("http://dartlang.org/bar/"))); + group('urlFor', () { + test('with a matching package and no path', () { + expect(resolver.urlFor('foo'), equals(Uri.parse('file:///foo/bar/'))); + expect(resolver.urlFor('bar'), + equals(Uri.parse('http://dartlang.org/bar/'))); }); - test("with a matching package and a path", () { - expect(resolver.urlFor("foo", "bang/qux.dart"), - equals(Uri.parse("file:///foo/bar/bang/qux.dart"))); - expect(resolver.urlFor("bar", "bang/qux.dart"), - equals(Uri.parse("http://dartlang.org/bar/bang/qux.dart"))); + test('with a matching package and a path', () { + expect(resolver.urlFor('foo', 'bang/qux.dart'), + equals(Uri.parse('file:///foo/bar/bang/qux.dart'))); + expect(resolver.urlFor('bar', 'bang/qux.dart'), + equals(Uri.parse('http://dartlang.org/bar/bang/qux.dart'))); }); - test("with a non-matching package and no path", () { - expect(resolver.urlFor("zap"), isNull); + test('with a non-matching package and no path', () { + expect(resolver.urlFor('zap'), isNull); }); }); - group("packageUriFor", () { - test("converts matching URIs to package:", () { - expect(resolver.packageUriFor("file:///foo/bar/bang/qux.dart"), - equals(Uri.parse("package:foo/bang/qux.dart"))); - expect(resolver.packageUriFor("http://dartlang.org/bar/bang/qux.dart"), - equals(Uri.parse("package:bar/bang/qux.dart"))); + group('packageUriFor', () { + test('converts matching URIs to package:', () { + expect(resolver.packageUriFor('file:///foo/bar/bang/qux.dart'), + equals(Uri.parse('package:foo/bang/qux.dart'))); + expect(resolver.packageUriFor('http://dartlang.org/bar/bang/qux.dart'), + equals(Uri.parse('package:bar/bang/qux.dart'))); }); - test("converts URIs with no paths", () { - expect(resolver.packageUriFor("file:///foo/bar"), - equals(Uri.parse("package:foo/"))); - expect(resolver.packageUriFor("http://dartlang.org/bar/"), - equals(Uri.parse("package:bar/"))); + test('converts URIs with no paths', () { + expect(resolver.packageUriFor('file:///foo/bar'), + equals(Uri.parse('package:foo/'))); + expect(resolver.packageUriFor('http://dartlang.org/bar/'), + equals(Uri.parse('package:bar/'))); }); - test("with a URI object", () { - expect(resolver.packageUriFor(Uri.parse("file:///foo/bar/bang/qux.dart")), - equals(Uri.parse("package:foo/bang/qux.dart"))); + test('with a URI object', () { + expect(resolver.packageUriFor(Uri.parse('file:///foo/bar/bang/qux.dart')), + equals(Uri.parse('package:foo/bang/qux.dart'))); }); - test("with an invalid argument type", () { + test('with an invalid argument type', () { expect(() => resolver.packageUriFor(12), throwsArgumentError); }); }); - group("packagePath", () { + group('packagePath', () { setUp(() { resolver = SyncPackageResolver.config({ - "foo": p.toUri(p.join(p.current, 'lib')), - "bar": Uri.parse("http://dartlang.org/bar") + 'foo': p.toUri(p.join(p.current, 'lib')), + 'bar': Uri.parse('http://dartlang.org/bar') }); }); - test("with a matching package", () { - expect(resolver.packagePath("foo"), equals(p.current)); - }, testOn: "vm"); + test('with a matching package', () { + expect(resolver.packagePath('foo'), equals(p.current)); + }, testOn: 'vm'); - test("with a package with a non-file scheme", () { - expect(resolver.packagePath("bar"), isNull); + test('with a package with a non-file scheme', () { + expect(resolver.packagePath('bar'), isNull); }); - test("with a non-matching", () { - expect(resolver.packagePath("baz"), isNull); + test('with a non-matching', () { + expect(resolver.packagePath('baz'), isNull); }); }); - group("loadConfig", () { + group('loadConfig', () { var server; var sandbox; setUp(() async { sandbox = - (await Directory.systemTemp.createTemp("package_resolver_test")).path; + (await Directory.systemTemp.createTemp('package_resolver_test')).path; }); tearDown(() async { @@ -184,29 +184,29 @@ await Directory(sandbox).delete(recursive: true); }); - test("with an http: URI", () async { + test('with an http: URI', () async { server = await shelf_io.serve((request) { - return shelf.Response.ok("foo:file:///foo/bar/\n" - "bar:http://dartlang.org/bar/"); + return shelf.Response.ok('foo:file:///foo/bar/\n' + 'bar:http://dartlang.org/bar/'); }, 'localhost', 0); var resolver = await SyncPackageResolver.loadConfig( - "http://localhost:${server.port}"); + 'http://localhost:${server.port}'); expect( resolver.packageConfigMap, equals({ - "foo": Uri.parse("file:///foo/bar/"), - "bar": Uri.parse("http://dartlang.org/bar/") + 'foo': Uri.parse('file:///foo/bar/'), + 'bar': Uri.parse('http://dartlang.org/bar/') })); expect(resolver.packageConfigUri, - equals(Uri.parse("http://localhost:${server.port}"))); + equals(Uri.parse('http://localhost:${server.port}'))); }); - test("with a file: URI", () async { - var packagesPath = p.join(sandbox, ".packages"); - File(packagesPath).writeAsStringSync("foo:file:///foo/bar/\n" - "bar:http://dartlang.org/bar/"); + test('with a file: URI', () async { + var packagesPath = p.join(sandbox, '.packages'); + File(packagesPath).writeAsStringSync('foo:file:///foo/bar/\n' + 'bar:http://dartlang.org/bar/'); var resolver = await SyncPackageResolver.loadConfig(p.toUri(packagesPath)); @@ -214,46 +214,46 @@ expect( resolver.packageConfigMap, equals({ - "foo": Uri.parse("file:///foo/bar/"), - "bar": Uri.parse("http://dartlang.org/bar/") + 'foo': Uri.parse('file:///foo/bar/'), + 'bar': Uri.parse('http://dartlang.org/bar/') })); expect(resolver.packageConfigUri, equals(p.toUri(packagesPath))); }); - test("with a data: URI", () async { - var data = Uri.parse("data:;charset=utf-8," - "foo:file:///foo/bar/%0A" - "bar:http://dartlang.org/bar/%0A"); + test('with a data: URI', () async { + var data = Uri.parse('data:;charset=utf-8,' + 'foo:file:///foo/bar/%0A' + 'bar:http://dartlang.org/bar/%0A'); var resolver = await SyncPackageResolver.loadConfig(data); expect( resolver.packageConfigMap, equals({ - "foo": Uri.parse("file:///foo/bar/"), - "bar": Uri.parse("http://dartlang.org/bar/") + 'foo': Uri.parse('file:///foo/bar/'), + 'bar': Uri.parse('http://dartlang.org/bar/') })); expect(resolver.packageConfigUri, equals(data)); }); - test("with a package: URI", () async { + test('with a package: URI', () async { var resolver = await SyncPackageResolver.loadConfig( - "package:package_resolver/src/test_package_config"); + 'package:package_resolver/src/test_package_config'); expect( resolver.packageConfigMap, equals({ - "foo": Uri.parse("file:///foo/bar/"), - "bar": Uri.parse("http://dartlang.org/bar/") + 'foo': Uri.parse('file:///foo/bar/'), + 'bar': Uri.parse('http://dartlang.org/bar/') })); expect( resolver.packageConfigUri, equals( - Uri.parse("package:package_resolver/src/test_package_config"))); + Uri.parse('package:package_resolver/src/test_package_config'))); }); - test("with an unsupported scheme", () { - expect(SyncPackageResolver.loadConfig("asdf:foo/bar"), + test('with an unsupported scheme', () { + expect(SyncPackageResolver.loadConfig('asdf:foo/bar'), throwsUnsupportedError); }); - }, testOn: "vm"); + }, testOn: 'vm'); }
diff --git a/test/package_root_info_test.dart b/test/package_root_info_test.dart index 200d6e5..8eb06cf 100644 --- a/test/package_root_info_test.dart +++ b/test/package_root_info_test.dart
@@ -12,142 +12,142 @@ void main() { var resolver; setUp(() { - resolver = SyncPackageResolver.root("file:///foo/bar"); + resolver = SyncPackageResolver.root('file:///foo/bar'); }); - group("constructor", () { - test("with a URI object", () { - var resolver = SyncPackageResolver.root(Uri.parse("file:///foo/bar/")); - expect(resolver.packageRoot, equals(Uri.parse("file:///foo/bar/"))); + group('constructor', () { + test('with a URI object', () { + var resolver = SyncPackageResolver.root(Uri.parse('file:///foo/bar/')); + expect(resolver.packageRoot, equals(Uri.parse('file:///foo/bar/'))); }); - test("with a URI without a path component", () { + test('with a URI without a path component', () { var resolver = - SyncPackageResolver.root(Uri.parse("http://localhost:1234")); - expect(resolver.packageRoot, equals(Uri.parse("http://localhost:1234/"))); + SyncPackageResolver.root(Uri.parse('http://localhost:1234')); + expect(resolver.packageRoot, equals(Uri.parse('http://localhost:1234/'))); }); - test("with an invalid URI type", () { + test('with an invalid URI type', () { expect(() => SyncPackageResolver.root(12), throwsArgumentError); }); }); - test("exposes a null config map", () { + test('exposes a null config map', () { expect(resolver.packageConfigMap, isNull); }); - test("exposes a null config URI", () { + test('exposes a null config URI', () { expect(resolver.packageConfigUri, isNull); }); - test("exposes the root root", () { - expect(resolver.packageRoot, equals(Uri.parse("file:///foo/bar/"))); + test('exposes the root root', () { + expect(resolver.packageRoot, equals(Uri.parse('file:///foo/bar/'))); }); - test("processArgument uses --package-root", () { - expect(resolver.processArgument, equals("--package-root=file:///foo/bar/")); + test('processArgument uses --package-root', () { + expect(resolver.processArgument, equals('--package-root=file:///foo/bar/')); }); - group("resolveUri", () { - test("with a package", () { - expect(resolver.resolveUri("package:baz/bang/qux.dart"), - equals(Uri.parse("file:///foo/bar/baz/bang/qux.dart"))); + group('resolveUri', () { + test('with a package', () { + expect(resolver.resolveUri('package:baz/bang/qux.dart'), + equals(Uri.parse('file:///foo/bar/baz/bang/qux.dart'))); }); - test("with a package with no path", () { - expect(resolver.resolveUri("package:baz"), isNull); + test('with a package with no path', () { + expect(resolver.resolveUri('package:baz'), isNull); }); - test("with a package with an empty path", () { - expect(resolver.resolveUri("package:baz/"), - equals(Uri.parse("file:///foo/bar/baz/"))); + test('with a package with an empty path', () { + expect(resolver.resolveUri('package:baz/'), + equals(Uri.parse('file:///foo/bar/baz/'))); }); - test("with a URI object", () { - expect(resolver.resolveUri(Uri.parse("package:baz/bang/qux.dart")), - equals(Uri.parse("file:///foo/bar/baz/bang/qux.dart"))); + test('with a URI object', () { + expect(resolver.resolveUri(Uri.parse('package:baz/bang/qux.dart')), + equals(Uri.parse('file:///foo/bar/baz/bang/qux.dart'))); }); - test("with an invalid argument type", () { + test('with an invalid argument type', () { expect(() => resolver.resolveUri(12), throwsArgumentError); }); - test("with a non-package URI", () { + test('with a non-package URI', () { expect( - () => resolver.resolveUri("file:///zip/zap"), throwsFormatException); + () => resolver.resolveUri('file:///zip/zap'), throwsFormatException); }); - test("with an invalid package URI", () { - expect(() => resolver.resolveUri("package:"), throwsFormatException); + test('with an invalid package URI', () { + expect(() => resolver.resolveUri('package:'), throwsFormatException); }); }); - group("urlFor", () { - test("with no path", () { - expect(resolver.urlFor("baz"), equals(Uri.parse("file:///foo/bar/baz/"))); + group('urlFor', () { + test('with no path', () { + expect(resolver.urlFor('baz'), equals(Uri.parse('file:///foo/bar/baz/'))); }); - test("with a path", () { - expect(resolver.urlFor("baz", "bang/qux.dart"), - equals(Uri.parse("file:///foo/bar/baz/bang/qux.dart"))); + test('with a path', () { + expect(resolver.urlFor('baz', 'bang/qux.dart'), + equals(Uri.parse('file:///foo/bar/baz/bang/qux.dart'))); }); }); - group("packageUriFor", () { - test("converts a matching URI to a package:", () { - expect(resolver.packageUriFor("file:///foo/bar/bang/qux.dart"), - equals(Uri.parse("package:bang/qux.dart"))); + group('packageUriFor', () { + test('converts a matching URI to a package:', () { + expect(resolver.packageUriFor('file:///foo/bar/bang/qux.dart'), + equals(Uri.parse('package:bang/qux.dart'))); }); - test("converts a matching URI with no path", () { - expect(resolver.packageUriFor("file:///foo/bar/baz"), - equals(Uri.parse("package:baz/"))); - expect(resolver.packageUriFor("file:///foo/bar/baz/"), - equals(Uri.parse("package:baz/"))); + test('converts a matching URI with no path', () { + expect(resolver.packageUriFor('file:///foo/bar/baz'), + equals(Uri.parse('package:baz/'))); + expect(resolver.packageUriFor('file:///foo/bar/baz/'), + equals(Uri.parse('package:baz/'))); }); - test("with a URI object", () { - expect(resolver.packageUriFor(Uri.parse("file:///foo/bar/bang/qux.dart")), - equals(Uri.parse("package:bang/qux.dart"))); + test('with a URI object', () { + expect(resolver.packageUriFor(Uri.parse('file:///foo/bar/bang/qux.dart')), + equals(Uri.parse('package:bang/qux.dart'))); }); - test("with an invalid argument type", () { + test('with an invalid argument type', () { expect(() => resolver.packageUriFor(12), throwsArgumentError); }); }); - group("packagePath", () { + group('packagePath', () { var sandbox; setUp(() async { sandbox = - (await Directory.systemTemp.createTemp("package_resolver_test")).path; + (await Directory.systemTemp.createTemp('package_resolver_test')).path; }); tearDown(() async { await Directory(sandbox).delete(recursive: true); }); - test("with a file: scheme", () async { - var packageLib = p.join(sandbox, "foo/lib"); + test('with a file: scheme', () async { + var packageLib = p.join(sandbox, 'foo/lib'); await Directory(packageLib).create(recursive: true); - var packagesDir = p.join(sandbox, "packages"); - var fooLink = p.join(packagesDir, "foo"); + var packagesDir = p.join(sandbox, 'packages'); + var fooLink = p.join(packagesDir, 'foo'); await Link(fooLink).create(packageLib, recursive: true); - var packagesLink = p.join(sandbox, "foo/packages"); + var packagesLink = p.join(sandbox, 'foo/packages'); await Link(packagesLink).create(packagesDir); var resolver = SyncPackageResolver.root(p.toUri(packagesLink)); - expect(resolver.packagePath("foo"), - equals(Directory(p.join(sandbox, "foo")).resolveSymbolicLinksSync())); - expect(resolver.packagePath("bar"), isNull); + expect(resolver.packagePath('foo'), + equals(Directory(p.join(sandbox, 'foo')).resolveSymbolicLinksSync())); + expect(resolver.packagePath('bar'), isNull); }); - test("without a file: scheme", () { - var resolver = SyncPackageResolver.root("http://dartlang.org/bar"); - expect(resolver.packagePath("foo"), isNull); + test('without a file: scheme', () { + var resolver = SyncPackageResolver.root('http://dartlang.org/bar'); + expect(resolver.packagePath('foo'), isNull); }); - }, testOn: "vm"); + }, testOn: 'vm'); }