eksperimental
Idiomatic way to assert on one of several values in ExUnit
Hi everyone.
Does anybody know if there is an idiomatic way of doing a pattern matching on a list of assertions
I am trying to do this.
assert (case git_short_commit do
"" -> true
<<_::8*7>> -> true
_ -> false
end)
Thank you.
Marked As Solved
lud
I’m not sure it would be useful in this case, but there is the flunk function:
(by the way, what is this “$”? Is it a typo?)
case stuff do
"" -> assert true
<<_::8*7>> -> assert true
_ -> flunk("the variable was not an empty string or a 7 byte binary")
end
4
Also Liked
LostKobrakai
Or switch the assert method around:
case value do
... -> :ok
... -> :ok
_ -> flunk "Invalid value"
end
3
eahanson
This one might be more intention-revealing:
blank? = (git_short_commit == "")
seven_bytes? = match?(<<_::8*7>>, git_short_commit)
assert blank? || seven_bytes?, "git short commits must be 7 bytes long (or blank), got: #{git_short_commit}"
2
derek-zhou
I will just do:
assert valid_commit?(git_short_commit)
...
defp valid_commit?(""), do: true
defp valid_commit?(<<_::8*7>>), do: true
defp valid_commit?(_), do: false
2
jeroenvisser101
Not sure if this is any better?
assert $git_short_commit == "" or match?(<<_::8*7>>, $git_short_commit)
1
eksperimental
It’s a PHP variable that made its way into Elixir! ![]()
1
Popular in Questions
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir
iex(2)...
New
Other popular topics
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
can someone please explain to me how Enum.reduce works with maps
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New







