Skip to content

Commit

Permalink
nfc: replace IOBuffer with `PipeBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Aug 30, 2022
1 parent 1cf999e commit 6f09c82
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions test/backend/libsixel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
println()
end

io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, img, enc)
bufferdata = String(take!(io))
bufferdata = read(io, String)
h, w = size(img, 1), 1
@test startswith(bufferdata, "\ePq\"1;1;$w;$h") && endswith(bufferdata, "\e\\")
test_sixel_display() do
Expand Down Expand Up @@ -73,9 +73,9 @@
sixel_encode(img, enc)
println()
end
io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, img, enc)
bufferdata = String(take!(io))
bufferdata = read(io, String)
@test startswith(bufferdata, "\ePq\"1;1;$w;$h") && endswith(bufferdata, "\e\\")
test_sixel_display() do
println(bufferdata)
Expand Down Expand Up @@ -115,9 +115,9 @@
sixel_encode(img, enc)
println()
end
io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, img, enc)
bufferdata = String(take!(io))
bufferdata = read(io, String)
h, w, c = size(img)
w = w * c
@test startswith(bufferdata, "\ePq\"1;1;$w;$h") && endswith(bufferdata, "\e\\")
Expand All @@ -144,9 +144,9 @@
sixel_encode(img, enc; transpose=true)
end

io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, img, enc; transpose=true)
bufferdata = String(take!(io))
bufferdata = read(io, String)
h, w, c = size(img)
h = h * c
h, w = w, h # transpose
Expand Down Expand Up @@ -183,9 +183,9 @@
# lazy array that does not occupy full memory
img = Diagonal(repeat(distinguishable_colors(5), inner=20))
w, h = size(img)
io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, img)
bufferdata = String(take!(io))
bufferdata = read(io, String)
@test startswith(bufferdata, "\ePq\"1;1;$w;$h") && endswith(bufferdata, "\e\\")
@info "Test Diagonal array"
test_sixel_display() do
Expand All @@ -199,23 +199,23 @@
@test stride(img, 1) == 50
@test stride(ori_img, 1) == 1

io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, ori_img)
bufferdata = String(take!(io))
bufferdata = read(io, String)
h, w = size(ori_img)
@test startswith(bufferdata, "\ePq\"1;1;$w;$h") && endswith(bufferdata, "\e\\")
io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, img)
@test bufferdata == String(take!(io))
@test bufferdata == read(io, String)

io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, ori_img, transpose=false)
bufferdata = String(take!(io))
bufferdata = read(io, String)
h, w = size(ori_img)
@test startswith(bufferdata, "\ePq\"1;1;$w;$h") && endswith(bufferdata, "\e\\")
io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, img, transpose=false)
@test bufferdata == String(take!(io))
@test bufferdata == read(io, String)
end

@testset "OffsetArray" begin
Expand All @@ -225,14 +225,14 @@
repeat(distinguishable_colors(10), inner=(10, 50)),
repeat(distinguishable_colors(5), inner=(20, 50, 3))
)
io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, img, enc)
ref = String(take!(io))
ref = read(io, String)

imgo = OffsetArray(img, OffsetArrays.Origin(0))
io = IOBuffer()
io = PipeBuffer()
sixel_encode(io, imgo, enc)
actual = String(take!(io))
actual = read(io, String)
@test ref == actual
end
end
Expand Down

0 comments on commit 6f09c82

Please sign in to comment.