diff --git a/src/interactive.jl b/src/interactive.jl index 8b80e01..a7d513f 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -3,7 +3,7 @@ # leaves(Plugin) # end -function Base.show(io::IO, p::T) where T <: Plugin +function Base.show(io::IO, ::MIME"text/plain", p::T) where T <: Plugin indent = get(io, :indent, 0) print(io, repeat(' ', indent), T, ":") foreach(fieldnames(T)) do n @@ -15,7 +15,7 @@ end show_field(x) = repr(x) show_field(x::AbstractString) = repr(contractuser(x)) -function Base.show(io::IO, t::Template) +function Base.show(io::IO, m::MIME"text/plain", t::Template) println(io, "Template:") foreach(fieldnames(Template)) do n n === :plugins || println(io, repeat(' ', 2), n, ": ", show_field(getfield(t, n))) @@ -24,9 +24,9 @@ function Base.show(io::IO, t::Template) print(io, " plugins: None") else print(io, repeat(' ', 2), "plugins:") - foreach(values(t.plugins)) do p + foreach(sort(collect(values(t.plugins)); by=string)) do p println(io) - show(IOContext(io, :indent => 4), p) + show(IOContext(io, :indent => 4), m, p) end end end diff --git a/test/show.jl b/test/show.jl index 54b9cac..b51aba8 100644 --- a/test/show.jl +++ b/test/show.jl @@ -9,7 +9,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) destination: "README.md" inline_badges: false """ - @test sprint(show, Readme()) == rstrip(expected) + @test sprint(show, MIME("text/plain"), Readme()) == rstrip(expected) end @testset "Template" begin @@ -17,7 +17,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) Template: authors: ["$USER"] develop: true - dir: "$(Pkg.devdir())" + dir: "$(contractuser(Pkg.devdir()))" git: true host: "github.com" julia_version: v"1.0.0" @@ -25,18 +25,26 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) ssh: false user: "$USER" plugins: - Readme: - file: "$DEFAULTS_DIR/README.md" - destination: "README.md" - inline_badges: false - Tests: - file: "$DEFAULTS_DIR/runtests.jl" Gitignore: ds_store: true dev: true License: path: "$LICENSE_DIR/MIT" destination: "LICENSE" + Readme: + file: "$DEFAULTS_DIR/README.md" + destination: "README.md" + inline_badges: false + Tests: + file: "$DEFAULTS_DIR/runtests.jl" """ + @test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected) + end + + @testset "show as serialization" begin + # Equality is not implemented for Template, so check the string form. + t1 = tpl() + t2 = eval(Meta.parse(sprint(show, t1))) + @test sprint(show, t1) == sprint(show, t2) end end