blob: d668ccc97c68b620fa0109d9ea1e8a8fee803211 [file] [log] [blame]
// Copyright (c) 2017, 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 ChunkedConversionSink<Object> startChunkedConversion(
/// Sink<String> sink
/// )
/// Starts a chunked conversion.
/// ...
/// It is an error to invoke add more than once on the returned sink.
/// @description Checks that it is an error to invoke add more than once on the
/// returned sink.
/// @author sgrekhov@unipro.ru
import "dart:convert";
import "../../../Utils/expect.dart";
check(data) {
JsonEncoder encoder = new JsonEncoder();
Sink<String> outSink = new ChunkedConversionSink.withCallback((chunks) {
Expect.equals(encoder.convert(data), chunks2string(chunks));
});
var inSink = encoder.startChunkedConversion(outSink);
inSink.add(data);
Expect.throws(() {inSink.add(data);});
Expect.throws(() {inSink.add(null);});
inSink.close();
}
String chunks2string(List<String> data) {
StringBuffer sb = new StringBuffer();
Iterator it = data.iterator;
while (it.moveNext()) {
sb.write(it.current);
}
return sb.toString();
}
main() {
check(1);
check(3.14);
check(null);
check(true);
check(false);
check('"str"');
check(["1", "2", "3.14"]);
check([[1, 2, 3], {"a": "3"}]);
check({"a": "b"});
check({"й": " ф "});
}