Skip to content

Commit

Permalink
Add push! and append! for options. (#183)
Browse files Browse the repository at this point in the history
Addesses #182, **NEEDS DOCS**.
  • Loading branch information
tpapp authored and KristofferC committed Nov 24, 2019
1 parent 1b672f5 commit 2f81f12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ function accum_opt!(d::AbstractDict, opt::AbstractDict)
end
end

function Base.append!(options::Options, opts)
for opt in opts
accum_opt!(options.dict, opt)
end
options
end

function Base.push!(options::Options, opts::Union{String,Pair}...)
append!(options, opts)
end

function dictify(args)
options = Options()
for arg in args
Expand Down
7 changes: 7 additions & 0 deletions test/test_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ end
@test squashed_repr_tex(@pgf Plot({}, Table([], []))) ==
"\\addplot[]\ntable[row sep={\\\\}]\n{\n\\\\\n}\n;" # note []
end

@testset "options push! and append!" begin
opt1 = "color" => "red"
opt2 = "dashed"
@test @pgf(push!({}, opt1, opt2)).dict == Dict([opt1, opt2 => nothing])
@test @pgf(append!({}, [opt1, opt2])).dict == Dict([opt1, opt2 => nothing])
end

0 comments on commit 2f81f12

Please sign in to comment.