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

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: 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 | « tests/standalone/src/readline_test2.dat ('k') | tools/testing/dart/status_file_parser.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/stub-generator/test_config.dart
diff --git a/tests/stub-generator/test_config.dart b/tests/stub-generator/test_config.dart
index c14884e42f14049c8f6ef123a1f9879f5cbfb4cb..f48a42a08f3aa436ddb8b1a9dc87ce44aefbc478 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,
« no previous file with comments | « tests/standalone/src/readline_test2.dat ('k') | tools/testing/dart/status_file_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698