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

Unified Diff: tests/stub-generator/test_config.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: Updated the Dart test runner to work with the file input stream changes 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
Index: tests/stub-generator/test_config.dart
diff --git a/tests/stub-generator/test_config.dart b/tests/stub-generator/test_config.dart
index 055b9cfce57c616f59ae63f281fa04db11dabea4..af2917f7d64693bd356e6f3c5b852ae129bbc93d 100644
--- a/tests/stub-generator/test_config.dart
+++ b/tests/stub-generator/test_config.dart
@@ -32,43 +32,66 @@ class StubGeneratorTestSuite extends StandardTestSuite {
File result = new File(resultPath);
StringInputStream origStream =
new StringInputStream(orig.openInputStream());
+ StringInputStream stubsStream =
+ new StringInputStream(stubs.openInputStream());
FileOutputStream resultStream = result.openOutputStream();
+ var origLine;
- // First copy first comments and imports from original file.
- var origLine = origStream.readLine();
- while (origLine != null) {
- origLine = origLine.trim();
- if (origLine.isEmpty() ||
- origLine.startsWith('//') ||
- origLine.startsWith('#')) {
- resultStream.write(origLine.charCodes());
- resultStream.write('\n'.charCodes());
+ void writeResultLine(String line) {
+ resultStream.write(line.charCodes());
+ resultStream.write('\n'.charCodes());
+ }
+
+ // Step 3: Copy in the rest of the original file.
+ void copyThirdPart() {
+ origLine = origStream.readLine();
+ while (origLine != null) {
+ writeResultLine(origLine);
origLine = origStream.readLine();
- } else {
- break;
}
}
- // Then copy in the generated stubs code.
- StringInputStream stubsStream =
- new StringInputStream(stubs.openInputStream());
- var stubsLine = stubsStream.readLine();
- while (stubsLine != null) {
- resultStream.write(stubsLine.charCodes());
- resultStream.write('\n'.charCodes());
- stubsLine = stubsStream.readLine();
+ // Step 2: Copy in the generated stubs code.
+ void copySecondPart() {
+ var stubsLine = stubsStream.readLine();
+ while (stubsLine != null) {
+ writeResultLine(stubsLine);
+ stubsLine = stubsStream.readLine();
+ }
}
- // Then copy in the rest of the original file.
- while (origLine != null) {
- resultStream.write(origLine.charCodes());
- resultStream.write('\n'.charCodes());
+ // Step 1: Copy first comments and imports from original file.
+ void copyFirstPart() {
origLine = origStream.readLine();
+ while (origLine != null) {
+ origLine = origLine.trim();
+ if (origLine.isEmpty() ||
+ origLine.startsWith('//') ||
+ origLine.startsWith('#')) {
+ writeResultLine(origLine);
+ origLine = origStream.readLine();
+ } else {
+ origStream.lineHandler = null;
+ // Start copying from the stubs file.
+ stubsStream.lineHandler = copySecondPart;
+ stubsStream.closeHandler = () {
+ // When the stubs file is all read continue with the rest
+ // of the original file including the pending line.
+ writeResultLine(origLine);
+ origStream.lineHandler = copyThirdPart;
+ };
+ return;
+ }
+ }
}
- // Done.
- resultStream.close();
- onGenerated(resultPath);
+ origStream.lineHandler = copyFirstPart;
+ origStream.closeHandler = () {
+ // Done generating file when all data has been read from the
+ // original file.
+ resultStream.close();
+ onGenerated(resultPath);
+ };
}
void generateTestCase(String filename,

Powered by Google App Engine
This is Rietveld 408576698