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

Side by Side Diff: pkg/barback/test/asset_test.dart

Issue 23469003: Add an AssetStream class to Barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests and fix a few bugs. Created 7 years, 3 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 | Annotate | Revision Log
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 barback.test.asset_test; 5 library barback.test.asset_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert' show Encoding, UTF8, LATIN1; 8 import 'dart:convert' show Encoding, UTF8, LATIN1;
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:utf'; 10 import 'dart:utf';
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 }); 66 });
67 }); 67 });
68 68
69 group("Asset.fromString", () { 69 group("Asset.fromString", () {
70 test("returns an asset with the given ID", () { 70 test("returns an asset with the given ID", () {
71 var asset = new Asset.fromString(id, "content"); 71 var asset = new Asset.fromString(id, "content");
72 expect(asset.id, equals(id)); 72 expect(asset.id, equals(id));
73 }); 73 });
74 }); 74 });
75 75
76 group("Asset.fromStream", () {
77 test("returns an asset with the given ID", () {
78 var asset = new Asset.fromStream(id,
79 new Stream.fromFuture(new Future.value([104, 101, 108, 108, 111])));
80 expect(asset.id, equals(id));
81 });
82 });
83
76 group("read()", () { 84 group("read()", () {
77 test("gets the UTF-8-encoded string for a string asset", () { 85 test("gets the UTF-8-encoded string for a string asset", () {
78 var asset = new Asset.fromString(id, "çøñ†éℵ™"); 86 var asset = new Asset.fromString(id, "çøñ†éℵ™");
79 expect(asset.read().toList(), 87 expect(asset.read().toList(),
80 completion(equals([encodeUtf8("çøñ†éℵ™")]))); 88 completion(equals([encodeUtf8("çøñ†éℵ™")])));
81 }); 89 });
82 90
83 test("gets the raw bytes for a byte asset", () { 91 test("gets the raw bytes for a byte asset", () {
84 var asset = new Asset.fromBytes(id, binaryContents); 92 var asset = new Asset.fromBytes(id, binaryContents);
85 expect(asset.read().toList(), 93 expect(asset.read().toList(),
86 completion(equals([binaryContents]))); 94 completion(equals([binaryContents])));
87 }); 95 });
88 96
89 test("gets the raw bytes for a binary file", () { 97 test("gets the raw bytes for a binary file", () {
90 var asset = new Asset.fromPath(id, binaryFilePath); 98 var asset = new Asset.fromPath(id, binaryFilePath);
91 expect(asset.read().toList(), 99 expect(asset.read().toList(),
92 completion(equals([binaryContents]))); 100 completion(equals([binaryContents])));
93 }); 101 });
94 102
95 test("gets the raw bytes for a text file", () { 103 test("gets the raw bytes for a text file", () {
96 var asset = new Asset.fromPath(id, textFilePath); 104 var asset = new Asset.fromPath(id, textFilePath);
97 expect(asset.read().toList(), 105 expect(asset.read().toList(),
98 completion(equals([encodeUtf8("çøñ†éℵ™")]))); 106 completion(equals([encodeUtf8("çøñ†éℵ™")])));
99 }); 107 });
108
109 test("gets the raw bytes for a stream", () {
110 var asset = new Asset.fromStream(id,
111 new Stream.fromFuture(new Future.value(encodeUtf8("çøñ†éℵ™"))));
112 expect(asset.read().toList(),
113 completion(equals([encodeUtf8("çøñ†éℵ™")])));
114 });
100 }); 115 });
101 116
102 group("readAsString()", () { 117 group("readAsString()", () {
103 group("byte asset", () { 118 group("byte asset", () {
104 test("defaults to UTF-8 if encoding is omitted", () { 119 test("defaults to UTF-8 if encoding is omitted", () {
105 var asset = new Asset.fromBytes(id, encodeUtf8("çøñ†éℵ™")); 120 var asset = new Asset.fromBytes(id, encodeUtf8("çøñ†éℵ™"));
106 expect(asset.readAsString(), 121 expect(asset.readAsString(),
107 completion(equals("çøñ†éℵ™"))); 122 completion(equals("çøñ†éℵ™")));
108 }); 123 });
109 124
(...skipping 20 matching lines...) Expand all
130 }); 145 });
131 }); 146 });
132 147
133 group("file asset", () { 148 group("file asset", () {
134 test("defaults to UTF-8 if encoding is omitted", () { 149 test("defaults to UTF-8 if encoding is omitted", () {
135 var asset = new Asset.fromPath(id, textFilePath); 150 var asset = new Asset.fromPath(id, textFilePath);
136 expect(asset.readAsString(), 151 expect(asset.readAsString(),
137 completion(equals("çøñ†éℵ™"))); 152 completion(equals("çøñ†éℵ™")));
138 }); 153 });
139 }); 154 });
155
156 group("stream asset", () {
157 test("defaults to UTF-8 if encoding is omitted", () {
158 var asset = new Asset.fromStream(id,
159 new Stream.fromFuture(new Future.value(encodeUtf8("çøñ†éℵ™"))));
160 expect(asset.readAsString(),
161 completion(equals("çøñ†éℵ™")));
162 });
163
164 test("supports UTF-8", () {
165 var asset = new Asset.fromStream(id,
166 new Stream.fromFuture(new Future.value(encodeUtf8("çøñ†éℵ™"))));
167 expect(asset.readAsString(encoding: UTF8),
168 completion(equals("çøñ†éℵ™")));
169 });
170
171 // TODO(nweiz): Test other encodings once #6284 is fixed.
Bob Nystrom 2013/08/27 17:20:29 Add some tests for how it handles the source strea
nweiz 2013/08/27 17:47:52 These are essentially the tests we already have fo
172 });
140 }); 173 });
141 174
142 group("toString()", () { 175 group("toString()", () {
143 group("byte asset", () { 176 group("byte asset", () {
144 test("shows the list of bytes in hex", () { 177 test("shows the list of bytes in hex", () {
145 var asset = new Asset.fromBytes(id, 178 var asset = new Asset.fromBytes(id,
146 [0, 1, 2, 4, 8, 16, 32, 64, 128, 255]); 179 [0, 1, 2, 4, 8, 16, 32, 64, 128, 255]);
147 expect(asset.toString(), equals( 180 expect(asset.toString(), equals(
148 "Bytes [00 01 02 04 08 10 20 40 80 ff]")); 181 "Bytes [00 01 02 04 08 10 20 40 80 ff]"));
149 }); 182 });
(...skipping 22 matching lines...) Expand all
172 }); 205 });
173 206
174 group("file asset", () { 207 group("file asset", () {
175 test("shows the file path", () { 208 test("shows the file path", () {
176 var asset = new Asset.fromPath(id, "path.txt"); 209 var asset = new Asset.fromPath(id, "path.txt");
177 expect(asset.toString(), equals('File "path.txt"')); 210 expect(asset.toString(), equals('File "path.txt"'));
178 }); 211 });
179 }); 212 });
180 }); 213 });
181 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698