Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: test/loader_file_test.dart

Issue 1387163002: Add Resource package. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Address comments. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/loader_data_test.dart ('k') | test/loader_http_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/loader_file_test.dart
diff --git a/test/loader_file_test.dart b/test/loader_file_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..aa4c23882abf05e6b4930d4b83adff18383163e6
--- /dev/null
+++ b/test/loader_file_test.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// 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";
+import "dart:convert";
+import "dart:io";
+
+import "package:resource/resource.dart";
+import "package:test/test.dart";
+
+const content = "Rødgrød med fløde";
+
+
+main() {
+ var dir;
+ setUp(() {
+ dir = Directory.systemTemp.createTempSync('testdir');
+ });
+ testFile(Encoding encoding) {
+ group("${encoding.name}", () {
+ var file;
+ var uri;
+ setUp(() {
+ var dirUri = dir.uri;
+ uri = dirUri.resolve("file.txt");
+ file = new File.fromUri(uri);
+ file.createSync();
+ var sink = file.openWrite(encoding: encoding);
+ sink.write(content);
+ sink.close();
+ });
+
+ test("read string", () async {
+ var loader = ResourceLoader.defaultLoader;
+ String string = await loader.readAsString(uri, encoding: encoding);
+ expect(string, content);
+ });
+
+ test("read bytes", () async {
+ var loader = ResourceLoader.defaultLoader;
+ List<int> bytes = await loader.readAsBytes(uri);
+ expect(bytes, encoding.encode(content));
+ });
+
+ test("read byte stream", () async {
+ var loader = ResourceLoader.defaultLoader;
+ Stream<int> bytes = loader.openRead(uri);
+ var buffer = [];
+ await bytes.forEach(buffer.addAll);
+ expect(buffer, encoding.encode(content));
+ });
+
+ tearDown(() {
+ file.deleteSync();
+ });
+ });
+ }
+ testFile(LATIN1);
+ testFile(UTF8);
+
+ tearDown(() {
+ dir.delete(recursive: true);
+ });
+}
« no previous file with comments | « test/loader_data_test.dart ('k') | test/loader_http_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698