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

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

Issue 9500002: Rename blahHandler to onBlah throughout dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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
« no previous file with comments | « tests/standalone/src/StreamPipeTest.dart ('k') | tests/standalone/src/TestingServer.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) 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 InputStream 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.dataHandler = 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 InputStream s = new ListInputStream();
38 s.write(data); 38 s.write(data);
39 s.markEndOfStream(); 39 s.markEndOfStream();
40 StringInputStream stream = new StringInputStream(s, "ISO-8859-1"); 40 StringInputStream stream = new StringInputStream(s, "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.dataHandler = 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 InputStream s = new ListInputStream();
58 s.write(data); 58 s.write(data);
59 s.markEndOfStream(); 59 s.markEndOfStream();
60 StringInputStream stream = new StringInputStream(s, "ASCII"); 60 StringInputStream stream = new StringInputStream(s, "ASCII");
61 void stringData() { 61 void stringData() {
62 String s = stream.read(); 62 String s = stream.read();
63 Expect.equals(6, s.length); 63 Expect.equals(6, s.length);
64 Expect.equals(new String.fromCharCodes([0x01]), s[0]); 64 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
65 Expect.equals("Dart", s.substring(1, 5)); 65 Expect.equals("Dart", s.substring(1, 5));
66 Expect.equals(new String.fromCharCodes([0x7f]), s[5]); 66 Expect.equals(new String.fromCharCodes([0x7f]), s[5]);
67 } 67 }
68 stream.dataHandler = stringData; 68 stream.onData = stringData;
69 } 69 }
70 70
71 void testReadLine1() { 71 void testReadLine1() {
72 InputStream s = new ListInputStream(); 72 InputStream s = new ListInputStream();
73 StringInputStream stream = new StringInputStream(s); 73 StringInputStream stream = new StringInputStream(s);
74 var stage = 0; 74 var stage = 0;
75 75
76 void stringData() { 76 void stringData() {
77 var line; 77 var line;
78 if (stage == 0) { 78 if (stage == 0) {
79 line = stream.readLine(); 79 line = stream.readLine();
80 Expect.equals(null, line); 80 Expect.equals(null, line);
81 stage++; 81 stage++;
82 s.markEndOfStream(); 82 s.markEndOfStream();
83 } else if (stage == 1) { 83 } else if (stage == 1) {
84 line = stream.readLine(); 84 line = stream.readLine();
85 Expect.equals("Line", line); 85 Expect.equals("Line", line);
86 line = stream.readLine(); 86 line = stream.readLine();
87 Expect.equals(null, line); 87 Expect.equals(null, line);
88 stage++; 88 stage++;
89 } 89 }
90 } 90 }
91 91
92 void streamClosed() { 92 void streamClosed() {
93 Expect.equals(true, stream.closed); 93 Expect.equals(true, stream.closed);
94 Expect.equals(2, stage); 94 Expect.equals(2, stage);
95 } 95 }
96 96
97 stream.dataHandler = stringData; 97 stream.onData = stringData;
98 stream.closeHandler = streamClosed; 98 stream.onClosed = streamClosed;
99 s.write("Line".charCodes()); 99 s.write("Line".charCodes());
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;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 Expect.equals(null, line); 143 Expect.equals(null, line);
144 stage++; 144 stage++;
145 } 145 }
146 } 146 }
147 147
148 void streamClosed() { 148 void streamClosed() {
149 Expect.equals(4, stage); 149 Expect.equals(4, stage);
150 Expect.equals(true, stream.closed); 150 Expect.equals(true, stream.closed);
151 } 151 }
152 152
153 stream.lineHandler = stringData; 153 stream.onLine = stringData;
154 stream.closeHandler = streamClosed; 154 stream.onClosed = streamClosed;
155 s.write("Line1\nLine2\r\nLine3\rLi".charCodes()); 155 s.write("Line1\nLine2\r\nLine3\rLi".charCodes());
156 } 156 }
157 157
158 main() { 158 main() {
159 testUtf8(); 159 testUtf8();
160 testLatin1(); 160 testLatin1();
161 testAscii(); 161 testAscii();
162 testReadLine1(); 162 testReadLine1();
163 testReadLine2(); 163 testReadLine2();
164 } 164 }
OLDNEW
« no previous file with comments | « tests/standalone/src/StreamPipeTest.dart ('k') | tests/standalone/src/TestingServer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698