Skip to content

Commit

Permalink
write(::IO, ::IO) tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor committed Jan 22, 2016
1 parent 0ce7a52 commit ab32dfb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export File,
S_IROTH, S_IWOTH, S_IXOTH, S_IRWXO

import Base: uvtype, uvhandle, eventloop, fd, position, stat, close,
write, read, read!, isopen, show,
write, read, readavailable, read!, isopen, show,
seek, seekend, skip, eof,
check_open, _sizeof_uv_fs, uv_error, UVError

Expand Down Expand Up @@ -181,6 +181,7 @@ function readbytes!(f::File, b::Array{UInt8}, nb=length(b))
return ret
end
read(io::File) = read!(io, Array(UInt8, nb_available(io)))
readavailable(io::File) = read(io)
read(io::File, nb::Integer) = read!(io, Array(UInt8, min(nb, nb_available(io))))

const SEEK_SET = Int32(0)
Expand Down
1 change: 1 addition & 0 deletions base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ function readbytes!(io::AbstractIOBuffer, b::Array{UInt8}, nb=length(b))
return nr
end
read(io::AbstractIOBuffer) = read!(io, Array(UInt8, nb_available(io)))
readavailable(io::AbstractIOBuffer) = read(io)
read(io::AbstractIOBuffer, nb::Integer) = read!(io, Array(UInt8, min(nb, nb_available(io))))

function search(buf::IOBuffer, delim::UInt8)
Expand Down
2 changes: 2 additions & 0 deletions base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ end
# num bytes available without blocking
nb_available(s::IOStream) = ccall(:jl_nb_available, Int32, (Ptr{Void},), s.ios)

readavailable(s::IOStream) = read!(s, Vector{UInt8}(nb_available(s)))

function read(s::IOStream, ::Type{UInt8})
b = ccall(:ios_getc, Cint, (Ptr{Void},), s.ios)
if b == -1
Expand Down
16 changes: 16 additions & 0 deletions test/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ for (name, f) in l
@test readstring(seekend(io())) == ""
end


verbose && println("$name write(::IOStream, ...)")
to = open("$filename.to", "w")
write(to, io())
close(to)
@test readstring("$filename.to") == text
cleanup()
verbose && println("$name write(filename, ...)")
write("$filename.to", io())
@test readstring("$filename.to") == text
cleanup()

verbose && println("$name write(::IOBuffer, ...)")
to = IOBuffer(Vector{UInt8}(copy(text)), false, true)
write(to, io())
@test takebuf_string(to) == text
cleanup()
end

Expand Down

0 comments on commit ab32dfb

Please sign in to comment.