Index: tests/lib/convert/chunked_conversion_utf85_test.dart |
diff --git a/tests/lib/convert/utf8_encode_test.dart b/tests/lib/convert/chunked_conversion_utf85_test.dart |
similarity index 51% |
copy from tests/lib/convert/utf8_encode_test.dart |
copy to tests/lib/convert/chunked_conversion_utf85_test.dart |
index 3aa208c11641a937449a52f74bc377401d5e6aa8..a5ae6b070eee51529f937b588341d5c34aeb2423 100644 |
--- a/tests/lib/convert/utf8_encode_test.dart |
+++ b/tests/lib/convert/chunked_conversion_utf85_test.dart |
@@ -2,7 +2,6 @@ |
// 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. |
-library utf8_test; |
import "package:expect/expect.dart"; |
import 'dart:convert'; |
@@ -38,9 +37,6 @@ const SIVA_STRING2 = "िसवा अणामालै"; |
const BEE_BYTES = const [0xf0, 0x90, 0x90, 0x92]; |
const BEE_STRING = "𐐒"; |
-const DIGIT_BYTES = const [ 0x35 ]; |
-const DIGIT_STRING = "5"; |
- |
const ASCII_BYTES = const [ 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, |
0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, |
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, |
@@ -48,17 +44,90 @@ const ASCII_BYTES = const [ 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, |
const ASCII_STRING = "abcdefghijklmnopqrstuvwxyz"; |
const TESTS = const [ |
- const [ const [], "" ], |
const [ INTER_BYTES, INTER_STRING ], |
const [ BLUEBERRY_BYTES, BLUEBERRY_STRING ], |
const [ SIVA_BYTES1, SIVA_STRING1 ], |
const [ SIVA_BYTES2, SIVA_STRING2 ], |
const [ BEE_BYTES, BEE_STRING ], |
- const [ DIGIT_BYTES, DIGIT_STRING ], |
const [ ASCII_BYTES, ASCII_STRING ]]; |
-List<int> encode(String str) => new Utf8Encoder().convert(str); |
-List<int> encode2(String str) => UTF8.encode(str); |
+List<int> encode(String str) { |
+ List<int> bytes; |
+ ChunkedConversionSink byteSink = |
+ new ByteConversionSink.withCallback((result) => bytes = result); |
+ var stringConversionSink = new Utf8Encoder().startChunkedConversion(byteSink); |
+ stringConversionSink.add(str); |
+ stringConversionSink.close(); |
+ return bytes; |
+} |
+ |
+List<int> encode2(String str) { |
+ List<int> bytes; |
+ ChunkedConversionSink byteSink = |
+ new ByteConversionSink.withCallback((result) => bytes = result); |
+ var stringConversionSink = new Utf8Encoder().startChunkedConversion(byteSink); |
+ ClosableStringSink stringSink = stringConversionSink.asStringSink(); |
+ stringSink.write(str); |
+ stringSink.close(); |
+ return bytes; |
+} |
+ |
+List<int> encode3(String str) { |
+ List<int> bytes; |
+ ChunkedConversionSink byteSink = |
+ new ByteConversionSink.withCallback((result) => bytes = result); |
+ var stringConversionSink = new Utf8Encoder().startChunkedConversion(byteSink); |
+ ClosableStringSink stringSink = stringConversionSink.asStringSink(); |
+ str.codeUnits.forEach(stringSink.writeCharCode); |
+ stringSink.close(); |
+ return bytes; |
+} |
+ |
+List<int> encode4(String str) { |
+ List<int> bytes; |
+ ChunkedConversionSink byteSink = |
+ new ByteConversionSink.withCallback((result) => bytes = result); |
+ var stringConversionSink = new Utf8Encoder().startChunkedConversion(byteSink); |
+ ClosableStringSink stringSink = stringConversionSink.asStringSink(); |
+ str.runes.forEach(stringSink.writeCharCode); |
+ stringSink.close(); |
+ return bytes; |
+} |
+ |
+List<int> encode5(String str) { |
+ List<int> bytes; |
+ ChunkedConversionSink byteSink = |
+ new ByteConversionSink.withCallback((result) => bytes = result); |
+ var stringConversionSink = new Utf8Encoder().startChunkedConversion(byteSink); |
+ ByteConversionSink inputByteSink = stringConversionSink.asUtf8Sink(false); |
+ List<int> tmpBytes = UTF8.encode(str); |
+ inputByteSink.add(tmpBytes); |
+ inputByteSink.close(); |
+ return bytes; |
+} |
+ |
+List<int> encode6(String str) { |
+ List<int> bytes; |
+ ChunkedConversionSink byteSink = |
+ new ByteConversionSink.withCallback((result) => bytes = result); |
+ var stringConversionSink = new Utf8Encoder().startChunkedConversion(byteSink); |
+ ByteConversionSink inputByteSink = stringConversionSink.asUtf8Sink(false); |
+ List<int> tmpBytes = UTF8.encode(str); |
+ tmpBytes.forEach((b) => inputByteSink.addSlice([0, b, 1], 1, 2, false)); |
+ inputByteSink.close(); |
+ return bytes; |
+} |
+ |
+List<int> encode7(String str) { |
+ List<int> bytes; |
+ ChunkedConversionSink byteSink = |
+ new ByteConversionSink.withCallback((result) => bytes = result); |
+ var stringConversionSink = new Utf8Encoder().startChunkedConversion(byteSink); |
+ stringConversionSink.addSlice("1" + str + "2", 1, str.length + 1, false); |
+ stringConversionSink.close(); |
+ return bytes; |
+} |
+ |
main() { |
Expect.equals(2, BEE_STRING.length); |
@@ -78,5 +147,10 @@ main() { |
String string = test[1]; |
Expect.listEquals(bytes, encode(string)); |
Expect.listEquals(bytes, encode2(string)); |
+ Expect.listEquals(bytes, encode3(string)); |
+ Expect.listEquals(bytes, encode4(string)); |
+ Expect.listEquals(bytes, encode5(string)); |
+ Expect.listEquals(bytes, encode6(string)); |
+ Expect.listEquals(bytes, encode7(string)); |
} |
} |