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

Append newline to the end of dump methods #17202

Merged
merged 2 commits into from
Jul 7, 2016
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
18 changes: 16 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ function dump(io::IO, x::SimpleVector, n::Int, indent)
end
end
end
isempty(indent) && println(io)
nothing
end

Expand All @@ -1056,6 +1057,7 @@ function dump(io::IO, x::ANY, n::Int, indent)
else
!isa(x,Function) && print(io, " ", x)
end
isempty(indent) && println(io)
nothing
end

Expand Down Expand Up @@ -1093,12 +1095,21 @@ function dump(io::IO, x::Array, n::Int, indent)
end
end
end
isempty(indent) && println(io)
nothing
end
function dump(io::IO, x::Symbol, n::Int, indent)
print(io, typeof(x), " ", x)
isempty(indent) && println(io)
nothing
end
dump(io::IO, x::Symbol, n::Int, indent) = print(io, typeof(x), " ", x)

# Types
dump(io::IO, x::Union, n::Int, indent) = print(io, x)
function dump(io::IO, x::Union, n::Int, indent)
print(io, x)
isempty(indent) && println(io)
nothing
end

function dump(io::IO, x::DataType, n::Int, indent)
print(io, x)
Expand All @@ -1115,6 +1126,7 @@ function dump(io::IO, x::DataType, n::Int, indent)
end
end
end
isempty(indent) && println(io)
nothing
end

Expand Down Expand Up @@ -1158,6 +1170,8 @@ function dumptype(io::IO, x::ANY, n::Int, indent)
end
end
end
isempty(indent) && println(io)
nothing
end
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe all the dump methods should explicitly return nothing?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Yes; otherwise they return false which doesn't really make sense.


# For abstract types, use _dumptype only if it's a form that will be called
Expand Down
6 changes: 6 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,9 @@ let s = IOBuffer(Array{UInt8}(0), true, true)
Base.showarray(s, [1,2,3], false, header = false)
@test String(resize!(s.data, s.size)) == " 1\n 2\n 3"
end

# The `dump` function should alway have a trailing newline
Copy link
Contributor

Choose a reason for hiding this comment

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

always

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I'll take care of that in another PR

let io = IOBuffer()
dump(io, :(x = 1))
@test takebuf_string(io)[end] == '\n'
end