| Index: tests/standalone/src/FileInputStreamTest.dart
|
| diff --git a/tests/standalone/src/FileInputStreamTest.dart b/tests/standalone/src/FileInputStreamTest.dart
|
| index a61ac68987c8100e018226d380ab2d394e9e53f6..d74e7dc1ea3164c7549c3efaf9c0cbafc8df2a9b 100644
|
| --- a/tests/standalone/src/FileInputStreamTest.dart
|
| +++ b/tests/standalone/src/FileInputStreamTest.dart
|
| @@ -8,10 +8,10 @@
|
| String getFilename(String path) =>
|
| new File(path).existsSync() ? path : '../' + path;
|
|
|
| -main() {
|
| - String fName = getFilename("tests/standalone/src/readuntil_test.dat");
|
| - // File contains "Hello Dart\nwassup!"
|
| - File file = new File(fName);
|
| +void testStringInputStreamSync() {
|
| + String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
|
| + // File contains "Hello Dart\nwassup!\n"
|
| + File file = new File(fileName);
|
| file.openSync();
|
| StringInputStream x = new StringInputStream(file.openInputStream());
|
| String line = x.readLine();
|
| @@ -20,3 +20,65 @@ main() {
|
| line = x.readLine();
|
| Expect.equals("wassup!", line);
|
| }
|
| +
|
| +
|
| +void testInputStreamAsync() {
|
| + String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
|
| + // File contains "Hello Dart\nwassup!\n"
|
| + var expected = "Hello Dart\nwassup!\n".charCodes();
|
| + File file = new File(fileName);
|
| + file.openSync();
|
| + InputStream x = file.openInputStream();
|
| + var byteCount = 0;
|
| + x.dataHandler = () {
|
| + Expect.equals(expected[byteCount], x.read(1)[0]);
|
| + byteCount++;
|
| + };
|
| + x.closeHandler = () {
|
| + Expect.equals(expected.length, byteCount);
|
| + };
|
| +}
|
| +
|
| +
|
| +void testStringInputStreamAsync1() {
|
| + String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
|
| + // File contains "Hello Dart\nwassup!\n"
|
| + File file = new File(fileName);
|
| + file.openSync();
|
| + 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"
|
| + File file = new File(fileName);
|
| + file.openSync();
|
| + 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++;
|
| + };
|
| + x.closeHandler = () {
|
| + Expect.equals(2, lineCount);
|
| + };
|
| +}
|
| +
|
| +
|
| +main() {
|
| + testStringInputStreamSync();
|
| + testInputStreamAsync();
|
| + testStringInputStreamAsync1();
|
| + testStringInputStreamAsync2();
|
| +}
|
|
|