OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 response_test; | 5 library response_test; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 import 'package:http/http.dart' as http; | 10 import 'package:http/http.dart' as http; |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 // TODO(nweiz): test that this respects the inferred encoding when issue | 40 // TODO(nweiz): test that this respects the inferred encoding when issue |
41 // 6284 is fixed. | 41 // 6284 is fixed. |
42 }); | 42 }); |
43 | 43 |
44 group('.fromStream()', () { | 44 group('.fromStream()', () { |
45 test('sets body', () { | 45 test('sets body', () { |
46 var stream = new ListInputStream(); | 46 var stream = new ListInputStream(); |
47 var streamResponse = new http.StreamedResponse(stream, 200, 13); | 47 var streamResponse = new http.StreamedResponse(stream, 200, 13); |
48 var future = http.Response.fromStream(streamResponse) | 48 var future = http.Response.fromStream(streamResponse) |
49 .transform((response) => response.body); | 49 .then((response) => response.body); |
50 expect(future, completion(equals("Hello, world!"))); | 50 expect(future, completion(equals("Hello, world!"))); |
51 | 51 |
52 stream.write([72, 101, 108, 108, 111, 44, 32]); | 52 stream.write([72, 101, 108, 108, 111, 44, 32]); |
53 stream.write([119, 111, 114, 108, 100, 33]); | 53 stream.write([119, 111, 114, 108, 100, 33]); |
54 stream.markEndOfStream(); | 54 stream.markEndOfStream(); |
55 }); | 55 }); |
56 | 56 |
57 test('sets bodyBytes', () { | 57 test('sets bodyBytes', () { |
58 var stream = new ListInputStream(); | 58 var stream = new ListInputStream(); |
59 var streamResponse = new http.StreamedResponse(stream, 200, 5); | 59 var streamResponse = new http.StreamedResponse(stream, 200, 5); |
60 var future = http.Response.fromStream(streamResponse) | 60 var future = http.Response.fromStream(streamResponse) |
61 .transform((response) => response.bodyBytes); | 61 .then((response) => response.bodyBytes); |
62 expect(future, completion(equals([104, 101, 108, 108, 111]))); | 62 expect(future, completion(equals([104, 101, 108, 108, 111]))); |
63 | 63 |
64 stream.write([104, 101, 108, 108, 111]); | 64 stream.write([104, 101, 108, 108, 111]); |
65 stream.markEndOfStream(); | 65 stream.markEndOfStream(); |
66 }); | 66 }); |
67 }); | 67 }); |
68 } | 68 } |
OLD | NEW |