Skip to content

Commit

Permalink
Use @forward for push! and append!. Add tests for both.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapp committed May 25, 2018
1 parent 7661b72 commit 0d4acfa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/axiselements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,7 @@ end
Plot(is3d::Bool, incremental::Bool, options::Options, data::PlotData,
trailing::Tuple) = Plot(is3d, incremental, options, data, collect(trailing))

Base.push!(plot::Plot, items...) = (push!(plot.trailing, items...); plot)
Base.append!(plot::Plot, items) = (append!(plot.trailing, items); plot)
@forward Plot.trailing Base.push!, Base.append!

"""
Plot([options::Options], data, trailing...)
Expand Down
3 changes: 1 addition & 2 deletions src/axislike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Return the corresponding LaTeX environment name.
"""
function axislike_environment end

Base.push!(axislike::AxisLike, items...) = (push!(axislike.contents, items...); axislike)
Base.append!(axislike::AxisLike, items) = (append!(axislike.contents, items); axislike)
@forward AxisLike.contents Base.push!, Base.append!

(T::Type{<:AxisLike})(contents...) = T(Options(), contents...)

Expand Down
5 changes: 2 additions & 3 deletions src/tikzdocument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ struct TikzDocument
end
end

Base.push!(td::TikzDocument, items...) = (push!(td.elements, items...); td)
Base.append!(td::TikzDocument, items) = (append!(td.elements, items); td)
@forward TikzDocument.elements Base.push!, Base.append!

"""
$SIGNATURES
Expand Down Expand Up @@ -191,7 +190,7 @@ function savepdf(filename::String, td::TikzDocument;
error("ran latex 5 times without converging, log is:\n$log")
end
if run_again
savepdf(filename, td; latex_engine=latex_engine, buildflags=buildflags,
savepdf(filename, td; latex_engine=latex_engine, buildflags=buildflags,
run_count=run_count+1, tmp = tmp)
return
end
Expand Down
3 changes: 1 addition & 2 deletions src/tikzpicture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ end

TikzPicture(elements::TikzElementOrStr...) = TikzPicture(Options(), elements...)

Base.push!(tp::TikzPicture, items::TikzElementOrStr...) = push!(tp.elements, items...)
Base.append!(tp::TikzPicture, items::TikzElementOrStr) = append!(tp.elements, items)
@forward TikzPicture.elements Base.push!, Base.append!

function print_tex(io::IO, tp::TikzPicture)
@unpack options, elements = tp
Expand Down
19 changes: 19 additions & 0 deletions test/test_elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,22 @@ end
@test repr_tex(Axis(Options(; print_empty = true))) ==
"\\begin{axis}[]\n\\end{axis}\n"
end

@testset "push! and append!" begin
plot = Plot(Expression("x"))
push!(plot, "a")
append!(plot, ["b", "c"])
@test plot.trailing == ["a", "b", "c"]
axis = Axis()
push!(axis, plot)
append!(axis, ["non", "sense"])
@test axis.contents == [plot, "non", "sense"]
picture = TikzPicture()
push!(picture, axis)
append!(picture, ["some", "thing"])
@test picture.elements == [axis, "some", "thing"]
document = TikzDocument()
push!(document, picture)
append!(document, ["stuff"])
@test document.elements == [picture, "stuff"]
end

0 comments on commit 0d4acfa

Please sign in to comment.