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

Side by Side Diff: tests/lib/convert/latin1_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 | « tests/lib/convert/ascii_test.dart ('k') | tests/lib/convert/utf8_encode_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 latin1Strings = [ 8 var latin1Strings = [
9 "pure ascii", 9 "pure ascii",
10 "blåbærgrød", 10 "blåbærgrød",
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 Expect.equals(latin1String, roundTripString); 45 Expect.equals(latin1String, roundTripString);
46 roundTripString = codec.decode(bytes); 46 roundTripString = codec.decode(bytes);
47 Expect.equals(latin1String, roundTripString); 47 Expect.equals(latin1String, roundTripString);
48 } 48 }
49 49
50 for (var nonLatin1String in nonLatin1Strings) { 50 for (var nonLatin1String in nonLatin1Strings) {
51 Expect.throws(() { 51 Expect.throws(() {
52 print(codec.encoder.convert(nonLatin1String)); 52 print(codec.encoder.convert(nonLatin1String));
53 }, null, nonLatin1String); 53 }, null, nonLatin1String);
54 } 54 }
55
56 var encode = codec.encoder.convert;
57 Expect.listEquals([0x42, 0xff, 0x44], encode("AB\xffDE", 1, 4));
58 Expect.listEquals([0x42, 0xff, 0x44, 0x45], encode("AB\xffDE", 1));
59 Expect.listEquals([0x42, 0xff, 0x44], encode("\u3000B\xffD\u3000", 1, 4));
60 Expect.throws(() { encode("\u3000B\xffD\u3000", 0, 4); });
61 Expect.throws(() { encode("\u3000B\xffD\u3000", 1); });
62 Expect.throws(() { encode("\u3000B\xffD\u3000", 1, 5); });
63 Expect.throws(() { encode("\u3000B\xffD\u3000", -1, 4); });
64 Expect.throws(() { encode("\u3000B\xffD\u3000", 1, -1); });
65 Expect.throws(() { encode("\u3000B\xffD\u3000", 3, 2); });
66
67 var decode = codec.decoder.convert;
68 Expect.equals("B\xffD", decode([0x41, 0x42, 0xff, 0x44, 0x45], 1, 4));
69 Expect.equals("B\xffDE", decode([0x41, 0x42, 0xff, 0x44, 0x45], 1));
70 Expect.equals("B\xffD", decode([0xFF, 0x42, 0xff, 0x44, 0xFF], 1, 4));
71 Expect.throws(() { decode([0x3000, 0x42, 0xff, 0x44, 0x3000], 0, 4); });
72 Expect.throws(() { decode([0x3000, 0x42, 0xff, 0x44, 0x3000], 1); });
73 Expect.throws(() { decode([0x3000, 0x42, 0xff, 0x44, 0x3000], 1, 5); });
74 Expect.throws(() { decode([0x3000, 0x42, 0xff, 0x44, 0x3000], -1, 4); });
75 Expect.throws(() { decode([0x3000, 0x42, 0xff, 0x44, 0x3000], 1, -1); });
76 Expect.throws(() { decode([0x3000, 0x42, 0xff, 0x44, 0x3000], 3, 2); });
55 } 77 }
56 78
57 var allowInvalidCodec = new Latin1Codec(allowInvalid: true); 79 var allowInvalidCodec = new Latin1Codec(allowInvalid: true);
58 var invalidBytes = [0, 1, 0xff, 0xdead, 0]; 80 var invalidBytes = [0, 1, 0xff, 0xdead, 0];
59 String decoded = allowInvalidCodec.decode(invalidBytes); 81 String decoded = allowInvalidCodec.decode(invalidBytes);
60 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded); 82 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded);
61 decoded = allowInvalidCodec.decoder.convert(invalidBytes); 83 decoded = allowInvalidCodec.decoder.convert(invalidBytes);
62 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded); 84 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded);
63 decoded = LATIN1.decode(invalidBytes, allowInvalid: true); 85 decoded = LATIN1.decode(invalidBytes, allowInvalid: true);
64 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded); 86 Expect.equals("\x00\x01\xFF\uFFFD\x00", decoded);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 149 }
128 for (var nonLatin1String in nonLatin1Strings) { 150 for (var nonLatin1String in nonLatin1Strings) {
129 var units = nonLatin1String.codeUnits.toList(); 151 var units = nonLatin1String.codeUnits.toList();
130 Expect.throws(() { 152 Expect.throws(() {
131 decode(units, chunkSize, converter); 153 decode(units, chunkSize, converter);
132 }); 154 });
133 } 155 }
134 } 156 }
135 } 157 }
136 } 158 }
OLDNEW
« no previous file with comments | « tests/lib/convert/ascii_test.dart ('k') | tests/lib/convert/utf8_encode_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698