Skip to content

Commit

Permalink
Merge pull request #48 from JuliaDebug/teh/docexprs
Browse files Browse the repository at this point in the history
Fix and test docstring extraction
  • Loading branch information
timholy authored Feb 19, 2019
2 parents 65f3c3d + 7d016f9 commit 8038678
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/JuliaInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ function prepare_toplevel!(modexs, docexprs, lex::Expr, mod::Module, ex::Expr; e
end
push!(docexs, ex)
body = ex.args[4]
if isa(body, Expr)
if isa(body, Expr) && body.head != :call
prepare_toplevel!(modexs, docexprs, lex, mod, body; extract_docexprs=extract_docexprs, filename=filename)
end
else
Expand Down
34 changes: 34 additions & 0 deletions test/toplevel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,37 @@ end
end
@test LowerAnon.z == [4,7,12]
end

@testset "Docstrings" begin
ex = quote
"""
A docstring
"""
f(x) = 1

g(T::Type) = 1
g(x) = 2

"""
Docstring 2
"""
g(T::Type)

module Sub
"""
Docstring 3
"""
f(x) = 2
end
end
Core.eval(Toplevel, Expr(:toplevel, ex.args...))
modexs, docexprs = JuliaInterpreter.prepare_toplevel(Toplevel, ex; extract_docexprs=true)
for (mod, ex) in modexs
frame = JuliaInterpreter.prepare_thunk(mod, ex)
while true
JuliaInterpreter.through_methoddef_or_done!(stack, frame) === nothing && break
end
end
@test length(docexprs[Toplevel]) == 2
@test length(docexprs[Toplevel.Sub]) == 1
end

0 comments on commit 8038678

Please sign in to comment.