blob: b50585ea7cdcb9304e1fde2154206d5e78b3535d [file] [log] [blame]
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion void writeAll(
/// Iterable objects, [
/// String separator = ""
/// ])
/// Iterates over the given objects and writes them in sequence.
///
/// If separator is provided, a write with the separator is performed between any
/// two elements of objects`.
///
/// This operation is non-blocking. See flush or done for how to get any errors
/// generated by this call.
/// @description Checks that this method iterates over the given objects and
/// writes them in sequence. Test objects that are not strings
/// @author sgrekhov@unipro.ru
import "dart:io";
import "../../../Utils/expect.dart";
var localhost = InternetAddress.loopbackIPv4.address;
class C {
String toString() {
return "This is C";
}
}
test(String method) async {
asyncStart();
Iterable objects = [1, "2", 3.14, new C(), null];
HttpServer server = await HttpServer.bind(localhost, 0);
server.listen((HttpRequest request) {
request.toList().then((List<List<int>> l) {
Expect.listEquals(["1", "2", "3.14", "This is C", "null"],
[new String.fromCharCodes(l[0]), new String.fromCharCodes(l[1]),
new String.fromCharCodes(l[2]), new String.fromCharCodes(l[3]),
new String.fromCharCodes(l[4])]);
request.response.close();
server.close();
asyncEnd();
});
});
HttpClient client = new HttpClient();
client.open(method, localhost, server.port, "")
.then((HttpClientRequest request) {
request.contentLength = -1;
request.writeAll(objects);
return request.close();
});
}
main() {
test("get");
test("head");
test("delete");
test("put");
test("post");
test("patch");
}