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

Side by Side Diff: tests/lib/convert/ascii_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 documentation for new parameters. 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
« no previous file with comments | « sdk/lib/convert/utf.dart ('k') | tests/lib/convert/latin1_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7
8 var asciiStrings = [ 8 var asciiStrings = [
9 "pure ascii", 9 "pure ascii",
10 "\x00 with control characters \n", 10 "\x00 with control characters \n",
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 Expect.equals(asciiString, roundTripString); 47 Expect.equals(asciiString, roundTripString);
48 roundTripString = codec.decode(bytes); 48 roundTripString = codec.decode(bytes);
49 Expect.equals(asciiString, roundTripString); 49 Expect.equals(asciiString, roundTripString);
50 } 50 }
51 51
52 for (var nonAsciiString in nonAsciiStrings) { 52 for (var nonAsciiString in nonAsciiStrings) {
53 Expect.throws(() { 53 Expect.throws(() {
54 print(codec.encoder.convert(nonAsciiString)); 54 print(codec.encoder.convert(nonAsciiString));
55 }, null, nonAsciiString); 55 }, null, nonAsciiString);
56 } 56 }
57
58 var encode = codec.encoder.convert;
59 Expect.listEquals([0x42, 0x43, 0x44], encode("ABCDE", 1, 4));
60 Expect.listEquals([0x42, 0x43, 0x44, 0x45], encode("ABCDE", 1));
61 Expect.listEquals([0x42, 0x43, 0x44], encode("\xffBCD\xff", 1, 4));
62 Expect.throws(() { encode("\xffBCD\xff", 0, 4); });
63 Expect.throws(() { encode("\xffBCD\xff", 1); });
64 Expect.throws(() { encode("\xffBCD\xff", 1, 5); });
65 Expect.throws(() { encode("\xffBCD\xff", -1, 4); });
66 Expect.throws(() { encode("\xffBCD\xff", 1, -1); });
67 Expect.throws(() { encode("\xffBCD\xff", 3, 2); });
68
69 var decode = codec.decoder.convert;
70 Expect.equals("BCD", decode([0x41, 0x42, 0x43, 0x44, 0x45], 1, 4));
71 Expect.equals("BCDE", decode([0x41, 0x42, 0x43, 0x44, 0x45], 1));
72 Expect.equals("BCD", decode([0xFF, 0x42, 0x43, 0x44, 0xFF], 1, 4));
73 Expect.throws(() { decode([0xFF, 0x42, 0x43, 0x44, 0xFF], 0, 4); });
74 Expect.throws(() { decode([0xFF, 0x42, 0x43, 0x44, 0xFF], 1); });
75 Expect.throws(() { decode([0xFF, 0x42, 0x43, 0x44, 0xFF], 1, 5); });
76 Expect.throws(() { decode([0xFF, 0x42, 0x43, 0x44, 0xFF], -1, 4); });
77 Expect.throws(() { decode([0xFF, 0x42, 0x43, 0x44, 0xFF], 1, -1); });
78 Expect.throws(() { decode([0xFF, 0x42, 0x43, 0x44, 0xFF], 3, 2); });
57 } 79 }
58 80
59 var allowInvalidCodec = new AsciiCodec(allowInvalid: true); 81 var allowInvalidCodec = new AsciiCodec(allowInvalid: true);
60 var invalidBytes = [0, 1, 0xff, 0xdead, 0]; 82 var invalidBytes = [0, 1, 0xff, 0xdead, 0];
61 String decoded = allowInvalidCodec.decode(invalidBytes); 83 String decoded = allowInvalidCodec.decode(invalidBytes);
62 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded); 84 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded);
63 decoded = allowInvalidCodec.decoder.convert(invalidBytes); 85 decoded = allowInvalidCodec.decoder.convert(invalidBytes);
64 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded); 86 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded);
65 decoded = ASCII.decode(invalidBytes, allowInvalid: true); 87 decoded = ASCII.decode(invalidBytes, allowInvalid: true);
66 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded); 88 Expect.equals("\x00\x01\uFFFD\uFFFD\x00", decoded);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 151 }
130 for (var nonAsciiString in nonAsciiStrings) { 152 for (var nonAsciiString in nonAsciiStrings) {
131 var units = nonAsciiString.codeUnits.toList(); 153 var units = nonAsciiString.codeUnits.toList();
132 Expect.throws(() { 154 Expect.throws(() {
133 decode(units, chunkSize, converter); 155 decode(units, chunkSize, converter);
134 }); 156 });
135 } 157 }
136 } 158 }
137 } 159 }
138 } 160 }
OLDNEW
« no previous file with comments | « sdk/lib/convert/utf.dart ('k') | tests/lib/convert/latin1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698