Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow customizable RenderMode for txt #19

Merged
merged 1 commit into from
Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/handlers.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# --------------------------------------------------------------------
# plain TXT

function test_reference(file::File{format"TXT"}, actual)
_test_reference(Diff(), file, string(actual))
function test_reference(file::File{format"TXT"}, actual; render = Diff())
_test_reference(render, file, string(actual))
end

function test_reference(file::File{format"TXT"}, actual::AbstractArray{<:AbstractString})
function test_reference(file::File{format"TXT"}, actual::AbstractArray{<:AbstractString}; render = Diff())
str = join(actual, '\n')
_test_reference(Diff(), file, str)
_test_reference(render, file, str)
end

# ---------------------------------
Expand All @@ -29,10 +29,10 @@ function test_reference(file::File, actual::AbstractArray{<:Colorant}; sigma=one
end

# Image as txt using ImageInTerminal
function test_reference(file::File{format"TXT"}, actual::AbstractArray{<:Colorant}; size = (20,40))
function test_reference(file::File{format"TXT"}, actual::AbstractArray{<:Colorant}; size = (20,40), render = BeforeAfterFull())
strs = @withcolor ImageInTerminal.encodeimg(ImageInTerminal.SmallBlocks(), ImageInTerminal.TermColor256(), actual, size...)[1]
str = join(strs,'\n')
_test_reference(BeforeAfterFull(), file, str)
_test_reference(render, file, str)
end

# --------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end
io2str_impl(arg) = :(throw(ArgumentError("Invalid use of `@io2str` macro: The given argument `$($(string(arg)))` is not an expression.")))

function io2str_impl(expr::Expr)
nvar = Symbol("#io#", randstring(4))
nvar = gensym("io")
if replace_expr!(expr, :(::IO), nvar)
esc(quote
$nvar = Base.IOBuffer()
Expand Down
1 change: 1 addition & 0 deletions test/references/ansii.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this should be blue
15 changes: 14 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if isinteractive()
@info ("In interactive use, one should respond \"n\" when the program"
* " offers to create or replace files associated with some tests.")
else
@info ("Four tests should correctly report failure in the transcript"
@info ("Eight tests should correctly report failure in the transcript"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you count to get to "four" ? if I count all the "complaints" about failing test or non-existing files i got to "seven" before the additional one in this PR. (thought its quite hard to count because the visual separation isn't too great)

* " (but not the test summary).")
end
# check for ambiguities
Expand Down Expand Up @@ -77,6 +77,19 @@ end
@test_reference "references/lena.txt" lena
end

@testset "plain ansi string" begin
@test_reference(
"references/ansii.txt",
@io2str(printstyled(IOContext(::IO, :color=>true), "this should be blue", color=:blue)),
render = ReferenceTests.BeforeAfterFull()
)
@test_throws ErrorException @test_reference(
"references/ansii.txt",
@io2str(printstyled(IOContext(::IO, :color=>true), "this should be red", color=:red)),
render = ReferenceTests.BeforeAfterFull()
)
end

@testset "string as SHA" begin
@test_reference "references/number1.sha256" 1337
foo = "foo"
Expand Down