Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Commit

Permalink
apply multi-param impl for callback (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa authored Oct 22, 2018
1 parent 7e144b9 commit 9a0a926
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ex_parameterized/params.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule ExUnit.Parameterized.Params do

defp escape_values(values) do
values
|> Tuple.to_list
|> Tuple.to_list()
|> Enum.map(fn x ->
case x do
value when is_map(value) -> Macro.escape(x)
Expand Down
15 changes: 13 additions & 2 deletions lib/ex_parameterized/params_callback.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule ExUnit.Parameterized.ParamsCallback do

# Quote literals case : http://elixir-lang.org/docs/master/elixir/Kernel.SpecialForms.html#quote/2
defp test_with(desc, context, fun, {{param_desc, values}, num}) when is_atom(param_desc) do
run("'#{desc}': '#{param_desc}': number of #{num}", context, fun, Tuple.to_list(values))
run("'#{desc}': '#{param_desc}': number of #{num}", context, fun, escape_values(values))
end

defp test_with(desc, context, fun, {{_, _, values}, num}),
Expand All @@ -69,7 +69,7 @@ defmodule ExUnit.Parameterized.ParamsCallback do

# Quote literals case : http://elixir-lang.org/docs/master/elixir/Kernel.SpecialForms.html#quote/2
defp test_with(desc, context, fun, {values, num}),
do: run("'#{desc}': number of #{num}", context, fun, Tuple.to_list(values))
do: run("'#{desc}': number of #{num}", context, fun, escape_values(values))

defp run(desc, context, fun, params) do
quote do
Expand All @@ -88,4 +88,15 @@ defmodule ExUnit.Parameterized.ParamsCallback do
defp param_with_index(_) do
raise(ArgumentError, message: "Unsupported format")
end

defp escape_values(values) do
values
|> Tuple.to_list()
|> Enum.map(fn x ->
case x do
value when is_map(value) -> Macro.escape(x)
_ -> x
end
end)
end
end
9 changes: 9 additions & 0 deletions test/ex_parameterized_callback_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,13 @@ defmodule ExParameterizedParamsCallbackTest do
{make.(1)}
]
end

test_with_params "with map as second parameter", context, fn a, m ->
assert a == "some"
assert m.a == "world"
end do
[
{"some", %{a: context[:hello], b: 2, c: 3}}
]
end
end

0 comments on commit 9a0a926

Please sign in to comment.