Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
function isfuncexpr(ex, name=nothing)
checkname(fdef::Expr, name) = checkname(fdef.args[1], name)
checkname(fname::Symbol, name::Symbol) = fname == name
checkname(fname::Symbol, name::Symbol) = begin
fname === name && return true
startswith(string(name), string('#', fname, '#')) && return true
return false
end
checkname(fname::Symbol, ::Nothing) = true

# Strip any macros that wrap the method definition
Expand Down
16 changes: 15 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Test, InteractiveUtils

using CodeTracking: line_is_decl

isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.jl")

@testset "CodeTracking.jl" begin
m = first(methods(f1))
Expand Down Expand Up @@ -172,3 +172,17 @@ end
print("hello")
end"""
end

@testset "kwargs methods" begin
m = nothing
for i in 1:30
s = Symbol("#func_2nd_kwarg#$i")
if isdefined(Main, s)
m = @eval $s
end
end
m === nothing && error("couldn't find keyword function")
body, loc = CodeTracking.definition(String, first(methods(m)))
@test loc == 28
@test body == "func_2nd_kwarg(; kw=2) = true"
end
3 changes: 3 additions & 0 deletions test/script.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ function f50() # issue #50
todB(x) = 10*log10(x)
println("100x is $(todB(100)) dB.")
end

func_1st_nokwarg() = true
func_2nd_kwarg(; kw=2) = true