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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'unicode_tests.dart'; 7 import 'unicode_tests.dart';
8 8
9 String decode(List<int> bytes) => new Utf8Decoder().convert(bytes); 9 String decode(List<int> bytes) => new Utf8Decoder().convert(bytes);
10 10
11 main() { 11 void main() {
12 for (var test in UNICODE_TESTS) { 12 for (var test in UNICODE_TESTS) {
13 List<int> bytes = test[0]; 13 List<int> bytes = test[0];
14 String expected = test[1]; 14 String expected = test[1];
15 Expect.stringEquals(expected, decode(bytes)); 15 Expect.stringEquals(expected, decode(bytes));
16 } 16 }
17
18 testDecodeSlice();
17 } 19 }
20
21 void testDecodeSlice() {
22 var decoder = UTF8.decoder; // Doesn't allow malformed.
23 var ascii = [0x41, 0x42, 0x43, 0x44, 0x45];
24 Expect.equals("ABCDE", decoder.convert(ascii));
25 Expect.equals("ABCDE", decoder.convert(ascii, 0));
26 Expect.equals("ABCDE", decoder.convert(ascii, 0, ascii.length));
27 Expect.equals("CDE", decoder.convert(ascii, 2));
28 Expect.equals("BCD", decoder.convert(ascii, 1, 4));
29 Expect.equals("ABCD", decoder.convert(ascii, 0, 4));
30
31 Expect.throws(() => decoder.convert(ascii, -1)); // start < 0.
32 Expect.throws(() => decoder.convert(ascii, 6)); // start > length
33 Expect.throws(() => decoder.convert(ascii, 0, -1)); // end < 0
34 Expect.throws(() => decoder.convert(ascii, 0, 6)); // end > length
35 Expect.throws(() => decoder.convert(ascii, 3, 2)); // end < start
36
37 var utf8 = [0xc2, 0x81, 0xc2, 0x82, 0xe1, 0x81, 0x81];
38 Expect.equals("\u0081\u0082\u1041", decoder.convert(utf8));
39 Expect.equals("\u0082\u1041", decoder.convert(utf8, 2));
40 Expect.equals("\u0081\u0082", decoder.convert(utf8, 0, 4));
41 Expect.equals("\u0082", decoder.convert(utf8, 2, 4));
42 Expect.throws(() => decoder.convert(utf8, 1));
43 Expect.throws(() => decoder.convert(utf8, 0, 1));
44 Expect.throws(() => decoder.convert(utf8, 2, 5));
45 }
OLDNEW
« sdk/lib/convert/utf.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