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

Side by Side Diff: test/codegen/lib/convert/chunked_conversion_utf83_test.dart

Issue 2254883002: roll analyzer (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: update Created 4 years, 4 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 unified diff | Download patch
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 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 5 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
6 // for details. All rights reserved. Use of this source code is governed by a 6 // for details. All rights reserved. Use of this source code is governed by a
7 // BSD-style license that can be found in the LICENSE file. 7 // BSD-style license that can be found in the LICENSE file.
8 8
9 import "package:expect/expect.dart"; 9 import "package:expect/expect.dart";
10 import 'dart:convert'; 10 import 'dart:convert';
11 11
12 String decode(List<int> bytes, int chunkSize) { 12 String decode(List<int> bytes, int chunkSize) {
13 StringBuffer buffer = new StringBuffer(); 13 StringBuffer buffer = new StringBuffer();
14 ChunkedConversionSink stringSink = 14 var stringSink = new StringConversionSink.fromStringSink(buffer);
15 new StringConversionSink.fromStringSink(buffer);
16 var byteSink = new Utf8Decoder().startChunkedConversion(stringSink); 15 var byteSink = new Utf8Decoder().startChunkedConversion(stringSink);
17 int i = 0; 16 int i = 0;
18 while (i < bytes.length) { 17 while (i < bytes.length) {
19 List nextChunk = []; 18 List nextChunk = [];
20 for (int j = 0; j < chunkSize; j++) { 19 for (int j = 0; j < chunkSize; j++) {
21 if (i < bytes.length) { 20 if (i < bytes.length) {
22 nextChunk.add(bytes[i]); 21 nextChunk.add(bytes[i]);
23 i++; 22 i++;
24 } 23 }
25 } 24 }
26 byteSink.add(nextChunk); 25 byteSink.add(nextChunk);
27 } 26 }
28 byteSink.close(); 27 byteSink.close();
29 return buffer.toString(); 28 return buffer.toString();
30 } 29 }
31 30
32 String decodeAllowMalformed(List<int> bytes, int chunkSize) { 31 String decodeAllowMalformed(List<int> bytes, int chunkSize) {
33 StringBuffer buffer = new StringBuffer(); 32 StringBuffer buffer = new StringBuffer();
34 ChunkedConversionSink stringSink = 33 var stringSink = new StringConversionSink.fromStringSink(buffer);
35 new StringConversionSink.fromStringSink(buffer);
36 var decoder = new Utf8Decoder(allowMalformed: true); 34 var decoder = new Utf8Decoder(allowMalformed: true);
37 var byteSink = decoder.startChunkedConversion(stringSink); 35 var byteSink = decoder.startChunkedConversion(stringSink);
38 int i = 0; 36 int i = 0;
39 while (i < bytes.length) { 37 while (i < bytes.length) {
40 List nextChunk = []; 38 List nextChunk = [];
41 for (int j = 0; j < chunkSize; j++) { 39 for (int j = 0; j < chunkSize; j++) {
42 if (i < bytes.length) { 40 if (i < bytes.length) {
43 nextChunk.add(bytes[i]); 41 nextChunk.add(bytes[i]);
44 i++; 42 i++;
45 } 43 }
(...skipping 24 matching lines...) Expand all
70 Expect.equals("", decodeAllowMalformed([0xEF, 0xBB, 0xBF], 4)); 68 Expect.equals("", decodeAllowMalformed([0xEF, 0xBB, 0xBF], 4));
71 Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF], 1)); 69 Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF], 1));
72 Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF], 2)); 70 Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF], 2));
73 Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF], 3)); 71 Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF], 3));
74 Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF], 4)); 72 Expect.equals("a\u{FEFF}", decode([0x61, 0xEF, 0xBB, 0xBF], 4));
75 Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF], 1)); 73 Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF], 1));
76 Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF], 2)); 74 Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF], 2));
77 Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF], 3)); 75 Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF], 3));
78 Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF], 4)); 76 Expect.equals("a\u{FEFF}", decodeAllowMalformed([0x61, 0xEF, 0xBB, 0xBF], 4));
79 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698