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

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

Issue 9572005: Move all tests using dart:io to a separate directory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review 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/TestExtensionTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #import("dart:io");
6
7 void testUtf8() {
8 List<int> data = [0x01,
9 0x7f,
10 0xc2, 0x80,
11 0xdf, 0xbf,
12 0xe0, 0xa0, 0x80,
13 0xef, 0xbf, 0xbf];
14 InputStream s = new ListInputStream();
15 s.write(data);
16 s.markEndOfStream();
17 StringInputStream stream = new StringInputStream(s);
18 void stringData() {
19 String s = stream.read();
20 Expect.equals(6, s.length);
21 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
22 Expect.equals(new String.fromCharCodes([0x7f]), s[1]);
23 Expect.equals(new String.fromCharCodes([0x80]), s[2]);
24 Expect.equals(new String.fromCharCodes([0x7ff]), s[3]);
25 Expect.equals(new String.fromCharCodes([0x800]), s[4]);
26 Expect.equals(new String.fromCharCodes([0xffff]), s[5]);
27 }
28 stream.onData = stringData;
29 }
30
31 void testLatin1() {
32 List<int> data = [0x01,
33 0x7f,
34 0x44, 0x61, 0x72, 0x74,
35 0x80,
36 0xff];
37 InputStream s = new ListInputStream();
38 s.write(data);
39 s.markEndOfStream();
40 StringInputStream stream = new StringInputStream(s, "ISO-8859-1");
41 void stringData() {
42 String s = stream.read();
43 Expect.equals(8, s.length);
44 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
45 Expect.equals(new String.fromCharCodes([0x7f]), s[1]);
46 Expect.equals("Dart", s.substring(2, 6));
47 Expect.equals(new String.fromCharCodes([0x80]), s[6]);
48 Expect.equals(new String.fromCharCodes([0xff]), s[7]);
49 }
50 stream.onData = stringData;
51 }
52
53 void testAscii() {
54 List<int> data = [0x01,
55 0x44, 0x61, 0x72, 0x74,
56 0x7f];
57 InputStream s = new ListInputStream();
58 s.write(data);
59 s.markEndOfStream();
60 StringInputStream stream = new StringInputStream(s, "ASCII");
61 void stringData() {
62 String s = stream.read();
63 Expect.equals(6, s.length);
64 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
65 Expect.equals("Dart", s.substring(1, 5));
66 Expect.equals(new String.fromCharCodes([0x7f]), s[5]);
67 }
68 stream.onData = stringData;
69 }
70
71 void testReadLine1() {
72 InputStream s = new ListInputStream();
73 StringInputStream stream = new StringInputStream(s);
74 var stage = 0;
75
76 void stringData() {
77 var line;
78 if (stage == 0) {
79 line = stream.readLine();
80 Expect.equals(null, line);
81 stage++;
82 s.markEndOfStream();
83 } else if (stage == 1) {
84 line = stream.readLine();
85 Expect.equals("Line", line);
86 line = stream.readLine();
87 Expect.equals(null, line);
88 stage++;
89 }
90 }
91
92 void streamClosed() {
93 Expect.equals(true, stream.closed);
94 Expect.equals(2, stage);
95 }
96
97 stream.onData = stringData;
98 stream.onClosed = streamClosed;
99 s.write("Line".charCodes());
100 }
101
102 void testReadLine2() {
103 InputStream s = new ListInputStream();
104 StringInputStream stream = new StringInputStream(s);
105 var stage = 0;
106
107 void stringData() {
108 var line;
109 if (stage == 0) {
110 line = stream.readLine();
111 Expect.equals("Line1", line);
112 line = stream.readLine();
113 Expect.equals("Line2", line);
114 line = stream.readLine();
115 Expect.equals("Line3", line);
116 line = stream.readLine();
117 Expect.equals(null, line);
118 stage++;
119 s.write("ne4\n".charCodes());
120 } else if (stage == 1) {
121 line = stream.readLine();
122 Expect.equals("Line4", line);
123 line = stream.readLine();
124 Expect.equals(null, line);
125 stage++;
126 s.write("\n\n\r\n\r\n\r\r".charCodes());
127 } else if (stage == 2) {
128 // Expect 5 empty lines. As long as the stream is not closed the
129 // final \r cannot be interpreted as a end of line.
130 for (int i = 0; i < 5; i++) {
131 line = stream.readLine();
132 Expect.equals("", line);
133 }
134 line = stream.readLine();
135 Expect.equals(null, line);
136 stage++;
137 s.markEndOfStream();
138 } else if (stage == 3) {
139 // The final \r can now be interpreted as an end of line.
140 line = stream.readLine();
141 Expect.equals("", line);
142 line = stream.readLine();
143 Expect.equals(null, line);
144 stage++;
145 }
146 }
147
148 void streamClosed() {
149 Expect.equals(4, stage);
150 Expect.equals(true, stream.closed);
151 }
152
153 stream.onLine = stringData;
154 stream.onClosed = streamClosed;
155 s.write("Line1\nLine2\r\nLine3\rLi".charCodes());
156 }
157
158 main() {
159 testUtf8();
160 testLatin1();
161 testAscii();
162 testReadLine1();
163 testReadLine2();
164 }
OLDNEW
« no previous file with comments | « tests/standalone/src/StreamPipeTest.dart ('k') | tests/standalone/src/TestExtensionTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698