Skip to content

Commit dda3fc2

Browse files
committed
Improve buffer tests.
1 parent 500b802 commit dda3fc2

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/buffer.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ end
7272
#=
7373
NOTE: We need to define multiple methods because of ambiguity error with base IO methods.
7474
=#
75-
function Base.write(buffer::FileBuffer, x::Union{UInt8, Vector{UInt8}})
75+
function Base.write(buffer::FileBuffer, x::Vector{UInt8})
7676
iswritable(buffer) || throw(ArgumentError("write failed, FileBuffer is not writeable"))
7777
write(buffer.io, x)
7878
end
@@ -82,6 +82,11 @@ function Base.write(buffer::FileBuffer, x::String)
8282
write(buffer.io, x)
8383
end
8484

85+
function Base.write(buffer::FileBuffer, x::UInt8)
86+
iswritable(buffer) || throw(ArgumentError("write failed, FileBuffer is not writeable"))
87+
write(buffer.io, x)
88+
end
89+
8590
function Base.flush(buffer::FileBuffer)
8691
if iswritable(buffer)
8792
seekstart(buffer)

test/buffer.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ using FilePathsBase: FileBuffer
1414
@test !eof(io)
1515
@test read(p, String) == read(io, String)
1616
@test eof(io)
17-
seekstart(io)
17+
finally
18+
close(io)
19+
end
20+
21+
io = FileBuffer(p)
22+
try
1823
for b in read(p)
1924
@test read(io, UInt8) == b
2025
end
@@ -50,6 +55,23 @@ using FilePathsBase: FileBuffer
5055
finally
5156
close(io)
5257
end
58+
59+
rm(p2)
60+
61+
io = FileBuffer(p2; read=true,write=true)
62+
try
63+
write(io, read(p1))
64+
flush(io)
65+
66+
seekstart(io)
67+
for b in read(p1)
68+
write(io, b)
69+
end
70+
flush(io)
71+
@test read(p1) == read(p2)
72+
finally
73+
close(io)
74+
end
5375
end
5476
end
5577
end

test/system.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ ps = PathSet(; symlink=true)
384384
@test ispath("cpstr")
385385

386386
# Recursive directory
387-
@show docsdir
388387
@test cp(docsdir, p"cpdstpath"; force=true) == p"cpdstpath"
389388
@test ispath(p"cpdstpath")
390389
@test ispath(p"cpdstpath/src/api.md")

0 commit comments

Comments
 (0)