Index: tests/standalone/src/StringStreamTest.dart |
diff --git a/tests/standalone/src/StringStreamTest.dart b/tests/standalone/src/StringStreamTest.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..26946a4f88bdad992e659e4b299c3e72d8454e35 |
--- /dev/null |
+++ b/tests/standalone/src/StringStreamTest.dart |
@@ -0,0 +1,56 @@ |
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+class ListInputStream implements InputStream2 { |
+ List<int> read() { |
+ var result = _data; |
+ _data = null; |
+ return result; |
+ } |
+ |
+ void set dataHandler(void callback()) { |
+ _datahandler = callback; |
+ } |
+ |
+ void set closeHandler(void callback()) { |
+ } |
+ |
+ void set errorHandler(void callback(int error)) { |
+ } |
+ |
+ write(List<int> data) { |
+ Expect.equals(null, _data); |
+ _data = data; |
+ if (_datahandler != null) { |
+ _datahandler(); |
+ } |
+ } |
+ |
+ List<int> _data; |
+ var _datahandler; |
+} |
+ |
+ |
+main() { |
+ List<int> data = [0x01, |
+ 0x7f, |
+ 0xc2, 0x80, |
+ 0xdf, 0xbf, |
+ 0xe0, 0xa0, 0x80, |
+ 0xef, 0xbf, 0xbf]; |
+ InputStream2 s = new ListInputStream(); |
+ StringInputStream stream = new StringInputStream(s); |
+ void stringData() { |
+ String s = stream.read(); |
+ Expect.equals(6, s.length); |
+ Expect.equals(new String.fromCharCodes([0x01]), s[0]); |
+ Expect.equals(new String.fromCharCodes([0x7f]), s[1]); |
+ Expect.equals(new String.fromCharCodes([0x80]), s[2]); |
+ Expect.equals(new String.fromCharCodes([0x7ff]), s[3]); |
+ Expect.equals(new String.fromCharCodes([0x800]), s[4]); |
+ Expect.equals(new String.fromCharCodes([0xffff]), s[5]); |
+ } |
+ stream.dataHandler = stringData; |
+ s.write(data); |
+} |