| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Testing FileInputStream, VM-only, standalone test. | 4 // Testing FileInputStream, VM-only, standalone test. |
| 5 | 5 |
| 6 | |
| 7 String callbackString = null; | |
| 8 | |
| 9 callback(List<int> buffer) { | |
| 10 callbackString = new String.fromCharCodes(buffer); | |
| 11 } | |
| 12 | |
| 13 // Helper method to be able to run the test from the runtime | 6 // Helper method to be able to run the test from the runtime |
| 14 // directory, or the top directory. | 7 // directory, or the top directory. |
| 15 String getFilename(String path) => | 8 String getFilename(String path) => |
| 16 FileUtil.fileExists(path) ? path : '../' + path; | 9 FileUtil.fileExists(path) ? path : '../' + path; |
| 17 | 10 |
| 18 main() { | 11 main() { |
| 19 String fName = getFilename("tests/standalone/src/readuntil_test.dat"); | 12 String fName = getFilename("tests/standalone/src/readuntil_test.dat"); |
| 20 // File contains "Hello Dart, wassup!" | 13 // File contains "Hello Dart\nwassup!" |
| 21 File file = new File(fName, false); | 14 File file = new File(fName, false); |
| 22 FileInputStream x = new FileInputStream(file); | 15 StringInputStream x = new StringInputStream(file.inputStream); |
| 23 x.readUntil("Dart".charCodes(), callback); | 16 String line = x.readLine(); |
| 17 Expect.equals("Hello Dart", line); |
| 24 file.close(); | 18 file.close(); |
| 25 Expect.stringEquals("Hello Dart", callbackString); | 19 line = x.readLine(); |
| 26 | 20 Expect.equals("wassup!", line); |
| 27 callbackString = null; | |
| 28 file = new File(fName, false); | |
| 29 x = new FileInputStream(file); | |
| 30 x.readUntil("Darty".charCodes(), callback); | |
| 31 file.close(); | |
| 32 Expect.isNull(callbackString); | |
| 33 | |
| 34 file = new File(fName, false); | |
| 35 x = new FileInputStream(file); | |
| 36 x.readUntil("wassup!".charCodes(), callback); | |
| 37 file.close(); | |
| 38 Expect.stringEquals("Hello Dart, wassup!", callbackString); | |
| 39 } | 21 } |
| OLD | NEW |