OLD | NEW |
(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 main() { |
| 15 var dir; |
| 16 testFile(Encoding encoding, bool base64) { |
| 17 group("${encoding.name}${base64 ? " base64" : ""}", () { |
| 18 var uri; |
| 19 setUp(() { |
| 20 var dataUri = new UriData.fromString(content, |
| 21 encoding: encoding, |
| 22 base64: base64); |
| 23 uri = dataUri.uri; |
| 24 }); |
| 25 |
| 26 test("read string", () async { |
| 27 var loader = ResourceLoader.defaultLoader; |
| 28 String string = await loader.readAsString(uri, encoding: encoding); |
| 29 expect(string, content); |
| 30 }); |
| 31 |
| 32 test("read bytes", () async { |
| 33 var loader = ResourceLoader.defaultLoader; |
| 34 List<int> bytes = await loader.readAsBytes(uri); |
| 35 expect(bytes, encoding.encode(content)); |
| 36 }); |
| 37 |
| 38 test("read byte stream", () async { |
| 39 var loader = ResourceLoader.defaultLoader; |
| 40 Stream<int> bytes = loader.openRead(uri); |
| 41 var buffer = []; |
| 42 await bytes.forEach(buffer.addAll); |
| 43 expect(buffer, encoding.encode(content)); |
| 44 }); |
| 45 }); |
| 46 } |
| 47 testFile(LATIN1, true); |
| 48 testFile(LATIN1, false); |
| 49 testFile(UTF8, true); |
| 50 testFile(UTF8, false); |
| 51 } |
OLD | NEW |