diff --git a/lib/outstanding/map.ex b/lib/outstanding/map.ex index 27aa9b0..e525ae8 100644 --- a/lib/outstanding/map.ex +++ b/lib/outstanding/map.ex @@ -4,10 +4,14 @@ defoutstanding expected :: Map, actual :: Any do case Outstand.type_of(actual) do Map -> Map.keys(expected) - |> Enum.filter(&(Outstanding.outstanding(expected[&1], actual[&1]))) + |> Enum.filter(fn key -> + not Map.has_key?(actual, key) or + Outstanding.outstanding(expected[key], actual[key]) != nil + end) |> Enum.into(%{}, &{&1, Outstanding.outstanding(expected[&1], actual[&1])}) |> Outstand.suppress() + _ -> expected - end + end end diff --git a/test/map_test.exs b/test/map_test.exs index c73361e..5839e8a 100644 --- a/test/map_test.exs +++ b/test/map_test.exs @@ -4,8 +4,12 @@ defmodule Outstanding.MapTest do gen_something_outstanding_test("key outstanding", %{x: :a, y: :b}, %{x: :a, z: :b}) gen_something_outstanding_test("value outstanding", %{x: :a, y: :b}, %{x: :b, y: :b}) + gen_something_outstanding_test("key nil value outstanding", %{x: :a, y: nil}, %{x: :a, z: :b}) + gen_something_outstanding_test("value falsy outstanding", %{x: false, y: :b}, %{x: :b, y: :b}) gen_nothing_outstanding_test("realized", %{x: :a, y: :b}, %{x: :a, y: :b}) gen_nothing_outstanding_test("realized with extra item", %{x: :a, y: :b}, %{x: :a, y: :b, z: :b}) gen_result_outstanding_test("key result", %{x: :a, y: :b}, %{x: :a, z: :b}, %{y: :b}) - gen_result_outstanding_test("value result", %{x: :a, y: :b}, %{x: :b, y: :b}, %{x: :a}) + gen_result_outstanding_test("value result", %{x: :a, y: :b}, %{x: :b, y: :b}, %{x: :a}) + gen_result_outstanding_test("key nil result", %{x: :a, y: nil}, %{x: :a, z: :b}, %{y: nil}) + gen_result_outstanding_test("value falsy result", %{x: false, y: :b}, %{x: :b, y: :b}, %{x: false}) end