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/StringStreamTest.dart

Issue 9289042: Minor changes to the dart:io library files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing files. Created 8 years, 11 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/ListInputStreamTest.dart ('k') | no next file » | 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) 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(data); 14 InputStream s = new ListInputStream();
15 s.write(data);
16 s.markEndOfStream();
15 StringInputStream stream = new StringInputStream(s); 17 StringInputStream stream = new StringInputStream(s);
16 void stringData() { 18 void stringData() {
17 String s = stream.read(); 19 String s = stream.read();
18 Expect.equals(6, s.length); 20 Expect.equals(6, s.length);
19 Expect.equals(new String.fromCharCodes([0x01]), s[0]); 21 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
20 Expect.equals(new String.fromCharCodes([0x7f]), s[1]); 22 Expect.equals(new String.fromCharCodes([0x7f]), s[1]);
21 Expect.equals(new String.fromCharCodes([0x80]), s[2]); 23 Expect.equals(new String.fromCharCodes([0x80]), s[2]);
22 Expect.equals(new String.fromCharCodes([0x7ff]), s[3]); 24 Expect.equals(new String.fromCharCodes([0x7ff]), s[3]);
23 Expect.equals(new String.fromCharCodes([0x800]), s[4]); 25 Expect.equals(new String.fromCharCodes([0x800]), s[4]);
24 Expect.equals(new String.fromCharCodes([0xffff]), s[5]); 26 Expect.equals(new String.fromCharCodes([0xffff]), s[5]);
25 } 27 }
26 stream.dataHandler = stringData; 28 stream.dataHandler = stringData;
27 } 29 }
28 30
29 void testLatin1() { 31 void testLatin1() {
30 List<int> data = [0x01, 32 List<int> data = [0x01,
31 0x7f, 33 0x7f,
32 0x44, 0x61, 0x72, 0x74, 34 0x44, 0x61, 0x72, 0x74,
33 0x80, 35 0x80,
34 0xff]; 36 0xff];
35 InputStream s = new ListInputStream(data); 37 InputStream s = new ListInputStream();
38 s.write(data);
39 s.markEndOfStream();
36 StringInputStream stream = new StringInputStream(s, "ISO-8859-1"); 40 StringInputStream stream = new StringInputStream(s, "ISO-8859-1");
37 void stringData() { 41 void stringData() {
38 String s = stream.read(); 42 String s = stream.read();
39 Expect.equals(8, s.length); 43 Expect.equals(8, s.length);
40 Expect.equals(new String.fromCharCodes([0x01]), s[0]); 44 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
41 Expect.equals(new String.fromCharCodes([0x7f]), s[1]); 45 Expect.equals(new String.fromCharCodes([0x7f]), s[1]);
42 Expect.equals("Dart", s.substring(2, 6)); 46 Expect.equals("Dart", s.substring(2, 6));
43 Expect.equals(new String.fromCharCodes([0x80]), s[6]); 47 Expect.equals(new String.fromCharCodes([0x80]), s[6]);
44 Expect.equals(new String.fromCharCodes([0xff]), s[7]); 48 Expect.equals(new String.fromCharCodes([0xff]), s[7]);
45 } 49 }
46 stream.dataHandler = stringData; 50 stream.dataHandler = stringData;
47 } 51 }
48 52
49 void testAscii() { 53 void testAscii() {
50 List<int> data = [0x01, 54 List<int> data = [0x01,
51 0x44, 0x61, 0x72, 0x74, 55 0x44, 0x61, 0x72, 0x74,
52 0x7f]; 56 0x7f];
53 InputStream s = new ListInputStream(data); 57 InputStream s = new ListInputStream();
58 s.write(data);
59 s.markEndOfStream();
54 StringInputStream stream = new StringInputStream(s, "ASCII"); 60 StringInputStream stream = new StringInputStream(s, "ASCII");
55 void stringData() { 61 void stringData() {
56 String s = stream.read(); 62 String s = stream.read();
57 Expect.equals(6, s.length); 63 Expect.equals(6, s.length);
58 Expect.equals(new String.fromCharCodes([0x01]), s[0]); 64 Expect.equals(new String.fromCharCodes([0x01]), s[0]);
59 Expect.equals("Dart", s.substring(1, 5)); 65 Expect.equals("Dart", s.substring(1, 5));
60 Expect.equals(new String.fromCharCodes([0x7f]), s[5]); 66 Expect.equals(new String.fromCharCodes([0x7f]), s[5]);
61 } 67 }
62 stream.dataHandler = stringData; 68 stream.dataHandler = stringData;
63 } 69 }
64 70
65 void testReadLine1() { 71 void testReadLine1() {
66 InputStream s = new DynamicListInputStream(); 72 InputStream s = new ListInputStream();
67 StringInputStream stream = new StringInputStream(s); 73 StringInputStream stream = new StringInputStream(s);
68 var stage = 0; 74 var stage = 0;
69 75
70 void stringData() { 76 void stringData() {
71 var line; 77 var line;
72 if (stage == 0) { 78 if (stage == 0) {
73 line = stream.readLine(); 79 line = stream.readLine();
74 Expect.equals(null, line); 80 Expect.equals(null, line);
75 stage++; 81 stage++;
76 s.markEndOfStream(); 82 s.markEndOfStream();
(...skipping 10 matching lines...) Expand all
87 Expect.equals(true, stream.closed); 93 Expect.equals(true, stream.closed);
88 Expect.equals(2, stage); 94 Expect.equals(2, stage);
89 } 95 }
90 96
91 stream.dataHandler = stringData; 97 stream.dataHandler = stringData;
92 stream.closeHandler = streamClosed; 98 stream.closeHandler = streamClosed;
93 s.write("Line".charCodes()); 99 s.write("Line".charCodes());
94 } 100 }
95 101
96 void testReadLine2() { 102 void testReadLine2() {
97 InputStream s = new DynamicListInputStream(); 103 InputStream s = new ListInputStream();
98 StringInputStream stream = new StringInputStream(s); 104 StringInputStream stream = new StringInputStream(s);
99 var stage = 0; 105 var stage = 0;
100 106
101 void stringData() { 107 void stringData() {
102 var line; 108 var line;
103 if (stage == 0) { 109 if (stage == 0) {
104 line = stream.readLine(); 110 line = stream.readLine();
105 Expect.equals("Line1", line); 111 Expect.equals("Line1", line);
106 line = stream.readLine(); 112 line = stream.readLine();
107 Expect.equals("Line2", line); 113 Expect.equals("Line2", line);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 s.write("Line1\nLine2\r\nLine3\rLi".charCodes()); 155 s.write("Line1\nLine2\r\nLine3\rLi".charCodes());
150 } 156 }
151 157
152 main() { 158 main() {
153 testUtf8(); 159 testUtf8();
154 testLatin1(); 160 testLatin1();
155 testAscii(); 161 testAscii();
156 testReadLine1(); 162 testReadLine1();
157 testReadLine2(); 163 testReadLine2();
158 } 164 }
OLDNEW
« no previous file with comments | « tests/standalone/src/ListInputStreamTest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698