Skip to content

Commit

Permalink
Merge pull request #301 from gustaphe/nothing
Browse files Browse the repository at this point in the history
Allow `nothing` as a sentinel value in recipes
  • Loading branch information
gustaphe authored Aug 8, 2024
2 parents f4b1546 + 9f23755 commit 46d5a2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ function create_kw_body(func_signature::Expr)
@warn("Type annotations on keyword arguments not currently supported in recipes. Type information has been discarded")
end
push!(kw_body.args, :($k = kwargs[$(Meta.quot(k))]))
kw_dict[k] = v isa QuoteNode ? v.value : v
if v == :nothing
kw_dict[k] = nothing
else
kw_dict[k] = v isa QuoteNode ? v.value : v
end
end
args = args[2:end]
end
Expand Down
13 changes: 13 additions & 0 deletions test/recipe_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,16 @@ sum1 = MyModule.MySum(3, 4)
@test latexify(:(2 + $(sum1)^2)) == raw"$2 + \left( 3 + 4 \right)^{2}$"
@test latexify(:(2 - $(sum1))) == raw"$2 - \left( 3 + 4 \right)$"

struct NothingThing end
@latexrecipe function f(::NothingThing; keyword=nothing)
if isnothing(keyword)
return L"a"
elseif keyword == :nothing
return L"b"
end
end
@test latexify(NothingThing()) == raw"$a$"
@test latexify(NothingThing(); keyword=nothing) == raw"$a$"
@test latexify(NothingThing(); keyword=:nothing) == raw"$b$"


0 comments on commit 46d5a2d

Please sign in to comment.