I'm currently writing a little test runner in Elixir. I want to use pattern matching to evaluate if a file is in the spec format (ending in "_spec.exs"). There are numerous tutorials on how to pattern match on the beginning of a string, but that somehow won't work on string endings:
defp filter_spec(file <> "_spec.exs") do
run_spec(file)
end
defp run_spec(file) do
...
end
This always ends up in the compilation error:
== Compilation error on file lib/monitor.ex ==
** (CompileError) lib/monitor.ex:13: a binary field without size is only allowed at the end of a binary pattern
(stdlib) lists.erl:1337: :lists.foreach/2
(stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
Is there any solution for that?
Check for match:
String.ends_with? filename, "_spec.exs"
Extract file:
file = String.trim_trailing filename, "_spec.exs"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With