| 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.message_test; | 5 library shelf.message_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/src/message.dart'; | 10 import 'package:shelf/src/message.dart'; | 
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; | 
| 12 | 12 | 
|  | 13 import 'test_util.dart'; | 
|  | 14 | 
| 13 class _TestMessage extends Message { | 15 class _TestMessage extends Message { | 
| 14   _TestMessage(Map<String, String> headers, Map<String, Object> context, | 16   _TestMessage(Map<String, String> headers, Map<String, Object> context, | 
| 15         Stream<List<int>> body) | 17         Stream<List<int>> body) | 
| 16       : super(body, headers: headers, context: context); | 18       : super(body, headers: headers, context: context); | 
|  | 19 | 
|  | 20   Message change({Map<String, String> headers, Map<String, Object> context}) { | 
|  | 21     throw new UnimplementedError(); | 
|  | 22   } | 
| 17 } | 23 } | 
| 18 | 24 | 
| 19 Message _createMessage({Map<String, String> headers, | 25 Message _createMessage({Map<String, String> headers, | 
| 20     Map<String, Object> context, Stream<List<int>> body}) { | 26     Map<String, Object> context, Stream<List<int>> body}) { | 
| 21   if (body == null) body = new Stream.fromIterable([]); | 27   if (body == null) body = new Stream.fromIterable([]); | 
| 22   return new _TestMessage(headers, context, body); | 28   return new _TestMessage(headers, context, body); | 
| 23 } | 29 } | 
| 24 | 30 | 
| 25 void main() { | 31 void main() { | 
| 26   group('headers', () { | 32   group('headers', () { | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 69     test("supports a null body", () { | 75     test("supports a null body", () { | 
| 70       var request = _createMessage(); | 76       var request = _createMessage(); | 
| 71       expect(request.readAsString(), completion(equals(""))); | 77       expect(request.readAsString(), completion(equals(""))); | 
| 72     }); | 78     }); | 
| 73 | 79 | 
| 74     test("supports a Stream<List<int>> body", () { | 80     test("supports a Stream<List<int>> body", () { | 
| 75       var controller = new StreamController(); | 81       var controller = new StreamController(); | 
| 76       var request = _createMessage(body: controller.stream); | 82       var request = _createMessage(body: controller.stream); | 
| 77       expect(request.readAsString(), completion(equals("hello, world"))); | 83       expect(request.readAsString(), completion(equals("hello, world"))); | 
| 78 | 84 | 
| 79       controller.add([104, 101, 108, 108, 111, 44]); | 85       controller.add(HELLO_BYTES); | 
| 80       return new Future(() { | 86       return new Future(() { | 
| 81         controller | 87         controller | 
| 82           ..add([32, 119, 111, 114, 108, 100]) | 88           ..add(WORLD_BYTES) | 
| 83           ..close(); | 89           ..close(); | 
| 84       }); | 90       }); | 
| 85     }); | 91     }); | 
| 86 | 92 | 
| 87     test("defaults to UTF-8", () { | 93     test("defaults to UTF-8", () { | 
| 88       var request = _createMessage(body: new Stream.fromIterable([[195, 168]])); | 94       var request = _createMessage(body: new Stream.fromIterable([[195, 168]])); | 
| 89       expect(request.readAsString(), completion(equals("è"))); | 95       expect(request.readAsString(), completion(equals("è"))); | 
| 90     }); | 96     }); | 
| 91 | 97 | 
| 92     test("the content-type header overrides the default", () { | 98     test("the content-type header overrides the default", () { | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 107   group("read", () { | 113   group("read", () { | 
| 108     test("supports a null body", () { | 114     test("supports a null body", () { | 
| 109       var request = _createMessage(); | 115       var request = _createMessage(); | 
| 110       expect(request.read().toList(), completion(isEmpty)); | 116       expect(request.read().toList(), completion(isEmpty)); | 
| 111     }); | 117     }); | 
| 112 | 118 | 
| 113     test("supports a Stream<List<int>> body", () { | 119     test("supports a Stream<List<int>> body", () { | 
| 114       var controller = new StreamController(); | 120       var controller = new StreamController(); | 
| 115       var request = _createMessage(body: controller.stream); | 121       var request = _createMessage(body: controller.stream); | 
| 116       expect(request.read().toList(), completion(equals([ | 122       expect(request.read().toList(), completion(equals([ | 
| 117         [104, 101, 108, 108, 111, 44], | 123         HELLO_BYTES, | 
| 118         [32, 119, 111, 114, 108, 100] | 124         WORLD_BYTES | 
| 119       ]))); | 125       ]))); | 
| 120 | 126 | 
| 121       controller.add([104, 101, 108, 108, 111, 44]); | 127       controller.add(HELLO_BYTES); | 
| 122       return new Future(() { | 128       return new Future(() { | 
| 123         controller | 129         controller | 
| 124           ..add([32, 119, 111, 114, 108, 100]) | 130           ..add(WORLD_BYTES) | 
| 125           ..close(); | 131           ..close(); | 
| 126       }); | 132       }); | 
| 127     }); | 133     }); | 
| 128   }); | 134   }); | 
| 129 | 135 | 
| 130   group("contentLength", () { | 136   group("contentLength", () { | 
| 131     test("is null without a content-length header", () { | 137     test("is null without a content-length header", () { | 
| 132       var request = _createMessage(); | 138       var request = _createMessage(); | 
| 133       expect(request.contentLength, isNull); | 139       expect(request.contentLength, isNull); | 
| 134     }); | 140     }); | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 176       }).encoding, isNull); | 182       }).encoding, isNull); | 
| 177     }); | 183     }); | 
| 178 | 184 | 
| 179     test("comes from the content-type charset parameter", () { | 185     test("comes from the content-type charset parameter", () { | 
| 180       expect(_createMessage(headers: { | 186       expect(_createMessage(headers: { | 
| 181         'content-type': 'text/plain; charset=iso-8859-1' | 187         'content-type': 'text/plain; charset=iso-8859-1' | 
| 182       }).encoding, equals(LATIN1)); | 188       }).encoding, equals(LATIN1)); | 
| 183     }); | 189     }); | 
| 184   }); | 190   }); | 
| 185 } | 191 } | 
| OLD | NEW | 
|---|