Documenter.jl icon indicating copy to clipboard operation
Documenter.jl copied to clipboard

`doctest` `filter` keyword does not accept substitution

Open cmichelenstrofer opened this issue 1 year ago • 3 comments

Is there a reason the filter keyword does not accept substitutions? I am trying to define a filter for all doctests (e.g. for comparing floating point numbers only consider up to 10 decimal values):

julia> doctest(MyPackage; doctestfilters = [(r"(\d*).(\d{1,10})\d+" => s"\1.\2"),])
...
TypeError: in keyword argument doctestfilters, expected Vector{Regex}, got a value of type Vector{Pair{Regex, SubstitutionString{String}}}
...

passing this filter to each jldoctest individually works, but I would rather do it just once.

cmichelenstrofer avatar Nov 28 '23 17:11 cmichelenstrofer

Also, when using the filters at the individual test level, I need to use double backslash or get an error about invalid escape sequence. What works for me is:

jldoctest; filter = r"(\\d*).(\\d{1,10})\\d+" => s"\\1.\\2"

Maybe this should be documented.

cmichelenstrofer avatar Nov 28 '23 18:11 cmichelenstrofer

Seems like an oversight when the substitutions got added. Probably just need to expand the version constraint on the function.

mortenpi avatar Nov 28 '23 19:11 mortenpi

This would probably be a good thing to implement. As a workaround, I'll point out that lookbehinds and lookaheads suffice for many (but not all) applications instead of a substitution. I wrote an example here.

moble avatar May 07 '24 19:05 moble