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

Unified Diff: test/message_test.dart

Issue 851423003: Request now has the same body model as Response (Closed) Base URL: https://github.com/dart-lang/shelf.git@master
Patch Set: nits Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pubspec.yaml ('k') | test/request_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/message_test.dart
diff --git a/test/message_test.dart b/test/message_test.dart
index 669d9ffc1cbddd76378c633b2c66837c23467ab7..2ce557595ffee56089a9cdf72ff8f7bee5174c8f 100644
--- a/test/message_test.dart
+++ b/test/message_test.dart
@@ -13,8 +13,9 @@ import 'package:unittest/unittest.dart';
import 'test_util.dart';
class _TestMessage extends Message {
- _TestMessage(Map<String, String> headers, Map<String, Object> context,
- Stream<List<int>> body) : super(body, headers: headers, context: context);
+ _TestMessage(Map<String, String> headers, Map<String, Object> context, body,
+ Encoding encoding)
+ : super(body, headers: headers, context: context, encoding: encoding);
Message change({Map<String, String> headers, Map<String, Object> context}) {
throw new UnimplementedError();
@@ -22,9 +23,8 @@ class _TestMessage extends Message {
}
Message _createMessage({Map<String, String> headers,
- Map<String, Object> context, Stream<List<int>> body}) {
- if (body == null) body = new Stream.fromIterable([]);
- return new _TestMessage(headers, context, body);
+ Map<String, Object> context, body, Encoding encoding}) {
+ return new _TestMessage(headers, context, body, encoding);
}
void main() {
@@ -202,5 +202,38 @@ void main() {
'content-type': 'text/plain; charset=iso-8859-1'
}).encoding, equals(LATIN1));
});
+
+ test("defaults to encoding a String as UTF-8", () {
+ expect(_createMessage(body: "è").read().toList(),
+ completion(equals([[195, 168]])));
+ });
+
+ test("uses the explicit encoding if available", () {
+ expect(_createMessage(body: "è", encoding: LATIN1).read().toList(),
+ completion(equals([[232]])));
+ });
+
+ test("adds an explicit encoding to the content-type", () {
+ var request = _createMessage(
+ body: "è", encoding: LATIN1, headers: {'content-type': 'text/plain'});
+ expect(request.headers,
+ containsPair('content-type', 'text/plain; charset=iso-8859-1'));
+ });
+
+ test("sets an absent content-type to application/octet-stream in order to "
+ "set the charset", () {
+ var request = _createMessage(body: "è", encoding: LATIN1);
+ expect(request.headers, containsPair(
+ 'content-type', 'application/octet-stream; charset=iso-8859-1'));
+ });
+
+ test("overwrites an existing charset if given an explicit encoding", () {
+ var request = _createMessage(
+ body: "è",
+ encoding: LATIN1,
+ headers: {'content-type': 'text/plain; charset=whatever'});
+ expect(request.headers,
+ containsPair('content-type', 'text/plain; charset=iso-8859-1'));
+ });
});
}
« no previous file with comments | « pubspec.yaml ('k') | test/request_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698