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

Side by Side Diff: tests/corelib_strong/data_resource_test.dart

Issue 2986503002: Migrate test block 4 to Dart 2.0. (Closed)
Patch Set: Merge with head Created 3 years, 5 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
« no previous file with comments | « tests/corelib_strong/corelib_strong.status ('k') | tests/corelib_strong/data_uri_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
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 const sampleText = "Sample text file.";
6
7 main() async {
8 var uriEncoded = sampleText.replaceAll(' ', '%20');
9 await testUri("data:application/dart;charset=utf-8,$uriEncoded");
10 // TODO: Support other data: URI formats too.
11 // See: https://github.com/dart-lang/sdk/issues/24030
12 // await testUri("data:text/plain;charset=utf-8,$uriEncoded");
13 var base64Encoded = "U2FtcGxlIHRleHQgZmlsZS4=";
14 // await testUri("data:application/dart;charset=utf-8;base64,$base64Encoded");
15 // await testUri("data:text/plain;charset=utf-8;base64,$base64Encoded");
16 }
17
18 testUri(uriText) async {
19 var resource = new Resource(uriText);
20
21 if (resource.uri != Uri.parse(uriText)) {
22 throw "uriText: Incorrect URI: ${resource.uri}";
23 }
24
25 var text = await resource.readAsString();
26 if (text != sampleText) {
27 throw "uriText: Incorrect reading of text file: $text";
28 }
29
30 var bytes = await resource.readAsBytes();
31 if (!compareBytes(bytes, sampleText.codeUnits)) {
32 throw "uriText: Incorrect reading of bytes: $bytes";
33 }
34
35 var streamBytes = [];
36 await for (var byteSlice in resource.openRead()) {
37 streamBytes.addAll(byteSlice);
38 }
39 if (!compareBytes(streamBytes, sampleText.codeUnits)) {
40 throw "uriText: Incorrect reading of bytes: $bytes";
41 }
42 }
43
44 /// Checks that [bytes] and [expectedBytes] have the same contents.
45 bool compareBytes(bytes, expectedBytes) {
46 if (bytes.length != expectedBytes.length) return false;
47 for (int i = 0; i < expectedBytes.length; i++) {
48 if (bytes[i] != expectedBytes[i]) return false;
49 }
50 return true;
51 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/corelib_strong.status ('k') | tests/corelib_strong/data_uri_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698