Hi!
I hope to not draw this out .. afaict the goal of the PR is to preserve the method the developer used in providing options. So, I am a bit confused by possibly doing any converting (presumably from options as atoms to their binary char equivalents). This is what I had in mind though and what I implemented locally.
This seems to me to be so by the change in the type of opts field in the structure to OR with a list/list(atom); with the change to how Regexs are inspected being a 2nd evidence.
I have added the following test which seems to show this:
--- a/lib/elixir/test/elixir/inspect_test.exs
+++ b/lib/elixir/test/elixir/inspect_test.exs
@@ -864,6 +864,7 @@ test "regex" do
assert inspect(~r" \\/ ") == "~r/ \\\\\\/ /"
assert inspect(~r/hi/, syntax_colors: [regex: :red]) == "\e[31m~r/hi/\e[0m"
+ assert inspect(Regex.compile!("foo", "i")) == ~S'~r/foo/i'
assert inspect(Regex.compile!("foo", [:caseless])) == ~S'Regex.compile!("foo", [:caseless])'
end
Finally, I also added some tests for Regex.opts which show options' type are preserved:
test "opts/1" do
assert Regex.opts(Regex.compile!("foo", "i")) == "i"
+ assert Regex.opts(Regex.compile!("foo", [:caseless])) == [:caseless]
end
Though, reviewing the type spec for opts, I believe it should be updated to reflect that options are a binary OR atom list:
- @spec opts(t) :: String.t()
+ @spec opts(t) :: String.t() | [term]
def opts(%Regex{opts: opts}) do
opts
end
I apologize for the length of this reply but it does seem the present implementation is contra to my thoughts on preferring the binary representation of options over a list.
Respectfully,
Q (Quentin)