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

Unified Diff: tests/lib/convert/utf8_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: Add start/end support on ASCII/Latin-1 encoder and decoder. 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
« sdk/lib/convert/ascii.dart ('K') | « tests/lib/convert/utf8_encode_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/convert/utf8_test.dart
diff --git a/tests/lib/convert/utf8_test.dart b/tests/lib/convert/utf8_test.dart
index ba5bc898cbd2c8331ae5dacba317191044a1c55a..cc4c7f5912006d46f879fbf1517c6b9d8086a225 100644
--- a/tests/lib/convert/utf8_test.dart
+++ b/tests/lib/convert/utf8_test.dart
@@ -8,10 +8,38 @@ import 'unicode_tests.dart';
String decode(List<int> bytes) => new Utf8Decoder().convert(bytes);
-main() {
+void main() {
for (var test in UNICODE_TESTS) {
List<int> bytes = test[0];
String expected = test[1];
Expect.stringEquals(expected, decode(bytes));
}
+
+ testDecodeSlice();
+}
+
+void testDecodeSlice() {
+ var decoder = UTF8.decoder; // Doesn't allow malformed.
+ var ascii = [0x41, 0x42, 0x43, 0x44, 0x45];
+ Expect.equals("ABCDE", decoder.convert(ascii));
+ Expect.equals("ABCDE", decoder.convert(ascii, 0));
+ Expect.equals("ABCDE", decoder.convert(ascii, 0, ascii.length));
+ Expect.equals("CDE", decoder.convert(ascii, 2));
+ Expect.equals("BCD", decoder.convert(ascii, 1, 4));
+ Expect.equals("ABCD", decoder.convert(ascii, 0, 4));
+
+ Expect.throws(() => decoder.convert(ascii, -1)); // start < 0.
+ Expect.throws(() => decoder.convert(ascii, 6)); // start > length
+ Expect.throws(() => decoder.convert(ascii, 0, -1)); // end < 0
+ Expect.throws(() => decoder.convert(ascii, 0, 6)); // end > length
+ Expect.throws(() => decoder.convert(ascii, 3, 2)); // end < start
+
+ var utf8 = [0xc2, 0x81, 0xc2, 0x82, 0xe1, 0x81, 0x81];
+ Expect.equals("\u0081\u0082\u1041", decoder.convert(utf8));
+ Expect.equals("\u0082\u1041", decoder.convert(utf8, 2));
+ Expect.equals("\u0081\u0082", decoder.convert(utf8, 0, 4));
+ Expect.equals("\u0082", decoder.convert(utf8, 2, 4));
+ Expect.throws(() => decoder.convert(utf8, 1));
+ Expect.throws(() => decoder.convert(utf8, 0, 1));
+ Expect.throws(() => decoder.convert(utf8, 2, 5));
}
« sdk/lib/convert/ascii.dart ('K') | « tests/lib/convert/utf8_encode_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698