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

Side by Side Diff: pkg/shelf/test/response_test.dart

Issue 227563010: pkg/shelf: case-insensitive headers, cleaner Request ctor, a lot more tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixing dependent code, changelog Created 6 years, 8 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
« no previous file with comments | « pkg/shelf/test/request_test.dart ('k') | pkg/shelf/test/shelf_io_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
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 shelf.response_test; 5 library shelf.response_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:shelf/shelf.dart'; 10 import 'package:shelf/shelf.dart';
(...skipping 16 matching lines...) Expand all
27 var response = new Response.ok(controller.stream); 27 var response = new Response.ok(controller.stream);
28 expect(response.readAsString(), completion(equals("hello, world"))); 28 expect(response.readAsString(), completion(equals("hello, world")));
29 29
30 controller.add([104, 101, 108, 108, 111, 44]); 30 controller.add([104, 101, 108, 108, 111, 44]);
31 return new Future(() { 31 return new Future(() {
32 controller 32 controller
33 ..add([32, 119, 111, 114, 108, 100]) 33 ..add([32, 119, 111, 114, 108, 100])
34 ..close(); 34 ..close();
35 }); 35 });
36 }); 36 });
37
38 test("defaults to UTF-8", () {
39 var response = new Response.ok(
40 new Stream.fromIterable([[195, 168]]));
41 expect(response.readAsString(), completion(equals("è")));
42 });
43
44 test("the content-type header overrides the default", () {
45 var response = new Response.ok(
46 new Stream.fromIterable([[195, 168]]),
47 headers: {'content-type': 'text/plain; charset=iso-8859-1'});
48 expect(response.readAsString(), completion(equals("è")));
49 });
50
51 test("an explicit encoding overrides the content-type header", () {
52 var response = new Response.ok(
53 new Stream.fromIterable([[195, 168]]),
54 headers: {'content-type': 'text/plain; charset=utf-8'});
55 expect(response.readAsString(LATIN1), completion(equals("è")));
56 });
57 }); 37 });
58 38
59 group("read", () { 39 group("read", () {
60 test("supports a null body", () { 40 test("supports a null body", () {
61 var response = new Response(200); 41 var response = new Response(200);
62 expect(response.read().toList(), completion(isEmpty)); 42 expect(response.read().toList(), completion(isEmpty));
63 }); 43 });
64 44
65 test("supports a String body", () { 45 test("supports a String body", () {
66 var response = new Response.ok("hello, world"); 46 var response = new Response.ok("hello, world");
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 var response = new Response.found('/foo'); 127 var response = new Response.found('/foo');
148 expect(response.headers, containsPair('location', '/foo')); 128 expect(response.headers, containsPair('location', '/foo'));
149 }); 129 });
150 130
151 test("sets the location header for a Uri", () { 131 test("sets the location header for a Uri", () {
152 var response = new Response.found(new Uri(path: '/foo')); 132 var response = new Response.found(new Uri(path: '/foo'));
153 expect(response.headers, containsPair('location', '/foo')); 133 expect(response.headers, containsPair('location', '/foo'));
154 }); 134 });
155 }); 135 });
156 136
157 group("mimeType", () {
158 test("is null without a content-type header", () {
159 expect(new Response.ok("okay!").mimeType, isNull);
160 });
161
162 test("comes from the content-type header", () {
163 expect(new Response.ok("okay!", headers: {
164 'content-type': 'text/plain'
165 }).mimeType, equals('text/plain'));
166 });
167
168 test("doesn't include parameters", () {
169 expect(new Response.ok("okay!", headers: {
170 'content-type': 'text/plain; foo=bar; bar=baz'
171 }).mimeType, equals('text/plain'));
172 });
173 });
174
175 group("encoding", () {
176 test("is null without a content-type header", () {
177 expect(new Response.ok("okay!").encoding, isNull);
178 });
179
180 test("is null without a charset parameter", () {
181 expect(new Response.ok("okay!", headers: {
182 'content-type': 'text/plain'
183 }).encoding, isNull);
184 });
185
186 test("is null with an unrecognized charset parameter", () {
187 expect(new Response.ok("okay!", headers: {
188 'content-type': 'text/plain; charset=fblthp'
189 }).encoding, isNull);
190 });
191
192 test("comes from the content-type charset parameter", () {
193 expect(new Response.ok("okay!", headers: {
194 'content-type': 'text/plain; charset=iso-8859-1'
195 }).encoding, equals(LATIN1));
196 });
197 });
198
199 group("expires", () { 137 group("expires", () {
200 test("is null without an Expires header", () { 138 test("is null without an Expires header", () {
201 expect(new Response.ok("okay!").expires, isNull); 139 expect(new Response.ok("okay!").expires, isNull);
202 }); 140 });
203 141
204 test("comes from the Expires header", () { 142 test("comes from the Expires header", () {
205 expect(new Response.ok("okay!", headers: { 143 expect(new Response.ok("okay!", headers: {
206 'expires': 'Sun, 06 Nov 1994 08:49:37 GMT' 144 'expires': 'Sun, 06 Nov 1994 08:49:37 GMT'
207 }).expires, equals(DateTime.parse("1994-11-06 08:49:37z"))); 145 }).expires, equals(DateTime.parse("1994-11-06 08:49:37z")));
208 }); 146 });
209 }); 147 });
210 148
211 group("lastModified", () { 149 group("lastModified", () {
212 test("is null without a Last-Modified header", () { 150 test("is null without a Last-Modified header", () {
213 expect(new Response.ok("okay!").lastModified, isNull); 151 expect(new Response.ok("okay!").lastModified, isNull);
214 }); 152 });
215 153
216 test("comes from the Last-Modified header", () { 154 test("comes from the Last-Modified header", () {
217 expect(new Response.ok("okay!", headers: { 155 expect(new Response.ok("okay!", headers: {
218 'last-modified': 'Sun, 06 Nov 1994 08:49:37 GMT' 156 'last-modified': 'Sun, 06 Nov 1994 08:49:37 GMT'
219 }).lastModified, equals(DateTime.parse("1994-11-06 08:49:37z"))); 157 }).lastModified, equals(DateTime.parse("1994-11-06 08:49:37z")));
220 }); 158 });
221 }); 159 });
222
223 group("contentLength", () {
224 test("is null without a content-length header", () {
225 expect(new Response.ok("okay!").contentLength, isNull);
226 });
227
228 test("comes from the content-length header", () {
229 expect(new Response.ok("okay!", headers: {
230 'content-length': '42'
231 }).contentLength, equals(42));
232 });
233 });
234 } 160 }
OLDNEW
« no previous file with comments | « pkg/shelf/test/request_test.dart ('k') | pkg/shelf/test/shelf_io_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698