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

Unified Diff: tests/standalone/io/file_test.dart

Issue 22872012: Remove Encoding-enum from dart:io and add interface in dart:convert. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo. Created 7 years, 4 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 | « tests/standalone/io/file_input_stream_test.dart ('k') | tests/standalone/io/process_run_output_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/file_test.dart
diff --git a/tests/standalone/io/file_test.dart b/tests/standalone/io/file_test.dart
index 6a16efcfff93b78ca48d132e886b9ffe3a536d6d..be1bd41ea946ebc9290d64530b9a57c83ec85eeb 100644
--- a/tests/standalone/io/file_test.dart
+++ b/tests/standalone/io/file_test.dart
@@ -7,6 +7,7 @@
import "package:expect/expect.dart";
import "package:path/path.dart";
import 'dart:async';
+import 'dart:convert';
import 'dart:collection';
import 'dart:io';
import 'dart:isolate';
@@ -393,13 +394,13 @@ class FileTest {
List<int> buffer = content.codeUnits;
var output = file.openWrite();
output.write("abcdABCD");
- output.encoding = UTF_8;
+ output.encoding = UTF8;
output.write("abcdABCD");
- output.encoding = ISO_8859_1;
+ output.encoding = LATIN1;
output.write("abcdABCD");
output.encoding = ASCII;
output.write("abcdABCD");
- output.encoding = UTF_8;
+ output.encoding = UTF8;
output.write("æøå");
output.close();
output.done.then((_) {
@@ -985,16 +986,16 @@ class FileTest {
});
var name = getFilename("tests/vm/data/fixed_length_file");
var f = new File(name);
- f.readAsString(encoding: UTF_8).then((text) {
+ f.readAsString(encoding: UTF8).then((text) {
Expect.isTrue(text.endsWith("42 bytes."));
Expect.equals(42, text.length);
var name = getDataFilename("tests/standalone/io/read_as_text.dat");
var f = new File(name);
- f.readAsString(encoding: UTF_8).then((text) {
+ f.readAsString(encoding: UTF8).then((text) {
Expect.equals(6, text.length);
var expected = [955, 120, 46, 32, 120, 10];
Expect.listEquals(expected, text.codeUnits);
- f.readAsString(encoding: ISO_8859_1).then((text) {
+ f.readAsString(encoding: LATIN1).then((text) {
Expect.equals(7, text.length);
var expected = [206, 187, 120, 46, 32, 120, 10];
Expect.listEquals(expected, text.codeUnits);
@@ -1017,7 +1018,7 @@ class FileTest {
});
var name = getFilename("tests/vm/data/empty_file");
var f = new File(name);
- f.readAsString(encoding: UTF_8).then((text) {
+ f.readAsString(encoding: UTF8).then((text) {
port.toSendPort().send(text.length);
return true;
});
@@ -1033,11 +1034,18 @@ class FileTest {
Expect.equals(6, text.length);
var expected = [955, 120, 46, 32, 120, 10];
Expect.listEquals(expected, text.codeUnits);
- text = new File(name).readAsStringSync(encoding: ASCII);
- // Default replacement character is '?', char code 63.
- expected = [63, 63, 120, 46, 32, 120, 10];
+ // First character is not ASCII. The default ASCII decoder will throw.
+ Expect.throws(() => new File(name).readAsStringSync(encoding: ASCII),
+ (e) => e is FormatError);
+ // We can use an ASCII decoder that inserts the replacement character.
+ var lenientAscii = const AsciiCodec(allowInvalid: true);
+ text = new File(name).readAsStringSync(encoding: lenientAscii);
+ // Default replacement character is the Unicode replacement character.
+ expected = [UNICODE_REPLACEMENT_CHARACTER_RUNE,
+ UNICODE_REPLACEMENT_CHARACTER_RUNE,
+ 120, 46, 32, 120, 10];
Expect.listEquals(expected, text.codeUnits);
- text = new File(name).readAsStringSync(encoding: ISO_8859_1);
+ text = new File(name).readAsStringSync(encoding: LATIN1);
expected = [206, 187, 120, 46, 32, 120, 10];
Expect.equals(7, text.length);
Expect.listEquals(expected, text.codeUnits);
@@ -1057,7 +1065,7 @@ class FileTest {
});
var name = getFilename("tests/vm/data/fixed_length_file");
var f = new File(name);
- f.readAsLines(encoding: UTF_8).then((lines) {
+ f.readAsLines(encoding: UTF8).then((lines) {
Expect.equals(1, lines.length);
var line = lines[0];
Expect.isTrue(line.endsWith("42 bytes."));
@@ -1091,10 +1099,10 @@ class FileTest {
var readAsBytesFuture = f.readAsBytes();
readAsBytesFuture.then((bytes) => Expect.fail("no bytes expected"))
.catchError((e) {
- var readAsStringFuture = f.readAsString(encoding: UTF_8);
+ var readAsStringFuture = f.readAsString(encoding: UTF8);
readAsStringFuture.then((text) => Expect.fail("no text expected"))
.catchError((e) {
- var readAsLinesFuture = f.readAsLines(encoding: UTF_8);
+ var readAsLinesFuture = f.readAsLines(encoding: UTF8);
readAsLinesFuture.then((lines) => Expect.fail("no lines expected"))
.catchError((e) {
port.toSendPort().send(1);
« no previous file with comments | « tests/standalone/io/file_input_stream_test.dart ('k') | tests/standalone/io/process_run_output_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698