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

Commit

Permalink
fix nil case (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa authored Mar 16, 2019
1 parent 34a02a5 commit 92674f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/ex_parameterized/params.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ defmodule ExUnit.Parameterized.Params do
end)
end

defp test_with(desc, fun, {{param_desc, {_, _, values}}, num}) when is_atom(param_desc) do
defp test_with(desc, fun, {{param_desc, {_, _, values}}, num})
when is_atom(param_desc) and not is_nil(param_desc) do
run("'#{desc}': '#{param_desc}': number of #{num}", fun, values)
end

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

Expand Down
6 changes: 4 additions & 2 deletions lib/ex_parameterized/params_callback.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ defmodule ExUnit.Parameterized.ParamsCallback do
end)
end

defp test_with(desc, context, fun, {{param_desc, {_, _, values}}, num}) when is_atom(param_desc) do
defp test_with(desc, context, fun, {{param_desc, {_, _, values}}, num})
when is_atom(param_desc) and not is_nil(param_desc) do
run("'#{desc}': '#{param_desc}': number of #{num}", context, fun, values)
end

# 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
defp test_with(desc, context, fun, {{param_desc, values}, num})
when is_atom(param_desc) and not is_nil(param_desc) do
run("'#{desc}': '#{param_desc}': number of #{num}", context, fun, escape_values(values))
end

Expand Down
12 changes: 11 additions & 1 deletion test/ex_parameterized_callback_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ExParameterizedParamsCallbackTest do
use ExUnit.Parameterized

setup do
{:ok, [hello: "world", value: 1, bool: false]}
{:ok, [hello: "world", value: 1, bool: false, nil_value: nil]}
end

test "ast format when one param with context" do
Expand Down Expand Up @@ -96,6 +96,16 @@ defmodule ExParameterizedParamsCallbackTest do
]
end

test_with_params "with nil", context, fn expected, a, b ->
assert a == expected
assert b == expected
end do
[
{context[:value], 1, 1},
{context[:nil_value], nil, nil}
]
end

test_with_params "with map value", context, fn a ->
assert a.b == 1
assert a.c == 2
Expand Down
9 changes: 9 additions & 0 deletions test/ex_parameterized_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ defmodule ExParameterizedTest do
]
end

test_with_params "with nil", fn a, b ->
assert a == b
end do
[
{1, 1},
{nil, nil}
]
end

test_with_params "with map value", fn a ->
assert a.b == 1
assert a.c == 2
Expand Down

0 comments on commit 92674f0

Please sign in to comment.