fix new pedantic lints, remove pubspec author (#46)
diff --git a/lib/resource.dart b/lib/resource.dart
index 667b03a..860de6c 100644
--- a/lib/resource.dart
+++ b/lib/resource.dart
@@ -21,5 +21,5 @@
/// .first;
library resource;
-export "src/resource.dart" show Resource;
-export "src/resource_loader.dart" show ResourceLoader;
+export 'src/resource.dart' show Resource;
+export 'src/resource_loader.dart' show ResourceLoader;
diff --git a/lib/src/io_html.dart b/lib/src/io_html.dart
index 3e555a7..c51b0f4 100644
--- a/lib/src/io_html.dart
+++ b/lib/src/io_html.dart
@@ -2,41 +2,41 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import "dart:async" show Future, Stream;
-import "dart:convert" show Encoding;
-import "dart:html";
-import "dart:typed_data" show ByteBuffer;
+import 'dart:async' show Future, Stream;
+import 'dart:convert' show Encoding;
+import 'dart:html';
+import 'dart:typed_data' show ByteBuffer;
/// Reads the bytes of a URI as a stream of bytes.
Stream<List<int>> readAsStream(Uri uri) async* {
// TODO(lrn): Should file be run through XmlHTTPRequest too?
- if (uri.scheme == "http" || uri.scheme == "https") {
+ if (uri.scheme == 'http' || uri.scheme == 'https') {
// TODO: Stream in chunks if DOM has a way to do so.
var response = await _httpGetBytes(uri);
yield response;
return;
}
- if (uri.scheme == "data") {
+ if (uri.scheme == 'data') {
yield uri.data.contentAsBytes();
return;
}
- throw UnsupportedError("Unsupported scheme: $uri");
+ throw UnsupportedError('Unsupported scheme: $uri');
}
/// Reads the bytes of a URI as a list of bytes.
Future<List<int>> readAsBytes(Uri uri) async {
- if (uri.scheme == "http" || uri.scheme == "https") {
+ if (uri.scheme == 'http' || uri.scheme == 'https') {
return _httpGetBytes(uri);
}
- if (uri.scheme == "data") {
+ if (uri.scheme == 'data') {
return uri.data.contentAsBytes();
}
- throw UnsupportedError("Unsupported scheme: $uri");
+ throw UnsupportedError('Unsupported scheme: $uri');
}
/// Reads the bytes of a URI as a string.
Future<String> readAsString(Uri uri, Encoding encoding) async {
- if (uri.scheme == "http" || uri.scheme == "https") {
+ if (uri.scheme == 'http' || uri.scheme == 'https') {
// Fetch as string if the encoding is expected to be understood,
// otherwise fetch as bytes and do decoding using the encoding.
if (encoding != null) {
@@ -44,14 +44,14 @@
}
return HttpRequest.getString(uri.toString());
}
- if (uri.scheme == "data") {
+ if (uri.scheme == 'data') {
return uri.data.contentAsString(encoding: encoding);
}
- throw UnsupportedError("Unsupported scheme: $uri");
+ throw UnsupportedError('Unsupported scheme: $uri');
}
Future<List<int>> _httpGetBytes(Uri uri) {
- return HttpRequest.request(uri.toString(), responseType: "arraybuffer")
+ return HttpRequest.request(uri.toString(), responseType: 'arraybuffer')
.then((request) {
ByteBuffer data = request.response;
return data.asUint8List();
diff --git a/lib/src/io_io.dart b/lib/src/io_io.dart
index 0370ff9..37be1c2 100644
--- a/lib/src/io_io.dart
+++ b/lib/src/io_io.dart
@@ -2,9 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import "dart:async" show Future, Stream;
-import "dart:convert" show Encoding, latin1, utf8;
-import "dart:io"
+import 'dart:async' show Future, Stream;
+import 'dart:convert' show Encoding, latin1, utf8;
+import 'dart:io'
show
File,
HttpStatus,
@@ -14,33 +14,33 @@
HttpException,
HttpHeaders;
-import "package:typed_data/typed_buffers.dart" show Uint8Buffer;
+import 'package:typed_data/typed_buffers.dart' show Uint8Buffer;
/// Read the bytes of a URI as a stream of bytes.
Stream<List<int>> readAsStream(Uri uri) async* {
- if (uri.scheme == "file") {
+ if (uri.scheme == 'file') {
yield* File.fromUri(uri).openRead();
return;
}
- if (uri.scheme == "http" || uri.scheme == "https") {
+ if (uri.scheme == 'http' || uri.scheme == 'https') {
var response = await _httpGetBytes(uri);
_throwIfFailed(response, uri);
yield* response;
return;
}
- if (uri.scheme == "data") {
+ if (uri.scheme == 'data') {
yield uri.data.contentAsBytes();
return;
}
- throw UnsupportedError("Unsupported scheme: $uri");
+ throw UnsupportedError('Unsupported scheme: $uri');
}
/// Read the bytes of a URI as a list of bytes.
Future<List<int>> readAsBytes(Uri uri) async {
- if (uri.scheme == "file") {
+ if (uri.scheme == 'file') {
return File.fromUri(uri).readAsBytes();
}
- if (uri.scheme == "http" || uri.scheme == "https") {
+ if (uri.scheme == 'http' || uri.scheme == 'https') {
var response = await _httpGetBytes(uri);
_throwIfFailed(response, uri);
var length = response.contentLength;
@@ -52,22 +52,22 @@
}
return buffer.toList();
}
- if (uri.scheme == "data") {
+ if (uri.scheme == 'data') {
return uri.data.contentAsBytes();
}
- throw UnsupportedError("Unsupported scheme: $uri");
+ throw UnsupportedError('Unsupported scheme: $uri');
}
/// Read the bytes of a URI as a string.
Future<String> readAsString(Uri uri, Encoding encoding) async {
- if (uri.scheme == "file") {
+ if (uri.scheme == 'file') {
encoding ??= utf8;
return File.fromUri(uri).readAsString(encoding: encoding);
}
- if (uri.scheme == "http" || uri.scheme == "https") {
+ if (uri.scheme == 'http' || uri.scheme == 'https') {
var request = await HttpClient().getUrl(uri);
// Prefer text/plain, text/* if possible, otherwise take whatever is there.
- request.headers.set(HttpHeaders.acceptHeader, "text/plain, text/*, */*");
+ request.headers.set(HttpHeaders.acceptHeader, 'text/plain, text/*, */*');
if (encoding != null) {
request.headers.set(HttpHeaders.acceptCharsetHeader, encoding.name);
}
@@ -89,10 +89,10 @@
}
return response.cast<List<int>>().transform(encoding.decoder).join();
}
- if (uri.scheme == "data") {
+ if (uri.scheme == 'data') {
return uri.data.contentAsString(encoding: encoding);
}
- throw UnsupportedError("Unsupported scheme: $uri");
+ throw UnsupportedError('Unsupported scheme: $uri');
}
HttpClient _sharedHttpClient = HttpClient()..maxConnectionsPerHost = 6;
@@ -101,7 +101,7 @@
// ignore: omit_local_variable_types
HttpClientRequest request = await _sharedHttpClient.getUrl(uri);
request.headers
- .set(HttpHeaders.acceptHeader, "application/octet-stream, */*");
+ .set(HttpHeaders.acceptHeader, 'application/octet-stream, */*');
return request.close();
}
diff --git a/lib/src/io_none.dart b/lib/src/io_none.dart
index bf34510..db22297 100644
--- a/lib/src/io_none.dart
+++ b/lib/src/io_none.dart
@@ -2,30 +2,30 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import "dart:async" show Future, Stream;
-import "dart:convert" show Encoding;
+import 'dart:async' show Future, Stream;
+import 'dart:convert' show Encoding;
/// Read the bytes of a URI as a stream of bytes.
Stream<List<int>> readAsStream(Uri uri) async* {
- if (uri.scheme == "data") {
+ if (uri.scheme == 'data') {
yield uri.data.contentAsBytes();
return;
}
- throw UnsupportedError("Unsupported scheme: $uri");
+ throw UnsupportedError('Unsupported scheme: $uri');
}
/// Read the bytes of a URI as a list of bytes.
Future<List<int>> readAsBytes(Uri uri) async {
- if (uri.scheme == "data") {
+ if (uri.scheme == 'data') {
return uri.data.contentAsBytes();
}
- throw UnsupportedError("Unsupported scheme: $uri");
+ throw UnsupportedError('Unsupported scheme: $uri');
}
/// Read the bytes of a URI as a string.
Future<String> readAsString(Uri uri, Encoding encoding) async {
- if (uri.scheme == "data") {
+ if (uri.scheme == 'data') {
return uri.data.contentAsString(encoding: encoding);
}
- throw UnsupportedError("Unsupported scheme: $uri");
+ throw UnsupportedError('Unsupported scheme: $uri');
}
diff --git a/lib/src/package_loader.dart b/lib/src/package_loader.dart
index 2e39d8c..1fce196 100644
--- a/lib/src/package_loader.dart
+++ b/lib/src/package_loader.dart
@@ -2,11 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import "dart:async" show Future, Stream;
-import "dart:convert" show Encoding;
+import 'dart:async' show Future, Stream;
+import 'dart:convert' show Encoding;
-import "resolve.dart";
-import "resource_loader.dart";
+import 'resolve.dart';
+import 'resource_loader.dart';
/// Implementation of [ResourceLoader] that accepts relative and package: URIs.
///
@@ -19,13 +19,16 @@
final ResourceLoader _loader;
const PackageLoader(ResourceLoader loader) : _loader = loader;
+ @override
Stream<List<int>> openRead(Uri uri) async* {
yield* _loader.openRead(await resolveUri(uri));
}
+ @override
Future<List<int>> readAsBytes(Uri uri) async =>
_loader.readAsBytes(await resolveUri(uri));
+ @override
Future<String> readAsString(Uri uri, {Encoding encoding}) async =>
_loader.readAsString(await resolveUri(uri), encoding: encoding);
}
diff --git a/lib/src/resolve.dart b/lib/src/resolve.dart
index 4858ccf..50cd642 100644
--- a/lib/src/resolve.dart
+++ b/lib/src/resolve.dart
@@ -2,15 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import "dart:async" show Future;
-import "dart:isolate" show Isolate;
+import 'dart:async' show Future;
+import 'dart:isolate' show Isolate;
/// Helper function for resolving to a non-relative, non-package URI.
Future<Uri> resolveUri(Uri uri) {
- if (uri.scheme == "package") {
+ if (uri.scheme == 'package') {
return Isolate.resolvePackageUri(uri).then((resolvedUri) {
if (resolvedUri == null) {
- throw ArgumentError.value(uri, "uri", "Unknown package");
+ throw ArgumentError.value(uri, 'uri', 'Unknown package');
}
return resolvedUri;
});
diff --git a/lib/src/resource.dart b/lib/src/resource.dart
index 258ff76..edd07a1 100644
--- a/lib/src/resource.dart
+++ b/lib/src/resource.dart
@@ -2,11 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import "dart:async" show Future, Stream;
-import "dart:convert" show Encoding;
+import 'dart:async' show Future, Stream;
+import 'dart:convert' show Encoding;
-import "resolve.dart";
-import "resource_loader.dart";
+import 'resolve.dart';
+import 'resource_loader.dart';
/// Base resource implementation.
class Resource {
diff --git a/lib/src/resource_loader.dart b/lib/src/resource_loader.dart
index 30a39a3..89d8860 100644
--- a/lib/src/resource_loader.dart
+++ b/lib/src/resource_loader.dart
@@ -2,13 +2,13 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import "dart:async" show Future, Stream;
-import "dart:convert" show Encoding;
+import 'dart:async' show Future, Stream;
+import 'dart:convert' show Encoding;
-import "io_none.dart"
+import 'io_none.dart'
if (dart.library.html) "io_html.dart"
if (dart.library.io) "io_io.dart" as io;
-import "package_loader.dart";
+import 'package_loader.dart';
/// Resource loading strategy.
///
@@ -61,10 +61,13 @@
class DefaultLoader implements ResourceLoader {
const DefaultLoader();
+ @override
Stream<List<int>> openRead(Uri uri) => io.readAsStream(uri);
+ @override
Future<List<int>> readAsBytes(Uri uri) => io.readAsBytes(uri);
+ @override
Future<String> readAsString(Uri uri, {Encoding encoding}) =>
io.readAsString(uri, encoding);
}
diff --git a/pubspec.yaml b/pubspec.yaml
index ee6b0b6..378ea2b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,7 +1,6 @@
name: resource
-version: 2.1.6
+version: 2.1.7-dev
description: Reading resource data from (package and other) files.
-author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/resource
environment:
diff --git a/test/browser_http_test.dart b/test/browser_http_test.dart
index fd5ddb0..999ed3b 100644
--- a/test/browser_http_test.dart
+++ b/test/browser_http_test.dart
@@ -2,51 +2,51 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-@TestOn("browser")
+@TestOn('browser')
-import "dart:convert";
+import 'dart:convert';
-import "package:resource/resource.dart";
-import "package:test/test.dart";
+import 'package:resource/resource.dart';
+import 'package:test/test.dart';
-const content = "Rødgrød med fløde";
+const content = 'Rødgrød med fløde';
void main() {
// Assume test files located next to Uri.base.
// This is how "pub run test" currently works.
- test("Default encoding", () async {
+ test('Default encoding', () async {
var loader = ResourceLoader.defaultLoader;
// The HTTPXmlRequest loader defaults to UTF-8 encoding.
- var uri = Uri.base.resolve("testfile-utf8.txt");
+ var uri = Uri.base.resolve('testfile-utf8.txt');
var string = await loader.readAsString(uri);
expect(string, content);
});
- test("Latin-1 encoding", () async {
+ test('Latin-1 encoding', () async {
var loader = ResourceLoader.defaultLoader;
- var uri = Uri.base.resolve("testfile-latin1.txt");
+ var uri = Uri.base.resolve('testfile-latin1.txt');
var string = await loader.readAsString(uri, encoding: latin1);
expect(string, content);
});
- test("UTF-8 encoding", () async {
+ test('UTF-8 encoding', () async {
var loader = ResourceLoader.defaultLoader;
- var uri = Uri.base.resolve("testfile-utf8.txt");
+ var uri = Uri.base.resolve('testfile-utf8.txt');
var string = await loader.readAsString(uri, encoding: utf8);
expect(string, content);
});
- test("bytes", () async {
+ test('bytes', () async {
var loader = ResourceLoader.defaultLoader;
- var uri = Uri.base.resolve("testfile-latin1.txt");
+ var uri = Uri.base.resolve('testfile-latin1.txt');
var bytes = await loader.readAsBytes(uri);
expect(bytes, content.codeUnits);
});
- test("byte stream", () async {
+ test('byte stream', () async {
var loader = ResourceLoader.defaultLoader;
- var uri = Uri.base.resolve("testfile-latin1.txt");
+ var uri = Uri.base.resolve('testfile-latin1.txt');
var bytes = loader.openRead(uri);
var buffer = [];
await bytes.forEach(buffer.addAll);
diff --git a/test/loader_data_test.dart b/test/loader_data_test.dart
index 1e61316..a90b3a3 100644
--- a/test/loader_data_test.dart
+++ b/test/loader_data_test.dart
@@ -2,14 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-@TestOn("vm")
+@TestOn('vm')
-import "dart:convert";
+import 'dart:convert';
-import "package:resource/resource.dart";
-import "package:test/test.dart";
+import 'package:resource/resource.dart';
+import 'package:test/test.dart';
-const content = "Rødgrød med fløde";
+const content = 'Rødgrød med fløde';
void main() {
void testFile(Encoding encoding, bool base64) {
@@ -21,19 +21,19 @@
uri = dataUri.uri;
});
- test("read string", () async {
+ test('read string', () async {
var loader = ResourceLoader.defaultLoader;
var string = await loader.readAsString(uri, encoding: encoding);
expect(string, content);
});
- test("read bytes", () async {
+ test('read bytes', () async {
var loader = ResourceLoader.defaultLoader;
var bytes = await loader.readAsBytes(uri);
expect(bytes, encoding.encode(content));
});
- test("read byte stream", () async {
+ test('read byte stream', () async {
var loader = ResourceLoader.defaultLoader;
var bytes = loader.openRead(uri);
var buffer = [];
diff --git a/test/loader_file_test.dart b/test/loader_file_test.dart
index cd10399..cfd4518 100644
--- a/test/loader_file_test.dart
+++ b/test/loader_file_test.dart
@@ -2,15 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-@TestOn("vm")
+@TestOn('vm')
-import "dart:convert";
-import "dart:io";
+import 'dart:convert';
+import 'dart:io';
-import "package:resource/resource.dart";
-import "package:test/test.dart";
+import 'package:resource/resource.dart';
+import 'package:test/test.dart';
-const content = "Rødgrød med fløde";
+const content = 'Rødgrød med fløde';
void main() {
Directory dir;
@@ -19,30 +19,30 @@
dir = Directory.systemTemp.createTempSync('testdir${dirCounter++}');
});
void testFile(Encoding encoding) {
- group("${encoding.name}", () {
+ group('${encoding.name}', () {
File file;
Uri uri;
setUp(() {
var dirUri = dir.uri;
- uri = dirUri.resolve("file.txt");
+ uri = dirUri.resolve('file.txt');
file = File.fromUri(uri);
// ignore: cascade_invocations
file.writeAsBytesSync(encoding.encode(content));
});
- test("read string", () async {
+ test('read string', () async {
var loader = ResourceLoader.defaultLoader;
var string = await loader.readAsString(uri, encoding: encoding);
expect(string, content);
});
- test("read bytes", () async {
+ test('read bytes', () async {
var loader = ResourceLoader.defaultLoader;
var bytes = await loader.readAsBytes(uri);
expect(bytes, encoding.encode(content));
});
- test("read byte stream", () async {
+ test('read byte stream', () async {
var loader = ResourceLoader.defaultLoader;
var bytes = loader.openRead(uri);
var buffer = [];
diff --git a/test/loader_http_test.dart b/test/loader_http_test.dart
index 9f62230..aa94831 100644
--- a/test/loader_http_test.dart
+++ b/test/loader_http_test.dart
@@ -2,27 +2,27 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-@TestOn("vm")
+@TestOn('vm')
-import "dart:convert";
-import "dart:io";
+import 'dart:convert';
+import 'dart:io';
import 'package:pedantic/pedantic.dart';
-import "package:resource/resource.dart";
-import "package:test/test.dart";
+import 'package:resource/resource.dart';
+import 'package:test/test.dart';
-const content = "Rødgrød med fløde";
+const content = 'Rødgrød med fløde';
void main() {
HttpServer server;
Uri uri;
setUp(() async {
- var addr = (await InternetAddress.lookup("localhost"))[0];
+ var addr = (await InternetAddress.lookup('localhost'))[0];
server = await HttpServer.bind(addr, 0);
var port = server.port;
- uri = Uri.parse("http://localhost:$port/default.html");
+ uri = Uri.parse('http://localhost:$port/default.html');
unawaited(server.forEach((HttpRequest request) {
- if (request.uri.path.endsWith(".not")) {
+ if (request.uri.path.endsWith('.not')) {
request.response
..statusCode = HttpStatus.notFound
..close();
@@ -31,8 +31,8 @@
var encodings = request.headers[HttpHeaders.acceptCharsetHeader];
var encoding = parseAcceptCharset(encodings);
request.response.headers.contentType =
- ContentType("text", "plain", charset: encoding.name);
- if (request.uri.query.contains("length")) {
+ ContentType('text', 'plain', charset: encoding.name);
+ if (request.uri.query.contains('length')) {
request.response.headers.contentLength =
encoding.encode(content).length;
}
@@ -45,56 +45,56 @@
}));
});
- test("Default encoding", () async {
+ test('Default encoding', () async {
var loader = ResourceLoader.defaultLoader;
var string = await loader.readAsString(uri);
expect(string, content);
});
- test("Latin-1 encoding", () async {
+ test('Latin-1 encoding', () async {
var loader = ResourceLoader.defaultLoader;
var string = await loader.readAsString(uri, encoding: latin1);
expect(string, content);
});
- test("Latin-1 encoding w/ length", () async {
+ test('Latin-1 encoding w/ length', () async {
// Regression test for issue #21.
var loader = ResourceLoader.defaultLoader;
// ignore: non_constant_identifier_names
- var Uri = uri.replace(query: "length"); // Request length set.
+ var Uri = uri.replace(query: 'length'); // Request length set.
var string = await loader.readAsString(Uri, encoding: latin1);
expect(string, content);
});
- test("UTF-8 encoding", () async {
+ test('UTF-8 encoding', () async {
var loader = ResourceLoader.defaultLoader;
// ignore: non_constant_identifier_names
- var Uri = uri.replace(query: "length"); // Request length set.
+ var Uri = uri.replace(query: 'length'); // Request length set.
var string = await loader.readAsString(Uri, encoding: utf8);
expect(string, content);
});
- test("UTF-8 encoding w/ length", () async {
+ test('UTF-8 encoding w/ length', () async {
var loader = ResourceLoader.defaultLoader;
var string = await loader.readAsString(uri, encoding: utf8);
expect(string, content);
});
- test("bytes", () async {
+ test('bytes', () async {
var loader = ResourceLoader.defaultLoader;
var bytes = await loader.readAsBytes(uri); // Sender uses Latin-1.
expect(bytes, content.codeUnits);
});
- test("bytes w/ length", () async {
+ test('bytes w/ length', () async {
var loader = ResourceLoader.defaultLoader;
// ignore: non_constant_identifier_names
- var Uri = uri.replace(query: "length"); // Request length set.
+ var Uri = uri.replace(query: 'length'); // Request length set.
var bytes = await loader.readAsBytes(Uri); // Sender uses Latin-1.
expect(bytes, content.codeUnits);
});
- test("byte stream", () async {
+ test('byte stream', () async {
var loader = ResourceLoader.defaultLoader;
var bytes = loader.openRead(uri); // Sender uses Latin-1.
var buffer = [];
@@ -102,21 +102,21 @@
expect(buffer, content.codeUnits);
});
- test("not found - String", () async {
+ test('not found - String', () async {
var loader = ResourceLoader.defaultLoader;
- var badUri = uri.resolve("file.not"); // .not makes server fail.
+ var badUri = uri.resolve('file.not'); // .not makes server fail.
expect(loader.readAsString(badUri), throwsException);
});
- test("not found - bytes", () async {
+ test('not found - bytes', () async {
var loader = ResourceLoader.defaultLoader;
- var badUri = uri.resolve("file.not"); // .not makes server fail.
+ var badUri = uri.resolve('file.not'); // .not makes server fail.
expect(loader.readAsBytes(badUri), throwsException);
});
- test("not found - byte stream", () async {
+ test('not found - byte stream', () async {
var loader = ResourceLoader.defaultLoader;
- var badUri = uri.resolve("file.not"); // .not makes server fail.
+ var badUri = uri.resolve('file.not'); // .not makes server fail.
expect(loader.openRead(badUri).length, throwsException);
});
@@ -130,7 +130,7 @@
Encoding encoding = latin1;
if (headers != null) {
var weight = 0.0;
- var pattern = RegExp(r"([\w-]+)(;\s*q=[\d.]+)?");
+ var pattern = RegExp(r'([\w-]+)(;\s*q=[\d.]+)?');
for (var acceptCharset in headers) {
for (var match in pattern.allMatches(acceptCharset)) {
var e = Encoding.getByName(match[1]);
diff --git a/test/resource_test.dart b/test/resource_test.dart
index e06b4df..95d7d8d 100644
--- a/test/resource_test.dart
+++ b/test/resource_test.dart
@@ -2,25 +2,25 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-@TestOn("vm")
+@TestOn('vm')
-import "dart:async" show Future, Stream;
-import "dart:convert" show Encoding, ascii;
-import "dart:isolate" show Isolate;
-import "package:resource/resource.dart";
-import "package:test/test.dart";
+import 'dart:async' show Future, Stream;
+import 'dart:convert' show Encoding, ascii;
+import 'dart:isolate' show Isolate;
+import 'package:resource/resource.dart';
+import 'package:test/test.dart';
void main() {
- Uri pkguri(path) => Uri(scheme: "package", path: path);
+ Uri pkguri(path) => Uri(scheme: 'package', path: path);
Future<Uri> resolve(Uri source) async {
- if (source.scheme == "package") {
+ if (source.scheme == 'package') {
return Isolate.resolvePackageUri(source);
}
return Uri.base.resolveUri(source);
}
- group("loading", () {
+ group('loading', () {
Future testLoad(Uri uri) async {
var loader = LogLoader();
var resource = Resource(uri, loader: loader);
@@ -32,25 +32,25 @@
var res1 = await resource.readAsBytes();
expect(res1, [0, 0, 0]);
var res2 = await resource.readAsString(encoding: ascii);
- expect(res2, "\x00\x00\x00");
+ expect(res2, '\x00\x00\x00');
expect(loader.requests, [
- ["Stream", resolved],
- ["Bytes", resolved],
- ["String", resolved, ascii]
+ ['Stream', resolved],
+ ['Bytes', resolved],
+ ['String', resolved, ascii]
]);
}
- test("load package: URIs", () async {
- await testLoad(pkguri("resource/bar/baz"));
- await testLoad(pkguri("test/foo/baz"));
+ test('load package: URIs', () async {
+ await testLoad(pkguri('resource/bar/baz'));
+ await testLoad(pkguri('test/foo/baz'));
});
- test("load non-pkgUri", () async {
- await testLoad(Uri.parse("file://localhost/something?x#y"));
- await testLoad(Uri.parse("http://auth/something?x#y"));
- await testLoad(Uri.parse("https://auth/something?x#y"));
- await testLoad(Uri.parse("data:,something?x"));
- await testLoad(Uri.parse("unknown:/something"));
+ test('load non-pkgUri', () async {
+ await testLoad(Uri.parse('file://localhost/something?x#y'));
+ await testLoad(Uri.parse('http://auth/something?x#y'));
+ await testLoad(Uri.parse('https://auth/something?x#y'));
+ await testLoad(Uri.parse('data:,something?x'));
+ await testLoad(Uri.parse('unknown:/something'));
});
});
}
@@ -61,18 +61,21 @@
requests.clear();
}
+ @override
Stream<List<int>> openRead(Uri uri) async* {
- requests.add(["Stream", uri]);
+ requests.add(['Stream', uri]);
yield [0x00, 0x00, 0x00];
}
+ @override
Future<List<int>> readAsBytes(Uri uri) async {
- requests.add(["Bytes", uri]);
+ requests.add(['Bytes', uri]);
return [0x00, 0x00, 0x00];
}
+ @override
Future<String> readAsString(Uri uri, {Encoding encoding}) async {
- requests.add(["String", uri, encoding]);
- return "\x00\x00\x00";
+ requests.add(['String', uri, encoding]);
+ return '\x00\x00\x00';
}
}