| 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'; |   13 import 'test_util.dart'; | 
|   14  |   14  | 
|   15 class _TestMessage extends Message { |   15 class _TestMessage extends Message { | 
|   16   _TestMessage(Map<String, String> headers, Map<String, Object> context, |   16   _TestMessage(Map<String, String> headers, Map<String, Object> context, | 
|   17         Stream<List<int>> body) |   17       Stream<List<int>> body) : super(body, headers: headers, context: context); | 
|   18       : super(body, headers: headers, context: context); |  | 
|   19  |   18  | 
|   20   Message change({Map<String, String> headers, Map<String, Object> context}) { |   19   Message change({Map<String, String> headers, Map<String, Object> context}) { | 
|   21     throw new UnimplementedError(); |   20     throw new UnimplementedError(); | 
|   22   } |   21   } | 
|   23 } |   22 } | 
|   24  |   23  | 
|   25 Message _createMessage({Map<String, String> headers, |   24 Message _createMessage({Map<String, String> headers, | 
|   26     Map<String, Object> context, Stream<List<int>> body}) { |   25     Map<String, Object> context, Stream<List<int>> body}) { | 
|   27   if (body == null) body = new Stream.fromIterable([]); |   26   if (body == null) body = new Stream.fromIterable([]); | 
|   28   return new _TestMessage(headers, context, body); |   27   return new _TestMessage(headers, context, body); | 
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  112  |  111  | 
|  113   group("read", () { |  112   group("read", () { | 
|  114     test("supports a null body", () { |  113     test("supports a null body", () { | 
|  115       var request = _createMessage(); |  114       var request = _createMessage(); | 
|  116       expect(request.read().toList(), completion(isEmpty)); |  115       expect(request.read().toList(), completion(isEmpty)); | 
|  117     }); |  116     }); | 
|  118  |  117  | 
|  119     test("supports a Stream<List<int>> body", () { |  118     test("supports a Stream<List<int>> body", () { | 
|  120       var controller = new StreamController(); |  119       var controller = new StreamController(); | 
|  121       var request = _createMessage(body: controller.stream); |  120       var request = _createMessage(body: controller.stream); | 
|  122       expect(request.read().toList(), completion(equals([ |  121       expect(request.read().toList(), | 
|  123         HELLO_BYTES, |  122           completion(equals([HELLO_BYTES, WORLD_BYTES]))); | 
|  124         WORLD_BYTES |  | 
|  125       ]))); |  | 
|  126  |  123  | 
|  127       controller.add(HELLO_BYTES); |  124       controller.add(HELLO_BYTES); | 
|  128       return new Future(() { |  125       return new Future(() { | 
|  129         controller |  126         controller | 
|  130           ..add(WORLD_BYTES) |  127           ..add(WORLD_BYTES) | 
|  131           ..close(); |  128           ..close(); | 
|  132       }); |  129       }); | 
|  133     }); |  130     }); | 
|  134  |  131  | 
|  135     test("throws when calling read()/readAsString() multiple times", () { |  132     test("throws when calling read()/readAsString() multiple times", () { | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
|  153     }); |  150     }); | 
|  154   }); |  151   }); | 
|  155  |  152  | 
|  156   group("contentLength", () { |  153   group("contentLength", () { | 
|  157     test("is null without a content-length header", () { |  154     test("is null without a content-length header", () { | 
|  158       var request = _createMessage(); |  155       var request = _createMessage(); | 
|  159       expect(request.contentLength, isNull); |  156       expect(request.contentLength, isNull); | 
|  160     }); |  157     }); | 
|  161  |  158  | 
|  162     test("comes from the content-length header", () { |  159     test("comes from the content-length header", () { | 
|  163       var request = _createMessage(headers: { |  160       var request = _createMessage(headers: {'content-length': '42'}); | 
|  164         'content-length': '42' |  | 
|  165       }); |  | 
|  166       expect(request.contentLength, 42); |  161       expect(request.contentLength, 42); | 
|  167     }); |  162     }); | 
|  168   }); |  163   }); | 
|  169  |  164  | 
|  170   group("mimeType", () { |  165   group("mimeType", () { | 
|  171     test("is null without a content-type header", () { |  166     test("is null without a content-type header", () { | 
|  172       expect(_createMessage().mimeType, isNull); |  167       expect(_createMessage().mimeType, isNull); | 
|  173     }); |  168     }); | 
|  174  |  169  | 
|  175     test("comes from the content-type header", () { |  170     test("comes from the content-type header", () { | 
|  176       expect(_createMessage(headers: { |  171       expect(_createMessage(headers: {'content-type': 'text/plain'}).mimeType, | 
|  177         'content-type': 'text/plain' |  172           equals('text/plain')); | 
|  178       }).mimeType, equals('text/plain')); |  | 
|  179     }); |  173     }); | 
|  180  |  174  | 
|  181     test("doesn't include parameters", () { |  175     test("doesn't include parameters", () { | 
|  182       expect(_createMessage(headers: { |  176       expect(_createMessage( | 
 |  177           headers: { | 
|  183         'content-type': 'text/plain; foo=bar; bar=baz' |  178         'content-type': 'text/plain; foo=bar; bar=baz' | 
|  184       }).mimeType, equals('text/plain')); |  179       }).mimeType, equals('text/plain')); | 
|  185     }); |  180     }); | 
|  186   }); |  181   }); | 
|  187  |  182  | 
|  188   group("encoding", () { |  183   group("encoding", () { | 
|  189     test("is null without a content-type header", () { |  184     test("is null without a content-type header", () { | 
|  190       expect(_createMessage().encoding, isNull); |  185       expect(_createMessage().encoding, isNull); | 
|  191     }); |  186     }); | 
|  192  |  187  | 
|  193     test("is null without a charset parameter", () { |  188     test("is null without a charset parameter", () { | 
|  194       expect(_createMessage(headers: { |  189       expect(_createMessage(headers: {'content-type': 'text/plain'}).encoding, | 
|  195         'content-type': 'text/plain' |  190           isNull); | 
|  196       }).encoding, isNull); |  | 
|  197     }); |  191     }); | 
|  198  |  192  | 
|  199     test("is null with an unrecognized charset parameter", () { |  193     test("is null with an unrecognized charset parameter", () { | 
|  200       expect(_createMessage(headers: { |  194       expect(_createMessage( | 
|  201         'content-type': 'text/plain; charset=fblthp' |  195               headers: {'content-type': 'text/plain; charset=fblthp'}).encoding, | 
|  202       }).encoding, isNull); |  196           isNull); | 
|  203     }); |  197     }); | 
|  204  |  198  | 
|  205     test("comes from the content-type charset parameter", () { |  199     test("comes from the content-type charset parameter", () { | 
|  206       expect(_createMessage(headers: { |  200       expect(_createMessage( | 
 |  201           headers: { | 
|  207         'content-type': 'text/plain; charset=iso-8859-1' |  202         'content-type': 'text/plain; charset=iso-8859-1' | 
|  208       }).encoding, equals(LATIN1)); |  203       }).encoding, equals(LATIN1)); | 
|  209     }); |  204     }); | 
|  210   }); |  205   }); | 
|  211 } |  206 } | 
| OLD | NEW |