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

Side by Side Diff: test/resource_test.dart

Issue 1387163002: Add Resource package. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Created 5 years, 2 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
(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" show Future, Stream;
6 import "package:resource/resource.dart";
7 import "package:test/test.dart";
8 import "dart:convert" show Encoding, ASCII;
9
10 main() {
11 pkguri(path) => new Uri(scheme: "package", path: path);
12
13 testLoading(String name, PackageResolver resolver) {
14 group("$name resolver", () {
15 testLoad(Uri uri) async {
16 LogLoader loader = new LogLoader();
17 var resource = resolver.resource(uri, loader: loader);
18 var res = await resource.openRead().toList();
19 expect(res, [[0, 0, 0]]);
20 res = await resource.readAsBytes();
21 expect(res, [0, 0, 0]);
22 res = await resource.readAsString(encoding: ASCII);
23 expect(res, "\x00\x00\x00");
24 var resolved = resolver.resolve(uri);
25
26 expect(loader.requests, [["Stream", resolved],
27 ["Bytes", resolved],
28 ["String", resolved, ASCII]]);
29 }
30
31 test("load package: URIs", () async {
32 await testLoad(pkguri("foo/bar/baz"));
33 await testLoad(pkguri("bar/foo/baz"));
34 });
35 test("load non-pkgUri", () async {
36 await testLoad(Uri.parse("file://localhost/something?x#y"));
37 await testLoad(Uri.parse("http://auth/something?x#y"));
38 await testLoad(Uri.parse("https://auth/something?x#y"));
39 await testLoad(Uri.parse("unknown:/something"));
40 });
41 });
42 }
43 testLoading("root",
44 new PackageResolver.fromRoot(Uri.parse("file:///path/root/")));
45 var fooRoot = Uri.parse("file:///files/foo/");
46 var barRoot = Uri.parse("http://example.com/files/bar/");
47 testLoading("map",
48 new PackageResolver.fromMap({"foo": fooRoot, "bar": barRoot }));
49 }
50
51
52 class LogLoader implements ResourceLoader {
53 final List requests = [];
54 void reset() { requests.clear(); }
55 Stream<List<int>> openRead(Uri uri) async* {
56 requests.add(["Stream", uri]);
57 yield [0x00, 0x00, 0x00];
58 }
59 Future<List<int>> readAsBytes(Uri uri) async {
60 requests.add(["Bytes", uri]);
61 return [0x00, 0x00, 0x00];
62 }
63 Future<String> readAsString(Uri uri, {Encoding encoding}) async {
64 requests.add(["String", uri, encoding]);
65 return "\x00\x00\x00";
66 }
67 }
OLDNEW
« pubspec.yaml ('K') | « test/resolve_test.dart ('k') | tool/travis.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698