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

Unified Diff: tests/lib/convert/utf8_encode_test.dart

Issue 736583008: Make Utf8Decoder and Utf8Encoder's convert methods take start and end too. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make UTF8.encoder/decoder return types be Utf8Encoder,Utf8Decoder, not just Converter<..> Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: tests/lib/convert/utf8_encode_test.dart
diff --git a/tests/lib/convert/utf8_encode_test.dart b/tests/lib/convert/utf8_encode_test.dart
index 4e15646347a6e4708992a2fdadede1d2867b1c66..489a12460e48c4fcbf3cec6df05a346e9c2d636c 100644
--- a/tests/lib/convert/utf8_encode_test.dart
+++ b/tests/lib/convert/utf8_encode_test.dart
@@ -9,11 +9,54 @@ import 'unicode_tests.dart';
List<int> encode(String str) => new Utf8Encoder().convert(str);
List<int> encode2(String str) => UTF8.encode(str);
-main() {
+void main() {
for (var test in UNICODE_TESTS) {
List<int> bytes = test[0];
String string = test[1];
Expect.listEquals(bytes, encode(string));
Expect.listEquals(bytes, encode2(string));
}
+
+ testEncodeSlice();
+}
+
+void testEncodeSlice() {
+ var encoder = UTF8.encoder;
+ String ascii = "ABCDE";
+ Expect.listEquals([0x41, 0x42, 0x43, 0x44, 0x45],
+ encoder.convert(ascii));
+ Expect.listEquals([0x41, 0x42, 0x43, 0x44, 0x45],
+ encoder.convert(ascii, 0));
+ Expect.listEquals([0x41, 0x42, 0x43, 0x44, 0x45],
+ encoder.convert(ascii, 0, 5));
+ Expect.listEquals([0x42, 0x43, 0x44, 0x45],
+ encoder.convert(ascii, 1));
+ Expect.listEquals([0x41, 0x42, 0x43, 0x44],
+ encoder.convert(ascii, 0, 4));
+ Expect.listEquals([0x42, 0x43, 0x44],
+ encoder.convert(ascii, 1, 4));
+
+ Expect.throws(() => encoder.convert(ascii, -1)); // start < 0.
+ Expect.throws(() => encoder.convert(ascii, 6)); // start > length
+ Expect.throws(() => encoder.convert(ascii, 0, -1)); // end < 0
+ Expect.throws(() => encoder.convert(ascii, 0, 6)); // end > length
+ Expect.throws(() => encoder.convert(ascii, 3, 2)); // end < start
+
+ var unicode = "\u0081\u0082\u1041\u{10101}";
+
+ Expect.listEquals([0xc2, 0x81, 0xc2, 0x82, 0xe1, 0x81, 0x81,
+ 0xf0, 0x90, 0x84, 0x81],
+ encoder.convert(unicode));
+ Expect.listEquals([0xc2, 0x81, 0xc2, 0x82, 0xe1, 0x81, 0x81,
+ 0xf0, 0x90, 0x84, 0x81],
+ encoder.convert(unicode, 0, unicode.length));
+ Expect.listEquals([0xc2, 0x82, 0xe1, 0x81, 0x81,
+ 0xf0, 0x90, 0x84, 0x81],
+ encoder.convert(unicode, 1));
+ Expect.listEquals([0xc2, 0x82, 0xe1, 0x81, 0x81],
+ encoder.convert(unicode, 1, 3));
+ // Split in the middle of a surrogate pair.
+ Expect.listEquals([0xc2, 0x82, 0xe1, 0x81, 0x81,
+ 0xed, 0xa0, 0x80],
+ encoder.convert(unicode, 1, 4));
}

Powered by Google App Engine
This is Rietveld 408576698