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

Side by Side Diff: tests/standalone/src/io/StringStreamTest.dart

Issue 9546003: Add method available to StringInputStream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #import("dart:io"); 5 #import("dart:io");
6 6
7 void testUtf8() { 7 void testUtf8() {
8 List<int> data = [0x01, 8 List<int> data = [0x01,
9 0x7f, 9 0x7f,
10 0xc2, 0x80, 10 0xc2, 0x80,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 void testReadLine2() { 102 void testReadLine2() {
103 InputStream s = new ListInputStream(); 103 InputStream s = new ListInputStream();
104 StringInputStream stream = new StringInputStream(s); 104 StringInputStream stream = new StringInputStream(s);
105 var stage = 0; 105 var stage = 0;
106 106
107 void stringData() { 107 void stringData() {
108 var line; 108 var line;
109 if (stage == 0) { 109 if (stage == 0) {
110 Expect.equals(21, stream.available());
110 line = stream.readLine(); 111 line = stream.readLine();
111 Expect.equals("Line1", line); 112 Expect.equals("Line1", line);
113 Expect.equals(15, stream.available());
112 line = stream.readLine(); 114 line = stream.readLine();
113 Expect.equals("Line2", line); 115 Expect.equals("Line2", line);
116 Expect.equals(8, stream.available());
114 line = stream.readLine(); 117 line = stream.readLine();
115 Expect.equals("Line3", line); 118 Expect.equals("Line3", line);
116 line = stream.readLine(); 119 line = stream.readLine();
120 Expect.equals(2, stream.available());
117 Expect.equals(null, line); 121 Expect.equals(null, line);
118 stage++; 122 stage++;
119 s.write("ne4\n".charCodes()); 123 s.write("ne4\n".charCodes());
120 } else if (stage == 1) { 124 } else if (stage == 1) {
125 Expect.equals(6, stream.available());
121 line = stream.readLine(); 126 line = stream.readLine();
122 Expect.equals("Line4", line); 127 Expect.equals("Line4", line);
128 Expect.equals(0, stream.available());
123 line = stream.readLine(); 129 line = stream.readLine();
124 Expect.equals(null, line); 130 Expect.equals(null, line);
125 stage++; 131 stage++;
126 s.write("\n\n\r\n\r\n\r\r".charCodes()); 132 s.write("\n\n\r\n\r\n\r\r".charCodes());
127 } else if (stage == 2) { 133 } else if (stage == 2) {
128 // Expect 5 empty lines. As long as the stream is not closed the 134 // Expect 5 empty lines. As long as the stream is not closed the
129 // final \r cannot be interpreted as a end of line. 135 // final \r cannot be interpreted as a end of line.
136 Expect.equals(8, stream.available());
130 for (int i = 0; i < 5; i++) { 137 for (int i = 0; i < 5; i++) {
131 line = stream.readLine(); 138 line = stream.readLine();
132 Expect.equals("", line); 139 Expect.equals("", line);
133 } 140 }
141 Expect.equals(1, stream.available());
134 line = stream.readLine(); 142 line = stream.readLine();
135 Expect.equals(null, line); 143 Expect.equals(null, line);
136 stage++; 144 stage++;
137 s.markEndOfStream(); 145 s.markEndOfStream();
138 } else if (stage == 3) { 146 } else if (stage == 3) {
139 // The final \r can now be interpreted as an end of line. 147 // The final \r can now be interpreted as an end of line.
148 Expect.equals(1, stream.available());
140 line = stream.readLine(); 149 line = stream.readLine();
141 Expect.equals("", line); 150 Expect.equals("", line);
142 line = stream.readLine(); 151 line = stream.readLine();
143 Expect.equals(null, line); 152 Expect.equals(null, line);
144 stage++; 153 stage++;
145 } 154 }
146 } 155 }
147 156
148 void streamClosed() { 157 void streamClosed() {
149 Expect.equals(4, stage); 158 Expect.equals(4, stage);
150 Expect.equals(true, stream.closed); 159 Expect.equals(true, stream.closed);
151 } 160 }
152 161
153 stream.onLine = stringData; 162 stream.onLine = stringData;
154 stream.onClosed = streamClosed; 163 stream.onClosed = streamClosed;
155 s.write("Line1\nLine2\r\nLine3\rLi".charCodes()); 164 s.write("Line1\nLine2\r\nLine3\rLi".charCodes());
156 } 165 }
157 166
158 main() { 167 main() {
159 testUtf8(); 168 testUtf8();
160 testLatin1(); 169 testLatin1();
161 testAscii(); 170 testAscii();
162 testReadLine1(); 171 testReadLine1();
163 testReadLine2(); 172 testReadLine2();
164 } 173 }
OLDNEW
« runtime/bin/input_stream.dart ('K') | « runtime/bin/string_stream.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698