| 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:async'; | |
| 8 | |
| 9 import 'package:http/http.dart' as http; | |
| 10 import 'package:unittest/unittest.dart'; | |
| 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 test('respects the inferred encoding', () { | |
| 26 var response = new http.Response("föøbãr", 200, | |
| 27 headers: {'content-type': 'text/plain; charset=iso-8859-1'}); | |
| 28 expect(response.bodyBytes, equals( | |
| 29 [102, 246, 248, 98, 227, 114])); | |
| 30 }); | |
| 31 }); | |
| 32 | |
| 33 group('.bytes()', () { | |
| 34 test('sets body', () { | |
| 35 var response = new http.Response.bytes([104, 101, 108, 108, 111], 200); | |
| 36 expect(response.body, equals("hello")); | |
| 37 }); | |
| 38 | |
| 39 test('sets bodyBytes', () { | |
| 40 var response = new http.Response.bytes([104, 101, 108, 108, 111], 200); | |
| 41 expect(response.bodyBytes, equals([104, 101, 108, 108, 111])); | |
| 42 }); | |
| 43 | |
| 44 test('respects the inferred encoding', () { | |
| 45 var response = new http.Response.bytes([102, 246, 248, 98, 227, 114], 200, | |
| 46 headers: {'content-type': 'text/plain; charset=iso-8859-1'}); | |
| 47 expect(response.body, equals("föøbãr")); | |
| 48 }); | |
| 49 }); | |
| 50 | |
| 51 group('.fromStream()', () { | |
| 52 test('sets body', () { | |
| 53 var controller = new StreamController(sync: true); | |
| 54 var streamResponse = new http.StreamedResponse( | |
| 55 controller.stream, 200, contentLength: 13); | |
| 56 var future = http.Response.fromStream(streamResponse) | |
| 57 .then((response) => response.body); | |
| 58 expect(future, completion(equals("Hello, world!"))); | |
| 59 | |
| 60 controller.add([72, 101, 108, 108, 111, 44, 32]); | |
| 61 controller.add([119, 111, 114, 108, 100, 33]); | |
| 62 controller.close(); | |
| 63 }); | |
| 64 | |
| 65 test('sets bodyBytes', () { | |
| 66 var controller = new StreamController(sync: true); | |
| 67 var streamResponse = new http.StreamedResponse( | |
| 68 controller.stream, 200, contentLength: 5); | |
| 69 var future = http.Response.fromStream(streamResponse) | |
| 70 .then((response) => response.bodyBytes); | |
| 71 expect(future, completion(equals([104, 101, 108, 108, 111]))); | |
| 72 | |
| 73 controller.add([104, 101, 108, 108, 111]); | |
| 74 controller.close(); | |
| 75 }); | |
| 76 }); | |
| 77 } | |
| OLD | NEW |