| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class ListInputStream implements InputStream { | 5 class ListInputStream implements InputStream { |
| 6 List<int> read() { | 6 List<int> read() { |
| 7 var result = _data; | 7 var result = _data; |
| 8 _data = null; | 8 _data = null; |
| 9 return result; | 9 return result; |
| 10 } | 10 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 if (stage == 0) { | 110 if (stage == 0) { |
| 111 line = stream.readLine(); | 111 line = stream.readLine(); |
| 112 Expect.equals(null, line); | 112 Expect.equals(null, line); |
| 113 stage++; | 113 stage++; |
| 114 s.close(); | 114 s.close(); |
| 115 } else if (stage == 1) { | 115 } else if (stage == 1) { |
| 116 line = stream.readLine(); | 116 line = stream.readLine(); |
| 117 Expect.equals("Line", line); | 117 Expect.equals("Line", line); |
| 118 line = stream.readLine(); | 118 line = stream.readLine(); |
| 119 Expect.equals(null, line); | 119 Expect.equals(null, line); |
| 120 Expect.equals(true, stream.closed); | |
| 121 stage++; | 120 stage++; |
| 122 } | 121 } |
| 123 } | 122 } |
| 124 | 123 |
| 125 void streamClosed() { | 124 void streamClosed() { |
| 125 Expect.equals(true, stream.closed); |
| 126 Expect.equals(2, stage); | 126 Expect.equals(2, stage); |
| 127 } | 127 } |
| 128 | 128 |
| 129 stream.dataHandler = stringData; | 129 stream.dataHandler = stringData; |
| 130 stream.closeHandler = streamClosed; | 130 stream.closeHandler = streamClosed; |
| 131 s.write("Line".charCodes()); | 131 s.write("Line".charCodes()); |
| 132 Expect.equals(2, stage); | |
| 133 } | 132 } |
| 134 | 133 |
| 135 void testReadLine2() { | 134 void testReadLine2() { |
| 136 InputStream s = new ListInputStream(); | 135 InputStream s = new ListInputStream(); |
| 137 StringInputStream stream = new StringInputStream(s); | 136 StringInputStream stream = new StringInputStream(s); |
| 138 var stage = 0; | 137 var stage = 0; |
| 139 | 138 |
| 140 void stringData() { | 139 void stringData() { |
| 141 var line; | 140 var line; |
| 142 if (stage == 0) { | 141 if (stage == 0) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 167 line = stream.readLine(); | 166 line = stream.readLine(); |
| 168 Expect.equals(null, line); | 167 Expect.equals(null, line); |
| 169 stage++; | 168 stage++; |
| 170 s.close(); | 169 s.close(); |
| 171 } else if (stage == 3) { | 170 } else if (stage == 3) { |
| 172 // The final \r can now be interpreted as an end of line. | 171 // The final \r can now be interpreted as an end of line. |
| 173 line = stream.readLine(); | 172 line = stream.readLine(); |
| 174 Expect.equals("", line); | 173 Expect.equals("", line); |
| 175 line = stream.readLine(); | 174 line = stream.readLine(); |
| 176 Expect.equals(null, line); | 175 Expect.equals(null, line); |
| 177 Expect.equals(true, stream.closed); | |
| 178 stage++; | 176 stage++; |
| 179 } | 177 } |
| 180 } | 178 } |
| 181 | 179 |
| 182 void streamClosed() { | 180 void streamClosed() { |
| 183 Expect.equals(4, stage); | 181 Expect.equals(4, stage); |
| 182 Expect.equals(true, stream.closed); |
| 184 } | 183 } |
| 185 | 184 |
| 186 stream.lineHandler = stringData; | 185 stream.lineHandler = stringData; |
| 187 stream.closeHandler = streamClosed; | 186 stream.closeHandler = streamClosed; |
| 188 s.write("Line1\nLine2\r\nLine3\rLi".charCodes()); | 187 s.write("Line1\nLine2\r\nLine3\rLi".charCodes()); |
| 189 Expect.equals(4, stage); | |
| 190 } | 188 } |
| 191 | 189 |
| 192 main() { | 190 main() { |
| 193 testUtf8(); | 191 testUtf8(); |
| 194 testLatin1(); | 192 testLatin1(); |
| 195 testAscii(); | 193 testAscii(); |
| 196 testReadLine1(); | 194 testReadLine1(); |
| 197 testReadLine2(); | 195 testReadLine2(); |
| 198 } | 196 } |
| OLD | NEW |