diff --git a/src/utils.jl b/src/utils.jl index 9818046..d88a64c 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 20d8400..5803393 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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)) @@ -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 diff --git a/test/script.jl b/test/script.jl index 7eec125..af157bf 100644 --- a/test/script.jl +++ b/test/script.jl @@ -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