Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doctest filter keyword does not accept substitution #2360

Open
cmichelenstrofer opened this issue Nov 28, 2023 · 3 comments · May be fixed by #2619
Open

doctest filter keyword does not accept substitution #2360

cmichelenstrofer opened this issue Nov 28, 2023 · 3 comments · May be fixed by #2619

Comments

@cmichelenstrofer
Copy link

cmichelenstrofer commented Nov 28, 2023

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
Copy link
Author

cmichelenstrofer commented Nov 28, 2023

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.

@mortenpi
Copy link
Member

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

@moble
Copy link

moble commented May 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants