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

Side by Side Diff: test/loader_file_test.dart

Issue 1387163002: Add Resource package. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Address comments. Created 4 years, 11 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 | « test/loader_data_test.dart ('k') | test/loader_http_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 import "dart:async";
6 import "dart:convert";
7 import "dart:io";
8
9 import "package:resource/resource.dart";
10 import "package:test/test.dart";
11
12 const content = "Rødgrød med fløde";
13
14
15 main() {
16 var dir;
17 setUp(() {
18 dir = Directory.systemTemp.createTempSync('testdir');
19 });
20 testFile(Encoding encoding) {
21 group("${encoding.name}", () {
22 var file;
23 var uri;
24 setUp(() {
25 var dirUri = dir.uri;
26 uri = dirUri.resolve("file.txt");
27 file = new File.fromUri(uri);
28 file.createSync();
29 var sink = file.openWrite(encoding: encoding);
30 sink.write(content);
31 sink.close();
32 });
33
34 test("read string", () async {
35 var loader = ResourceLoader.defaultLoader;
36 String string = await loader.readAsString(uri, encoding: encoding);
37 expect(string, content);
38 });
39
40 test("read bytes", () async {
41 var loader = ResourceLoader.defaultLoader;
42 List<int> bytes = await loader.readAsBytes(uri);
43 expect(bytes, encoding.encode(content));
44 });
45
46 test("read byte stream", () async {
47 var loader = ResourceLoader.defaultLoader;
48 Stream<int> bytes = loader.openRead(uri);
49 var buffer = [];
50 await bytes.forEach(buffer.addAll);
51 expect(buffer, encoding.encode(content));
52 });
53
54 tearDown(() {
55 file.deleteSync();
56 });
57 });
58 }
59 testFile(LATIN1);
60 testFile(UTF8);
61
62 tearDown(() {
63 dir.delete(recursive: true);
64 });
65 }
OLDNEW
« no previous file with comments | « test/loader_data_test.dart ('k') | test/loader_http_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698