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

Side by Side Diff: test/codegen/lib/convert/chunked_conversion_utf82_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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library utf8_test; 5 library utf8_test;
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 String decode(List<int> bytes, int chunkSize) { 9 String decode(List<int> bytes, int chunkSize) {
10 StringBuffer buffer = new StringBuffer(); 10 StringBuffer buffer = new StringBuffer();
11 ChunkedConversionSink stringSink = 11 var stringSink = new StringConversionSink.fromStringSink(buffer);
12 new StringConversionSink.fromStringSink(buffer);
13 var byteSink = new Utf8Decoder().startChunkedConversion(stringSink); 12 var byteSink = new Utf8Decoder().startChunkedConversion(stringSink);
14 int i = 0; 13 int i = 0;
15 while (i < bytes.length) { 14 while (i < bytes.length) {
16 List nextChunk = []; 15 List nextChunk = [];
17 for (int j = 0; j < chunkSize; j++) { 16 for (int j = 0; j < chunkSize; j++) {
18 if (i < bytes.length) { 17 if (i < bytes.length) {
19 nextChunk.add(bytes[i]); 18 nextChunk.add(bytes[i]);
20 i++; 19 i++;
21 } 20 }
22 } 21 }
23 byteSink.add(nextChunk); 22 byteSink.add(nextChunk);
24 } 23 }
25 byteSink.close(); 24 byteSink.close();
26 return buffer.toString(); 25 return buffer.toString();
27 } 26 }
28 27
29 String decodeAllowMalformed(List<int> bytes, int chunkSize) { 28 String decodeAllowMalformed(List<int> bytes, int chunkSize) {
30 StringBuffer buffer = new StringBuffer(); 29 StringBuffer buffer = new StringBuffer();
31 ChunkedConversionSink stringSink = 30 var stringSink = new StringConversionSink.fromStringSink(buffer);
32 new StringConversionSink.fromStringSink(buffer);
33 var decoder = new Utf8Decoder(allowMalformed: true); 31 var decoder = new Utf8Decoder(allowMalformed: true);
34 var byteSink = decoder.startChunkedConversion(stringSink); 32 var byteSink = decoder.startChunkedConversion(stringSink);
35 int i = 0; 33 int i = 0;
36 while (i < bytes.length) { 34 while (i < bytes.length) {
37 List nextChunk = []; 35 List nextChunk = [];
38 for (int j = 0; j < chunkSize; j++) { 36 for (int j = 0; j < chunkSize; j++) {
39 if (i < bytes.length) { 37 if (i < bytes.length) {
40 nextChunk.add(bytes[i]); 38 nextChunk.add(bytes[i]);
41 i++; 39 i++;
42 } 40 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 Expect.throws(() => decode(bytes, 3), (e) => e is FormatException); 144 Expect.throws(() => decode(bytes, 3), (e) => e is FormatException);
147 Expect.throws(() => decode(bytes, 4), (e) => e is FormatException); 145 Expect.throws(() => decode(bytes, 4), (e) => e is FormatException);
148 146
149 String expected = test[1]; 147 String expected = test[1];
150 Expect.equals(expected, decodeAllowMalformed(bytes, 1)); 148 Expect.equals(expected, decodeAllowMalformed(bytes, 1));
151 Expect.equals(expected, decodeAllowMalformed(bytes, 2)); 149 Expect.equals(expected, decodeAllowMalformed(bytes, 2));
152 Expect.equals(expected, decodeAllowMalformed(bytes, 3)); 150 Expect.equals(expected, decodeAllowMalformed(bytes, 3));
153 Expect.equals(expected, decodeAllowMalformed(bytes, 4)); 151 Expect.equals(expected, decodeAllowMalformed(bytes, 4));
154 } 152 }
155 } 153 }
OLDNEW
« no previous file with comments | « test/codegen/lib/convert/ascii_test.dart ('k') | test/codegen/lib/convert/chunked_conversion_utf83_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698