Skip to content

Commit

Permalink
more tests for readall and readbytes
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor committed Jan 19, 2016
1 parent 7f5646c commit 0032cd6
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions test/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ close(s)
push!(l, ("IOBuffer", io))


# TCPSocket
# FIXME
# The following should work on windows.
# Windows dev environment and expertise is required to get them working.

@windows ? nothing : begin

# PR#14627
Base.connect!(sock::TCPSocket, addr::Base.InetAddr) = Base.connect!(sock, addr.host, addr.port)
# TCPSocket

addr = Base.InetAddr(ip"127.0.0.1", 4444)
io = (text) -> begin
Expand All @@ -70,8 +73,6 @@ close(s)
push!(l, ("TCPSocket", io))


@windows ? nothing : begin

# PipeEndpoint
socketname = joinpath(dir, "socket")
io = (text)-> begin
Expand Down Expand Up @@ -121,13 +122,7 @@ for (name, f) in l

io = ()->(s=f(text); push!(open_streams, s); s)

verbose && println("$name readall...")
@test readall(io()) == text
@test readall(io()) == readall(filename)

verbose && println("$name read...")
@test readbytes(io()) == Vector{UInt8}(text)
@test readbytes(io()) == open(readbytes,filename)
@test read(io(), UInt8) == read(IOBuffer(text), UInt8)
@test read(io(), UInt8) == open(io->read(io, UInt8), filename)
@test read(io(), Int) == read(IOBuffer(text), Int)
Expand All @@ -145,11 +140,6 @@ for (name, f) in l
close(s1)
close(s2)

verbose && println("$name readuntil...")
@test readuntil(io(), '\n') == open(io->readuntil(io,'\n'),filename)
@test readuntil(io(), "\n") == open(io->readuntil(io,"\n"),filename)
@test readuntil(io(), ',') == open(io->readuntil(io,','),filename)

verbose && println("$name eof...")
n = length(text) - 1
@test read!(io(), Vector{UInt8}(n)) ==
Expand All @@ -174,6 +164,12 @@ for (name, f) in l
UTF8String(['A' + i % 52 for i in 1:(7 + Base.SZ_UNBUFFERED_IO *3)])
]

verbose && println("$name readall...")
@test readall(io()) == text

verbose && println("$name readbytes...")
@test readbytes(io()) == Vector{UInt8}(text)

verbose && println("$name readbytes!...")
l = length(text)
for n = [1, 2, l-2, l-1, l, l+1, l+2]
Expand Down Expand Up @@ -202,6 +198,11 @@ for (name, f) in l

cleanup()

verbose && println("$name readuntil...")
@test readuntil(io(), '\n') == readuntil(IOBuffer(text),'\n')
@test readuntil(io(), "\n") == readuntil(IOBuffer(text),"\n")
@test readuntil(io(), ',') == readuntil(IOBuffer(text),',')

verbose && println("$name readline...")
@test readline(io()) == readline(IOBuffer(text))

Expand Down

0 comments on commit 0032cd6

Please sign in to comment.