| OLD | NEW |
| 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.request_test; | 5 library shelf.request_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'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 | 12 |
| 13 Request _request([Map<String, String> headers, Stream<List<int>> body]) { | 13 Request _request([Map<String, String> headers, Stream<List<int>> body, |
| 14 Map<String, Object> context]) { |
| 14 if (headers == null) headers = {}; | 15 if (headers == null) headers = {}; |
| 15 return new Request("/", "", "GET", "", "1.1", Uri.parse('http://localhost/'), | 16 return new Request("/", "", "GET", "", "1.1", Uri.parse('http://localhost/'), |
| 16 headers, body: body); | 17 headers, body: body, context: context); |
| 17 } | 18 } |
| 18 | 19 |
| 19 void main() { | 20 void main() { |
| 20 group("contentLength", () { | 21 group("contentLength", () { |
| 21 test("is null without a content-length header", () { | 22 test("is null without a content-length header", () { |
| 22 var request = _request(); | 23 var request = _request(); |
| 23 expect(request.contentLength, isNull); | 24 expect(request.contentLength, isNull); |
| 24 }); | 25 }); |
| 25 | 26 |
| 26 test("comes from the content-length header", () { | 27 test("comes from the content-length header", () { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 'content-type': 'text/plain; charset=fblthp' | 141 'content-type': 'text/plain; charset=fblthp' |
| 141 }).encoding, isNull); | 142 }).encoding, isNull); |
| 142 }); | 143 }); |
| 143 | 144 |
| 144 test("comes from the content-type charset parameter", () { | 145 test("comes from the content-type charset parameter", () { |
| 145 expect(_request({ | 146 expect(_request({ |
| 146 'content-type': 'text/plain; charset=iso-8859-1' | 147 'content-type': 'text/plain; charset=iso-8859-1' |
| 147 }).encoding, equals(LATIN1)); | 148 }).encoding, equals(LATIN1)); |
| 148 }); | 149 }); |
| 149 }); | 150 }); |
| 151 |
| 152 group("context", () { |
| 153 test("are correctly populated", () { |
| 154 expect(_request({ |
| 155 'content-type': 'text/plain' |
| 156 }, null, { |
| 157 'my-param' : 42 |
| 158 }).context['my-param'], equals(42)); |
| 159 }); |
| 160 }); |
| 150 } | 161 } |
| OLD | NEW |