io: make new_multi_writer use varargs (#10062)

pull/10067/head
Leigh McCulloch 2021-05-08 23:21:08 -07:00 committed by GitHub
parent 6a54f3a84d
commit 26652c8a23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -6,7 +6,7 @@ module io
// full length an error is returned and writing to other writers stops, and if // full length an error is returned and writing to other writers stops, and if
// any writer returns an error the error is returned immediately and writing to // any writer returns an error the error is returned immediately and writing to
// other writers stops. // other writers stops.
pub fn new_multi_writer(writers []Writer) Writer { pub fn new_multi_writer(writers ...Writer) Writer {
return &MultiWriter{ return &MultiWriter{
writers: writers writers: writers
} }

View File

@ -3,7 +3,7 @@ module io
fn test_multi_writer_write_successful() { fn test_multi_writer_write_successful() {
w0 := TestWriter{} w0 := TestWriter{}
w1 := TestWriter{} w1 := TestWriter{}
mw := new_multi_writer([w0, w1]) mw := new_multi_writer(w0, w1)
n := mw.write('0123456789'.bytes()) or { n := mw.write('0123456789'.bytes()) or {
assert false assert false
return return
@ -16,7 +16,7 @@ fn test_multi_writer_write_successful() {
fn test_multi_writer_write_incomplete() { fn test_multi_writer_write_incomplete() {
w0 := TestWriter{} w0 := TestWriter{}
w1 := TestIncompleteWriter{} w1 := TestIncompleteWriter{}
mw := new_multi_writer([w0, w1]) mw := new_multi_writer(w0, w1)
n := mw.write('0123456789'.bytes()) or { n := mw.write('0123456789'.bytes()) or {
assert w0.bytes == '0123456789'.bytes() assert w0.bytes == '0123456789'.bytes()
assert w1.bytes == '012345678'.bytes() assert w1.bytes == '012345678'.bytes()
@ -29,7 +29,7 @@ fn test_multi_writer_write_error() {
w0 := TestWriter{} w0 := TestWriter{}
w1 := TestErrorWriter{} w1 := TestErrorWriter{}
w2 := TestWriter{} w2 := TestWriter{}
mw := new_multi_writer([w0, w1, w2]) mw := new_multi_writer(w0, w1, w2)
n := mw.write('0123456789'.bytes()) or { n := mw.write('0123456789'.bytes()) or {
assert w0.bytes == '0123456789'.bytes() assert w0.bytes == '0123456789'.bytes()
assert w2.bytes == [] assert w2.bytes == []