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

Unified Diff: tests/standalone/src/FileTest.dart

Issue 9452014: Implement File.{readAsBytes, readAsText, readAsLines}. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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
« runtime/bin/file_impl.dart ('K') | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/src/FileTest.dart
diff --git a/tests/standalone/src/FileTest.dart b/tests/standalone/src/FileTest.dart
index a32f69d5e91558e58326ac3a3e8bbdfc1b600838..1d6ff22977ffb17d46f38b5cd56d89caa7a32403 100644
--- a/tests/standalone/src/FileTest.dart
+++ b/tests/standalone/src/FileTest.dart
@@ -880,6 +880,90 @@ class FileTest {
}
}
+ static void testReadAsBytes() {
+ var port = new ReceivePort.singleShot();
+ port.receive((result, replyTo) {
+ Expect.equals(42, result);
+ });
+ var name = getFilename("tests/vm/data/fixed_length_file");
+ var f = new File(name);
+ f.readAsBytes();
+ f.readAsBytesHandler = (bytes) {
+ Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes."));
+ port.toSendPort().send(bytes.length);
+ };
+ f.errorHandler = (e) {
+ Expect.fail("No errors expected: $e");
+ };
+ }
+
+ static void testReadAsBytesSync() {
+ var name = getFilename("tests/vm/data/fixed_length_file");
+ var bytes = new File(name).readAsBytesSync();
+ Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes."));
+ Expect.equals(bytes.length, 42);
+ }
+
+ static void testReadAsText() {
Søren Gjesse 2012/02/24 07:24:51 I know that the decoders are tested elsewhere, but
Mads Ager (google) 2012/02/24 13:11:17 Done.
+ var port = new ReceivePort.singleShot();
+ port.receive((result, replyTo) {
+ Expect.equals(42, result);
+ });
+ var name = getFilename("tests/vm/data/fixed_length_file");
+ var f = new File(name);
+ f.readAsText('UTF-8');
+ f.readAsTextHandler = (text) {
+ Expect.isTrue(text.endsWith("42 bytes."));
+ port.toSendPort().send(text.length);
+ };
+ f.errorHandler = (e) {
+ Expect.fail("No errors expected: $e");
+ };
+ }
+
+ static void testReadAsTextSync() {
+ var name = getFilename("tests/vm/data/fixed_length_file");
+ var text = new File(name).readAsTextSync();
+ Expect.isTrue(text.endsWith("42 bytes."));
+ Expect.equals(42, text.length);
+ }
+
+ static void testReadAsLines() {
Søren Gjesse 2012/02/24 07:24:51 Again I know that the line-splitting is tested els
Mads Ager (google) 2012/02/24 13:11:17 Done.
+ var port = new ReceivePort.singleShot();
+ port.receive((result, replyTo) {
+ Expect.equals(42, result);
+ });
+ var name = getFilename("tests/vm/data/fixed_length_file");
+ var f = new File(name);
+ f.readAsLines('UTF-8');
+ f.readAsLinesHandler = (lines) {
+ Expect.equals(1, lines.length);
+ var line = lines[0];
+ Expect.isTrue(line.endsWith("42 bytes."));
+ port.toSendPort().send(line.length);
+ };
+ f.errorHandler = (e) {
+ Expect.fail("No errors expected: $e");
+ };
+ }
+
+ static void testReadAsLinesSync() {
+ var name = getFilename("tests/vm/data/fixed_length_file");
+ var lines = new File(name).readAsLinesSync();
+ Expect.equals(1, lines.length);
+ var line = lines[0];
+ Expect.isTrue(line.endsWith("42 bytes."));
+ Expect.equals(42, line.length);
+ }
+
+ static void testReadAsErrors() {
+ var f = new File('.');
+ Expect.throws(f.readAsBytesSync, (e) => e is FileIOException);
+ Expect.throws(f.readAsTextSync, (e) => e is FileIOException);
+ Expect.throws(f.readAsLinesSync, (e) => e is FileIOException);
+ // TODO(ager): Add tests of errors in readAsBytes when input
+ // streams are truely async.
+ }
// Test that opens the same file for writing then for appending to test
// that the file is not truncated when opened for appending.
@@ -957,6 +1041,13 @@ class FileTest {
testMixedSyncAndAsync();
testOpenDirectoryAsFile();
testOpenDirectoryAsFileSync();
+ testReadAsBytes();
+ testReadAsBytesSync();
+ testReadAsText();
+ testReadAsTextSync();
+ testReadAsLines();
+ testReadAsLinesSync();
+ testReadAsErrors();
createTempDirectory(() {
testReadWrite();
« runtime/bin/file_impl.dart ('K') | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698