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

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

Issue 8885032: Improve the event handling for string input stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebased Created 9 years 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 | « runtime/bin/string_stream.dart ('k') | tests/standalone/src/StatusFileParserTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/src/FileInputStreamTest.dart
diff --git a/tests/standalone/src/FileInputStreamTest.dart b/tests/standalone/src/FileInputStreamTest.dart
index 354c0b53a081a8bed2f0a1b3a4b118fece6101af..b5957425a9c3ac021c6c2e5045cfce4e2595b942 100644
--- a/tests/standalone/src/FileInputStreamTest.dart
+++ b/tests/standalone/src/FileInputStreamTest.dart
@@ -13,10 +13,14 @@ void testStringInputStreamSync() {
// File contains "Hello Dart\nwassup!\n"
File file = new File(fileName);
StringInputStream x = new StringInputStream(file.openInputStream());
- String line = x.readLine();
- Expect.equals("Hello Dart", line);
- line = x.readLine();
- Expect.equals("wassup!", line);
+ x.lineHandler = () {
+ // The file input stream is known (for now) to have read the whole
+ // file when the data handler is called.
+ String line = x.readLine();
+ Expect.equals("Hello Dart", line);
+ line = x.readLine();
+ Expect.equals("wassup!", line);
+ };
}
void testInputStreamAsync() {
@@ -35,36 +39,23 @@ void testInputStreamAsync() {
}
-void testStringInputStreamAsync1() {
- String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
- // File contains "Hello Dart\nwassup!\n"
- File file = new File(fileName);
- StringInputStream x = new StringInputStream(file.openInputStream());
- var result = "";
- x.dataHandler = () {
- result += x.read();
- };
- x.closeHandler = () {
- Expect.equals("Hello Dart\nwassup!\n", result);
- };
-}
-
-
-void testStringInputStreamAsync2() {
- String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
- // File contains "Hello Dart\nwassup!\n"
+void testStringInputStreamAsync(String name, int length) {
+ String fileName = getFilename("tests/standalone/src/$name");
+ // File contains 10 lines.
File file = new File(fileName);
+ Expect.equals(length, file.openSync().lengthSync());
StringInputStream x = new StringInputStream(file.openInputStream());
int lineCount = 0;
x.lineHandler = () {
var line = x.readLine();
- Expect.isTrue(lineCount == 0 || lineCount == 1);
- if (lineCount == 0) Expect.equals("Hello Dart", line);
- if (lineCount == 1) Expect.equals("wassup!", line);
lineCount++;
+ Expect.isTrue(lineCount <= 10);
+ if (line[0] != "#") {
+ Expect.equals("Line $lineCount", line);
+ }
};
x.closeHandler = () {
- Expect.equals(2, lineCount);
+ Expect.equals(10, lineCount);
};
}
@@ -90,7 +81,10 @@ void testChunkedInputStream() {
main() {
testStringInputStreamSync();
testInputStreamAsync();
- testStringInputStreamAsync1();
- testStringInputStreamAsync2();
+ // Check the length of these files as both are text files where one
+ // is without a terminating line separator which can easily be added
+ // back if accidentally opened in a text editor.
+ testStringInputStreamAsync("readline_test1.dat", 111);
+ testStringInputStreamAsync("readline_test2.dat", 114);
testChunkedInputStream();
}
« no previous file with comments | « runtime/bin/string_stream.dart ('k') | tests/standalone/src/StatusFileParserTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698