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

Commit

Permalink
Guard list (#20)
Browse files Browse the repository at this point in the history
* add guard for list
  • Loading branch information
KazuCocoa authored Jan 15, 2018
1 parent 224ec84 commit c8febf7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/ex_parameterized/params.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ defmodule ExUnit.Parameterized.Params do
end
end

defp param_with_index(list) do
defp param_with_index(list) when is_list(list) do
Enum.zip(list, 0..Enum.count(list))
end
defp param_with_index(list) do
raise(ArgumentError, message: "Unsupported format")
end
end
5 changes: 4 additions & 1 deletion lib/ex_parameterized/params_callback.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ defmodule ExUnit.Parameterized.ParamsCallback do
end
end

defp param_with_index(list) do
defp param_with_index(list) when is_list(list) do
Enum.zip(list, 0..Enum.count(list))
end
defp param_with_index(list) do
raise(ArgumentError, message: "Unsupported format")
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 @@ -119,4 +119,13 @@ defmodule ExParameterizedParamsCallbackTest do
"description for param2": {"hello", context[:hello], "hello and world"}
]
end

test_with_params "with function", fn p ->
p
end do
make = fn a -> a + 1 end
[
{make.(1)}
]
end
end
9 changes: 9 additions & 0 deletions test/ex_parameterized_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,13 @@ defmodule ExParameterizedTest do
end do
Enum.map([{["a", "b"]}], fn x -> x end)
end

test_with_params "with function", fn p ->
p
end do
make = fn a -> a + 1 end
[
{make.(1)}
]
end
end

0 comments on commit c8febf7

Please sign in to comment.