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

Fix newlines around nested dicts #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,19 @@ function print_table(f::MbyFunc, io::IO, a::AbstractDict,
value = to_toml_value(f, value)
end
if is_table(value)
# print table
first_block || println(io)
first_block = false
push!(ks, String(key))
header = isempty(value) || !all(is_tabular(v) for v in values(value))::Bool
if header
# print table
first_block || println(io)
first_block = false
Base.print(io, ' '^4indent)
Base.print(io,"[")
printkey(io, ks)
Base.print(io,"]\n")
end
# Use runtime dispatch here since the type of value seems not to be enforced other than as AbstractDict
Base.invokelatest(print_table, f, io, value, ks; indent = indent + header, first_block = header, sorted=sorted, by=by)
Base.invokelatest(print_table, f, io, value, ks; indent = indent + header, first_block = true, sorted=sorted, by=by)
pop!(ks)
elseif is_array_of_tables(value)
# print array of tables
Expand Down
9 changes: 9 additions & 0 deletions test/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,12 @@ a = 2
c = 1.345
d = "hello"
"""

@test toml_str(Dict("a" => Dict("b" => Dict("c" => 1)), "d" => Dict("e" => 2))) ==
"""
[a.b]
c = 1

[d]
e = 2
"""