- I have a function (
myfun/1
) that takes in a list of characters, and depending on the characters in the list, returns a list of named functions (that are defined in the same module)–which will be applied at a later time.
Enum.reduce(com_chars, [], fn x, acc ->
case x do
"." -> [&to_lowercase/1 | acc]
"^" -> [&to_uppercase/1 | acc]
_ -> [:error | acc]
end
end)
|> Enum.reverse()
- when I test this function in ExUnit (after importing MyMod) with
assert myfun([".", "^"]) == [&to_lowercase/1, &to_uppercase/1]
, the test fails for the following reasons:- in the test,
&to_lowercase/1
and&to_uppercase/1
are expanded to&MyMod.the_function/1
-
myfun
seems to return a list of lambdas and not the named functions:[#Function..., #Function...]
- in the test,
- I can get around this if I use fully qualified names in
myfun
, however this does not work if I pass in a function with a set argument, like&get_slice(&1, "[0-5]")
. In this case the function shows up as a lambda on both sides of the assert (and not the same lambda either).
My question is: how exactly should I be testing functions that return other functions?