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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4
5 #library("stub_generator_test_config"); 5 #library("stub_generator_test_config");
6 6
7 #import("../../tools/testing/dart/test_suite.dart"); 7 #import("../../tools/testing/dart/test_suite.dart");
8 8
9 class StubGeneratorTestSuite extends StandardTestSuite { 9 class StubGeneratorTestSuite extends StandardTestSuite {
10 String dartcPath; 10 String dartcPath;
(...skipping 14 matching lines...) Expand all
25 String stubsFile, 25 String stubsFile,
26 Function onGenerated) { 26 Function onGenerated) {
27 File orig = new File(filename); 27 File orig = new File(filename);
28 File stubs = new File(stubsFile); 28 File stubs = new File(stubsFile);
29 Expect.isTrue(filename.endsWith(".dart")); 29 Expect.isTrue(filename.endsWith(".dart"));
30 String baseName = filename.substring(0, filename.length - 5); 30 String baseName = filename.substring(0, filename.length - 5);
31 String resultPath = '${baseName}-generatedTest.dart'; 31 String resultPath = '${baseName}-generatedTest.dart';
32 File result = new File(resultPath); 32 File result = new File(resultPath);
33 StringInputStream origStream = 33 StringInputStream origStream =
34 new StringInputStream(orig.openInputStream()); 34 new StringInputStream(orig.openInputStream());
35 StringInputStream stubsStream =
36 new StringInputStream(stubs.openInputStream());
35 FileOutputStream resultStream = result.openOutputStream(); 37 FileOutputStream resultStream = result.openOutputStream();
38 var origLine;
36 39
37 // First copy first comments and imports from original file. 40 void writeResultLine(String line) {
38 var origLine = origStream.readLine(); 41 resultStream.write(line.charCodes());
39 while (origLine != null) { 42 resultStream.write('\n'.charCodes());
40 origLine = origLine.trim(); 43 }
41 if (origLine.isEmpty() || 44
42 origLine.startsWith('//') || 45 // Step 3: Copy in the rest of the original file.
43 origLine.startsWith('#')) { 46 void copyThirdPart() {
44 resultStream.write(origLine.charCodes()); 47 origLine = origStream.readLine();
45 resultStream.write('\n'.charCodes()); 48 while (origLine != null) {
49 writeResultLine(origLine);
46 origLine = origStream.readLine(); 50 origLine = origStream.readLine();
47 } else {
48 break;
49 } 51 }
50 } 52 }
51 53
52 // Then copy in the generated stubs code. 54 // Step 2: Copy in the generated stubs code.
53 StringInputStream stubsStream = 55 void copySecondPart() {
54 new StringInputStream(stubs.openInputStream()); 56 var stubsLine = stubsStream.readLine();
55 var stubsLine = stubsStream.readLine(); 57 while (stubsLine != null) {
56 while (stubsLine != null) { 58 writeResultLine(stubsLine);
57 resultStream.write(stubsLine.charCodes()); 59 stubsLine = stubsStream.readLine();
58 resultStream.write('\n'.charCodes()); 60 }
59 stubsLine = stubsStream.readLine();
60 } 61 }
61 62
62 // Then copy in the rest of the original file. 63 // Step 1: Copy first comments and imports from original file.
63 while (origLine != null) { 64 void copyFirstPart() {
64 resultStream.write(origLine.charCodes());
65 resultStream.write('\n'.charCodes());
66 origLine = origStream.readLine(); 65 origLine = origStream.readLine();
66 while (origLine != null) {
67 origLine = origLine.trim();
68 if (origLine.isEmpty() ||
69 origLine.startsWith('//') ||
70 origLine.startsWith('#')) {
71 writeResultLine(origLine);
72 origLine = origStream.readLine();
73 } else {
74 origStream.lineHandler = null;
75 // Start copying from the stubs file.
76 stubsStream.lineHandler = copySecondPart;
77 stubsStream.closeHandler = () {
78 // When the stubs file is all read continue with the rest
79 // of the original file including the pending line.
80 writeResultLine(origLine);
81 origStream.lineHandler = copyThirdPart;
82 };
83 return;
84 }
85 }
67 } 86 }
68 87
69 // Done. 88 origStream.lineHandler = copyFirstPart;
70 resultStream.close(); 89 origStream.closeHandler = () {
71 onGenerated(resultPath); 90 // Done generating file when all data has been read from the
91 // original file.
92 resultStream.close();
93 onGenerated(resultPath);
94 };
72 } 95 }
73 96
74 void generateTestCase(String filename, 97 void generateTestCase(String filename,
75 String interfaceFile, 98 String interfaceFile,
76 String classes, 99 String classes,
77 Function onGenerated) { 100 Function onGenerated) {
78 testGeneratorStarted(); 101 testGeneratorStarted();
79 Directory temp = new Directory(''); 102 Directory temp = new Directory('');
80 temp.createTempSync(); 103 temp.createTempSync();
81 File stubsOutFile = new File("${temp.path}/${interfaceFile}"); 104 File stubsOutFile = new File("${temp.path}/${interfaceFile}");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 String interfaceFile = splitIsolateStubsOptions[0]; 138 String interfaceFile = splitIsolateStubsOptions[0];
116 String classes = splitIsolateStubsOptions[1]; 139 String classes = splitIsolateStubsOptions[1];
117 generateTestCase(filename, interfaceFile, classes, (String filename) { 140 generateTestCase(filename, interfaceFile, classes, (String filename) {
118 createTestCase(filename, optionsFromFile['isNegative']); 141 createTestCase(filename, optionsFromFile['isNegative']);
119 testGeneratorDone(); 142 testGeneratorDone();
120 }); 143 });
121 } 144 }
122 } 145 }
123 } 146 }
124 } 147 }
OLDNEW
« 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