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

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

Issue 10035056: Fix a number of editor errors and warnings in io tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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,
11 0xdf, 0xbf, 11 0xdf, 0xbf,
12 0xe0, 0xa0, 0x80, 12 0xe0, 0xa0, 0x80,
13 0xef, 0xbf, 0xbf]; 13 0xef, 0xbf, 0xbf];
14 InputStream s = new ListInputStream(); 14 ListInputStream s = new ListInputStream();
15 s.write(data); 15 s.write(data);
16 s.markEndOfStream(); 16 s.markEndOfStream();
17 StringInputStream stream = new StringInputStream(s); 17 StringInputStream stream = new StringInputStream(s);
18 void stringData() { 18 void stringData() {
19 String s = stream.read(); 19 String s = stream.read();
20 Expect.equals(6, s.length); 20 Expect.equals(6, s.length);
21 Expect.equals(new String.fromCharCodes([0x01]), s[0]); 21 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
22 Expect.equals(new String.fromCharCodes([0x7f]), s[1]); 22 Expect.equals(new String.fromCharCodes([0x7f]), s[1]);
23 Expect.equals(new String.fromCharCodes([0x80]), s[2]); 23 Expect.equals(new String.fromCharCodes([0x80]), s[2]);
24 Expect.equals(new String.fromCharCodes([0x7ff]), s[3]); 24 Expect.equals(new String.fromCharCodes([0x7ff]), s[3]);
25 Expect.equals(new String.fromCharCodes([0x800]), s[4]); 25 Expect.equals(new String.fromCharCodes([0x800]), s[4]);
26 Expect.equals(new String.fromCharCodes([0xffff]), s[5]); 26 Expect.equals(new String.fromCharCodes([0xffff]), s[5]);
27 } 27 }
28 stream.onData = stringData; 28 stream.onData = stringData;
29 } 29 }
30 30
31 void testLatin1() { 31 void testLatin1() {
32 List<int> data = [0x01, 32 List<int> data = [0x01,
33 0x7f, 33 0x7f,
34 0x44, 0x61, 0x72, 0x74, 34 0x44, 0x61, 0x72, 0x74,
35 0x80, 35 0x80,
36 0xff]; 36 0xff];
37 InputStream s = new ListInputStream(); 37 ListInputStream s = new ListInputStream();
38 s.write(data); 38 s.write(data);
39 s.markEndOfStream(); 39 s.markEndOfStream();
40 StringInputStream stream = new StringInputStream(s, Encoding.ISO_8859_1); 40 StringInputStream stream = new StringInputStream(s, Encoding.ISO_8859_1);
41 void stringData() { 41 void stringData() {
42 String s = stream.read(); 42 String s = stream.read();
43 Expect.equals(8, s.length); 43 Expect.equals(8, s.length);
44 Expect.equals(new String.fromCharCodes([0x01]), s[0]); 44 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
45 Expect.equals(new String.fromCharCodes([0x7f]), s[1]); 45 Expect.equals(new String.fromCharCodes([0x7f]), s[1]);
46 Expect.equals("Dart", s.substring(2, 6)); 46 Expect.equals("Dart", s.substring(2, 6));
47 Expect.equals(new String.fromCharCodes([0x80]), s[6]); 47 Expect.equals(new String.fromCharCodes([0x80]), s[6]);
48 Expect.equals(new String.fromCharCodes([0xff]), s[7]); 48 Expect.equals(new String.fromCharCodes([0xff]), s[7]);
49 } 49 }
50 stream.onData = stringData; 50 stream.onData = stringData;
51 } 51 }
52 52
53 void testAscii() { 53 void testAscii() {
54 List<int> data = [0x01, 54 List<int> data = [0x01,
55 0x44, 0x61, 0x72, 0x74, 55 0x44, 0x61, 0x72, 0x74,
56 0x7f]; 56 0x7f];
57 InputStream s = new ListInputStream(); 57 ListInputStream s = new ListInputStream();
58 s.write(data); 58 s.write(data);
59 s.markEndOfStream(); 59 s.markEndOfStream();
60 StringInputStream stream = 60 StringInputStream stream =
61 new StringInputStream(s, Encoding.ASCII); 61 new StringInputStream(s, Encoding.ASCII);
62 void stringData() { 62 void stringData() {
63 String s = stream.read(); 63 String s = stream.read();
64 Expect.equals(6, s.length); 64 Expect.equals(6, s.length);
65 Expect.equals(new String.fromCharCodes([0x01]), s[0]); 65 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
66 Expect.equals("Dart", s.substring(1, 5)); 66 Expect.equals("Dart", s.substring(1, 5));
67 Expect.equals(new String.fromCharCodes([0x7f]), s[5]); 67 Expect.equals(new String.fromCharCodes([0x7f]), s[5]);
68 } 68 }
69 stream.onData = stringData; 69 stream.onData = stringData;
70 } 70 }
71 71
72 void testReadLine1() { 72 void testReadLine1() {
73 InputStream s = new ListInputStream(); 73 ListInputStream s = new ListInputStream();
74 StringInputStream stream = new StringInputStream(s); 74 StringInputStream stream = new StringInputStream(s);
75 var stage = 0; 75 var stage = 0;
76 76
77 void stringData() { 77 void stringData() {
78 var line; 78 var line;
79 if (stage == 0) { 79 if (stage == 0) {
80 line = stream.readLine(); 80 line = stream.readLine();
81 Expect.equals(null, line); 81 Expect.equals(null, line);
82 stage++; 82 stage++;
83 s.markEndOfStream(); 83 s.markEndOfStream();
(...skipping 10 matching lines...) Expand all
94 Expect.equals(true, stream.closed); 94 Expect.equals(true, stream.closed);
95 Expect.equals(2, stage); 95 Expect.equals(2, stage);
96 } 96 }
97 97
98 stream.onData = stringData; 98 stream.onData = stringData;
99 stream.onClosed = streamClosed; 99 stream.onClosed = streamClosed;
100 s.write("Line".charCodes()); 100 s.write("Line".charCodes());
101 } 101 }
102 102
103 void testReadLine2() { 103 void testReadLine2() {
104 InputStream s = new ListInputStream(); 104 ListInputStream s = new ListInputStream();
105 StringInputStream stream = new StringInputStream(s); 105 StringInputStream stream = new StringInputStream(s);
106 var stage = 0; 106 var stage = 0;
107 107
108 void stringData() { 108 void stringData() {
109 var line; 109 var line;
110 if (stage == 0) { 110 if (stage == 0) {
111 Expect.equals(21, stream.available()); 111 Expect.equals(21, stream.available());
112 line = stream.readLine(); 112 line = stream.readLine();
113 Expect.equals("Line1", line); 113 Expect.equals("Line1", line);
114 Expect.equals(15, stream.available()); 114 Expect.equals(15, stream.available());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void streamClosed() { 158 void streamClosed() {
159 Expect.equals(4, stage); 159 Expect.equals(4, stage);
160 Expect.equals(true, stream.closed); 160 Expect.equals(true, stream.closed);
161 } 161 }
162 162
163 stream.onLine = stringData; 163 stream.onLine = stringData;
164 stream.onClosed = streamClosed; 164 stream.onClosed = streamClosed;
165 s.write("Line1\nLine2\r\nLine3\rLi".charCodes()); 165 s.write("Line1\nLine2\r\nLine3\rLi".charCodes());
166 } 166 }
167 167
168 class TestException { 168 class TestException implements Exception {
169 TestException(); 169 TestException();
170 } 170 }
171 171
172 class ErrorInputStream implements InputStream { 172 class ErrorInputStream implements InputStream {
173 ErrorInputStream(); 173 ErrorInputStream();
174 List<int> read([int len]) => null; 174 List<int> read([int len]) => null;
175 int readInto(List<int> buffer, [int offset, int len]) => 0; 175 int readInto(List<int> buffer, [int offset, int len]) => 0;
176 int available() => 0; 176 int available() => 0;
177 void pipe(OutputStream output, [bool close]){ } 177 void pipe(OutputStream output, [bool close]){ }
178 void close() { } 178 void close() { }
(...skipping 16 matching lines...) Expand all
195 } 195 }
196 196
197 main() { 197 main() {
198 testUtf8(); 198 testUtf8();
199 testLatin1(); 199 testLatin1();
200 testAscii(); 200 testAscii();
201 testReadLine1(); 201 testReadLine1();
202 testReadLine2(); 202 testReadLine2();
203 testErrorHandler(); 203 testErrorHandler();
204 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698