diff --git a/src/parse_dfname.jl b/src/parse_dfname.jl index cb02eba..197362c 100644 --- a/src/parse_dfname.jl +++ b/src/parse_dfname.jl @@ -34,8 +34,10 @@ end # end _noerr(x...) = nothing -function _parse_dfname(name::String, ondigest::Function) +function _parse_dfname(dfn::String, ondigest::Function) _check__SEPS() + + dfn = basename(dfn) # containers head = [] @@ -43,7 +45,7 @@ function _parse_dfname(name::String, ondigest::Function) ext = "" # empty string - isempty(name) && return (;head, params, ext) + isempty(dfn) && return (;head, params, ext) # escape ESC_SEPS = _hex_escaped_seps() @@ -53,7 +55,7 @@ function _parse_dfname(name::String, ondigest::Function) hex_extsep = ESC_SEPS[:EXT_SEP] |> Regex # first digest - dig = split(name, hex_elsep; keepempty = false) + dig = split(dfn, hex_elsep; keepempty = false) # extenssion # if "blo<>.ext", extract ".ext" @@ -72,8 +74,8 @@ function _parse_dfname(name::String, ondigest::Function) # redigest if !isempty(ext) - name = name[1:end - length(ext)] - dig = split(name, hex_elsep; keepempty = false) + dfn = dfn[1:end - length(ext)] + dig = split(dfn, hex_elsep; keepempty = false) end # head @@ -81,7 +83,7 @@ function _parse_dfname(name::String, ondigest::Function) startswith(first(dig), hex_plsep) && break str = popfirst!(dig) str = _check_str(str, _noerr) - isnothing(str) && return ondigest(name, dig) + isnothing(str) && return ondigest(dfn, dig) push!(head, _parse_val(str)) end @@ -94,7 +96,7 @@ function _parse_dfname(name::String, ondigest::Function) end end - !isempty(dig) && return ondigest(name, dig) + !isempty(dig) && return ondigest(dfn, dig) return (;head, params, ext) diff --git a/test/runtests.jl b/test/runtests.jl index fcab853..6fac843 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -75,10 +75,17 @@ function _run_tests() let head = "dat" ext = ".jls" + fname = dfname(head, ext) par_head, par_params, par_ext = parse_dfname(fname) @test head in par_head @test ext == par_ext + + # with dir + fname = dfname([@__DIR__], head, ext) + par_head, par_params, par_ext = parse_dfname(fname) + @test head in par_head + @test ext == par_ext end for it in 1:100