Flow Assertions v0.3.0 FlowAssertions.EnumA View Source
Assertions that apply to Enums.
Link to this section Summary
Functions
Assert that an Enum has no elements."
If the value doesn't implement Enumerable produces an assertion exception.
Assert that an Enum has only a single element.
Returns the content element of what must be a single-element Enum.
Link to this section Functions
Assert that an Enum has no elements."
[] |> assert_empty # true
%{} |> assert_empty # true If the value doesn't implement Enumerable produces an assertion exception.
The output is more friendly than a Protocol.UndefinedError. So, for example,
the other assertions in this module start with this assertion.
defchain assert_empty(value_to_check) do
assert_enumerable(value_to_check)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
elaborate_assert(Enum.empty?(value_to_check),
Messages.expected_no_element,
left: value_to_check)
end Assert that an Enum has only a single element.
[1] |> assert_singleton # passes
[ ] |> assert_singleton # fails
%{a: 1} |> assert_singleton # passes
%{a: 1, b: 2} |> assert_singleton # fails Returns the content element of what must be a single-element Enum.
''' [1] |> singleton_content # 1 [ ] |> singleton_content # fails %{a: 1} |> singleton_content # the tuple {:a, 1} 5 |> singleton_content # faila