From 11dcd63b0fe874eefdcb07a66f05880d78b429ba Mon Sep 17 00:00:00 2001 From: Iblis Lin Date: Mon, 15 Jan 2018 10:40:58 +0800 Subject: [PATCH] markdown: Base.copy for Markdown.MD (#25315) --- base/markdown/parse/parse.jl | 1 + test/markdown.jl | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/base/markdown/parse/parse.jl b/base/markdown/parse/parse.jl index b9a2f9c1f36c2..a47dcc627f481 100644 --- a/base/markdown/parse/parse.jl +++ b/base/markdown/parse/parse.jl @@ -26,6 +26,7 @@ Base.setindex!(md::MD, args...) = setindex!(md.content, args...) Base.endof(md::MD) = endof(md.content) Base.length(md::MD) = length(md.content) Base.isempty(md::MD) = isempty(md.content) +Base.copy(md::MD) = MD(copy(md.content), copy(md.meta)) ==(a::MD, b::MD) = (html(a) == html(b)) diff --git a/test/markdown.jl b/test/markdown.jl index dcdce625a7510..4b9df5512e926 100644 --- a/test/markdown.jl +++ b/test/markdown.jl @@ -1079,3 +1079,17 @@ t = """ :-- | --: 1 | 2""" @test sprint(Markdown.term, Markdown.parse(t), 0) == "a b\n– –\n1 2\n" + +# test Base.copy +let + md = doc"test" + md′ = copy(md) + @test length(md) == length(md′) == 1 + push!(md, "new") + @test length(md) == 2 + @test length(md′) == 1 + + @test !haskey(md.meta, :foo) + md.meta[:foo] = 42 + @test !haskey(md′.meta, :foo) +end