| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library response_test; |
| 6 |
| 7 import 'dart:io'; |
| 8 |
| 9 import '../../unittest/lib/unittest.dart'; |
| 10 import '../lib/http.dart' as http; |
| 11 |
| 12 void main() { |
| 13 group('()', () { |
| 14 test('sets body', () { |
| 15 var response = new http.Response("Hello, world!", 200); |
| 16 expect(response.body, equals("Hello, world!")); |
| 17 }); |
| 18 |
| 19 test('sets bodyBytes', () { |
| 20 var response = new http.Response("Hello, world!", 200); |
| 21 expect(response.bodyBytes, equals( |
| 22 [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33])); |
| 23 }); |
| 24 |
| 25 // TODO(nweiz): test that this respects the inferred encoding when issue |
| 26 // 6284 is fixed. |
| 27 }); |
| 28 |
| 29 group('.bytes()', () { |
| 30 test('sets body', () { |
| 31 var response = new http.Response.bytes([104, 101, 108, 108, 111], 200); |
| 32 expect(response.body, equals("hello")); |
| 33 }); |
| 34 |
| 35 test('sets bodyBytes', () { |
| 36 var response = new http.Response.bytes([104, 101, 108, 108, 111], 200); |
| 37 expect(response.bodyBytes, equals([104, 101, 108, 108, 111])); |
| 38 }); |
| 39 |
| 40 // TODO(nweiz): test that this respects the inferred encoding when issue |
| 41 // 6284 is fixed. |
| 42 }); |
| 43 |
| 44 group('.fromStream()', () { |
| 45 test('sets body', () { |
| 46 var stream = new ListInputStream(); |
| 47 var streamResponse = new http.StreamedResponse(stream, 200, 13); |
| 48 var future = http.Response.fromStream(streamResponse) |
| 49 .transform((response) => response.body); |
| 50 expect(future, completion(equals("Hello, world!"))); |
| 51 |
| 52 stream.write([72, 101, 108, 108, 111, 44, 32]); |
| 53 stream.write([119, 111, 114, 108, 100, 33]); |
| 54 stream.markEndOfStream(); |
| 55 }); |
| 56 |
| 57 test('sets bodyBytes', () { |
| 58 var stream = new ListInputStream(); |
| 59 var streamResponse = new http.StreamedResponse(stream, 200, 5); |
| 60 var future = http.Response.fromStream(streamResponse) |
| 61 .transform((response) => response.bodyBytes); |
| 62 expect(future, completion(equals([104, 101, 108, 108, 111]))); |
| 63 |
| 64 stream.write([104, 101, 108, 108, 111]); |
| 65 stream.markEndOfStream(); |
| 66 }); |
| 67 }); |
| 68 } |
| OLD | NEW |