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

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

Issue 2619793002: Add offset to UTF8-decode format exceptions. (Closed)
Patch Set: Created 3 years, 11 months 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
« no previous file with comments | « sdk/lib/convert/utf.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 cc4c7f5912006d46f879fbf1517c6b9d8086a225..f24dffc96f2e108495553e13f5e43c6ceebd200d 100644
--- a/tests/lib/convert/utf8_test.dart
+++ b/tests/lib/convert/utf8_test.dart
@@ -16,6 +16,7 @@ void main() {
}
testDecodeSlice();
+ testErrorOffset();
}
void testDecodeSlice() {
@@ -43,3 +44,40 @@ void testDecodeSlice() {
Expect.throws(() => decoder.convert(utf8, 0, 1));
Expect.throws(() => decoder.convert(utf8, 2, 5));
}
+
+void testErrorOffset() {
+ // Test that failed convert calls have an offset in the exception.
+ testExn(input, offset) {
+ Expect.throws(() { UTF8.decoder.convert(input); },
+ (e) => e is FormatException &&
+ input == e.source &&
+ offset == e.offset);
+ }
+
+ // Bad encoding, points to first bad byte.
+ testExn([0x80, 0x00], 0);
+ testExn([0xC0, 0x00], 1);
+ testExn([0xE0, 0x00], 1);
+ testExn([0xE0, 0x80, 0x00], 2);
+ testExn([0xF0, 0x00], 1);
+ testExn([0xF0, 0x80, 0x00], 2);
+ testExn([0xF0, 0x80, 0x80, 0x00], 3);
+ testExn([0xF8, 0x00], 0);
+ // Short encoding, points to end.
+ testExn([0xC0], 1);
+ testExn([0xE0], 1);
+ testExn([0xE0, 0x80], 2);
+ testExn([0xF0], 1);
+ testExn([0xF0, 0x80], 2);
+ testExn([0xF0, 0x80, 0x80], 3);
+ // Overlong encoding, points to start of encoding.
+ testExn([0xC0, 0x80], 0);
+ testExn([0xC1, 0xBF], 0);
+ testExn([0xE0, 0x80, 0x80], 0);
+ testExn([0xE0, 0x9F, 0xBF], 0);
+ testExn([0xF0, 0x80, 0x80, 0x80], 0);
+ testExn([0xF0, 0x8F, 0xBF, 0xBF], 0);
+ // Invalid character (value too large, over 0x10FFFF).
+ testExn([0xF4, 0x90, 0x80, 0x80], 0);
+ testExn([0xF7, 0xBF, 0xBF, 0xBF], 0);
+}
« no previous file with comments | « sdk/lib/convert/utf.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698