diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7a9b41d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,24 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](Https://conventionalcommits.org) for commit guidelines. + + + +## [v0.1.0](https://github.com/diffo-dev/outstanding/compare/v0.1.0...v0.1.0) (2025-03-11) + +### Features: +* initial version + +## [v0.2.0](https://github.com/diffo-dev/outstanding/compare/v0.1.0...v0.2.0) (2025-05-12) + +### Features: +* duration +* added outstanding? to protocol (use Outstanding.outstanding? rather than Outstand.outstanding?) +* livebook + +## [v0.2.1](https://github.com/diffo-dev/outstanding/compare/v0.2.0...v0.2.1) (2025-05-17) + +### Features +* enhanced List implementation +* fixed Duration and related expected functions not to use to_timeout \ No newline at end of file diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/README.md b/README.md index ff0f6ec..27b09f5 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ by adding `outstanding` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:outstanding, "~> 0.2.0"} + {:outstanding, "~> 0.3.0"} ] end ``` @@ -141,15 +141,13 @@ Expected functions of arity 2 are also supported. These have the form of a tuple You can supply your own functions where needed. -## Infix Shortcuts +### Exceeds and Difference Operators -`use Outstand` expression provides infix shortcuts for outstanding -Also it provides infix shortcuts for these utilities: +For convenient use in expressions we've implemented operators. -| Equivalent Function | infix shortcut | returns | memory aid | -|--------------------------------------------|-------------------------|------------------------|--------------------------| -| Outstanding.outstanding(expected, actual) | expected --- actual | nil or Outstanding.t() | expected less actual | -| Outstanding.outstanding?(expected, actual) | expected >>> actual | boolean | expected exceeds actual? | +The 'exceeds' operator tells us whether our expectations exceed our actual. ```expected >>> actual``` is equivalent to ```Outstanding.outstanding?(expected, actual)``` + +The 'difference' operator tells us what expectations remain unmet. ```expected --- actual``` is equivalent to ```Outstanding.outstanding(expected, actual)``` Example of infix shortcuts usage: diff --git a/VERSION b/VERSION index 341cf11..7dff5b8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 \ No newline at end of file +0.2.1 \ No newline at end of file diff --git a/lib/outstand.ex b/lib/outstand.ex index d92384c..a757352 100644 --- a/lib/outstand.ex +++ b/lib/outstand.ex @@ -276,7 +276,7 @@ defmodule Outstand do false ``` """ - @spec nil_outstanding?(Outstanding.t, any) :: boolean() + @spec nil_outstanding?(Outstanding.t(), any) :: boolean() def nil_outstanding?(expected, actual) do not Outstanding.outstanding?(expected, actual) end @@ -365,6 +365,7 @@ defmodule Outstand do case actual do %Date{} -> nil + _ -> :any_date end @@ -388,6 +389,7 @@ defmodule Outstand do case actual do %DateTime{} -> nil + _ -> :any_date_time end @@ -411,6 +413,7 @@ defmodule Outstand do case actual do %Duration{} -> nil + _ -> :any_duration end @@ -434,6 +437,7 @@ defmodule Outstand do case actual do %NaiveDateTime{} -> nil + _ -> :any_naive_date_time end @@ -457,6 +461,7 @@ defmodule Outstand do case actual do %Time{} -> nil + _ -> :any_time end @@ -572,6 +577,7 @@ defmodule Outstand do case actual do %MapSet{} -> nil + _ -> :any_map_set end @@ -617,6 +623,7 @@ defmodule Outstand do case actual do _first.._last//_step -> nil + _ -> :any_range end @@ -667,9 +674,11 @@ defmodule Outstand do case Date.compare(actual, DateTime.utc_now() |> DateTime.to_date()) do :eq -> nil + _ -> :current_date end + _ -> :current_date end @@ -696,11 +705,12 @@ defmodule Outstand do case actual do %DateTime{} -> if DateTime.after?(actual, DateTime.utc_now() |> DateTime.add(-1, :minute)) && - DateTime.before?(actual, DateTime.utc_now() |> DateTime.add(1, :minute)) do + DateTime.before?(actual, DateTime.utc_now() |> DateTime.add(1, :minute)) do nil else :current_date_time end + _ -> :current_date_time end @@ -727,11 +737,12 @@ defmodule Outstand do case actual do %NaiveDateTime{} -> if NaiveDateTime.after?(actual, DateTime.utc_now() |> DateTime.to_naive() |> NaiveDateTime.add(-1, :minute)) && - NaiveDateTime.before?(actual, DateTime.utc_now() |> DateTime.to_naive() |> NaiveDateTime.add(1, :minute)) do + NaiveDateTime.before?(actual, DateTime.utc_now() |> DateTime.to_naive() |> NaiveDateTime.add(1, :minute)) do nil else :current_naive_date_time end + _ -> :current_naive_date_time end @@ -758,11 +769,12 @@ defmodule Outstand do case actual do %Time{} -> if Time.after?(actual, DateTime.utc_now() |> DateTime.to_time() |> Time.add(-1, :minute)) && - Time.before?(actual, DateTime.utc_now() |> DateTime.to_time() |> Time.add(1, :minute)) do + Time.before?(actual, DateTime.utc_now() |> DateTime.to_time() |> Time.add(1, :minute)) do nil else :current_time end + _ -> :current_time end @@ -834,6 +846,7 @@ defmodule Outstand do else :empty_map_set end + _ -> :empty_map_set end @@ -884,6 +897,7 @@ defmodule Outstand do else :future_date end + _ -> :future_date end @@ -912,6 +926,7 @@ defmodule Outstand do else :future_date_time end + _ -> :future_date_time end @@ -940,6 +955,7 @@ defmodule Outstand do else :future_naive_date_time end + _ -> :future_naive_date_time end @@ -968,12 +984,13 @@ defmodule Outstand do else :future_time end + _ -> :future_time end end - @doc """ + @doc """ Function which expects non empty keyword ## Examples @@ -1061,6 +1078,7 @@ defmodule Outstand do else :non_empty_map_set end + _ -> :non_empty_map_set end @@ -1110,6 +1128,7 @@ defmodule Outstand do else :past_date end + _ -> :past_date end @@ -1137,6 +1156,7 @@ defmodule Outstand do else :past_date_time end + _ -> :past_date_time end @@ -1164,6 +1184,7 @@ defmodule Outstand do else :past_naive_date_time end + _ -> :past_naive_date_time end @@ -1191,6 +1212,7 @@ defmodule Outstand do else :past_time end + _ -> :past_time end @@ -1298,10 +1320,12 @@ defmodule Outstand do cond do actual == nil -> :less_than - to_timeout(actual) < to_timeout(expected) -> - nil true -> - :less_than + now = DateTime.utc_now() + case DateTime.compare(DateTime.shift(now, actual), DateTime.shift(now, expected)) do + :lt -> nil + _ -> :less_than + end end end @@ -1323,10 +1347,12 @@ defmodule Outstand do cond do actual == nil -> :greater_than - to_timeout(actual) > to_timeout(expected) -> - nil true -> - :greater_than + now = DateTime.utc_now() + case DateTime.compare(DateTime.shift(now, actual), DateTime.shift(now, expected)) do + :gt -> nil + _ -> :greater_than + end end end @@ -1350,16 +1376,22 @@ defmodule Outstand do cond do actual == nil -> :bounded_by + length(expected) != 2 -> :error + true -> - min = to_timeout(hd(expected)) - max = to_timeout(hd(tl(expected))) + now = DateTime.utc_now() + min = DateTime.shift(now, hd(expected)) + max = DateTime.shift(now, hd(tl(expected))) + shifted = DateTime.shift(now, actual) + cond do - to_timeout(actual) >= min and to_timeout(actual) <= max -> - nil - true -> + DateTime.before?(shifted, min) or DateTime.after?(shifted, max) -> :bounded_by + + true -> + :nil end end end @@ -1384,14 +1416,20 @@ defmodule Outstand do cond do actual == nil -> :unbounded_by + length(expected) != 2 -> :error + true -> - min = to_timeout(hd(expected)) - max = to_timeout(hd(tl(expected))) + now = DateTime.utc_now() + min = DateTime.shift(now, hd(expected)) + max = DateTime.shift(now, hd(tl(expected))) + shifted = DateTime.shift(now, actual) + cond do - to_timeout(actual) < min or to_timeout(actual) > max -> - nil + DateTime.before?(shifted, min) or DateTime.after?(shifted, max) -> + :nil + true -> :unbounded_by end @@ -1433,7 +1471,7 @@ defmodule Outstand do """ @spec map_to_struct(any() | nil, bitstring()) :: any() def map_to_struct(term, name) do - if (is_map(term)) do + if is_map(term) do struct(name, term) else term @@ -1476,6 +1514,7 @@ defmodule Outstand do def suppress(list) when is_list(list) do nils_removed = Enum.reject(list, &is_nil(&1)) + if Enum.empty?(nils_removed) do nil else @@ -1539,22 +1578,27 @@ defmodule Outstand do @spec type_of(any()) :: module() def type_of(term) do case term do - _first.._last//_step -> Range - %MapSet{} -> MapSet - %_{} -> term.__struct__ + _first.._last//_step -> + Range + + %MapSet{} -> + MapSet + + %_{} -> + term.__struct__ _ -> cond do - is_boolean(term) -> Boolean - is_atom(term) -> Atom - is_bitstring(term) -> BitString - is_float(term) -> Float - is_function(term) -> Function - is_integer(term) -> Integer - is_list(term) -> List - is_map(term) -> Map - is_tuple(term) -> Tuple - true -> Other + is_boolean(term) -> Boolean + is_atom(term) -> Atom + is_bitstring(term) -> BitString + is_float(term) -> Float + is_function(term) -> Function + is_integer(term) -> Integer + is_list(term) -> List + is_map(term) -> Map + is_tuple(term) -> Tuple + true -> Other end end end diff --git a/lib/outstanding.ex b/lib/outstanding.ex index a528afb..b675e05 100644 --- a/lib/outstanding.ex +++ b/lib/outstanding.ex @@ -1,5 +1,4 @@ defprotocol Outstanding do - @moduledoc """ Protocol for comparing expected and actual, highlighting outstanding expectations unmet by actual """ diff --git a/lib/outstanding/date.ex b/lib/outstanding/date.ex index 0e2cc44..cc3e399 100644 --- a/lib/outstanding/date.ex +++ b/lib/outstanding/date.ex @@ -7,6 +7,7 @@ defoutstanding expected :: Date, actual :: Any do case Date.compare(expected, actual) do :eq -> nil + _ -> expected end diff --git a/lib/outstanding/date_time.ex b/lib/outstanding/date_time.ex index 04d5a8a..e30788e 100644 --- a/lib/outstanding/date_time.ex +++ b/lib/outstanding/date_time.ex @@ -7,6 +7,7 @@ defoutstanding expected :: DateTime, actual :: Any do case DateTime.compare(expected, actual) do :eq -> nil + _ -> expected end diff --git a/lib/outstanding/duration.ex b/lib/outstanding/duration.ex index 0c3da7c..73c3938 100644 --- a/lib/outstanding/duration.ex +++ b/lib/outstanding/duration.ex @@ -4,7 +4,8 @@ defoutstanding expected :: Duration, actual :: Any do if expected == nil or Outstand.type_of(actual) != Duration do expected else - if to_timeout(expected) == to_timeout(actual) do + now = DateTime.utc_now() + if DateTime.shift(now, expected) == DateTime.shift(now, actual) do nil else expected diff --git a/lib/outstanding/float.ex b/lib/outstanding/float.ex index 63b82ae..5be2a65 100644 --- a/lib/outstanding/float.ex +++ b/lib/outstanding/float.ex @@ -7,12 +7,14 @@ defoutstanding expected :: Float, actual :: Any do ^expected -> nil _ -> expected end + Integer -> - if (expected == actual) do + if expected == actual do nil else expected end + _ -> expected end diff --git a/lib/outstanding/integer.ex b/lib/outstanding/integer.ex index 02183f8..9193bb9 100644 --- a/lib/outstanding/integer.ex +++ b/lib/outstanding/integer.ex @@ -7,18 +7,21 @@ defoutstanding expected :: Integer, actual :: Any do ^expected -> nil _ -> expected end + Float -> - if (expected == actual) do + if expected == actual do nil else expected end + Range -> - if (expected in actual) do + if expected in actual do nil else expected end + _ -> expected end diff --git a/lib/outstanding/list.ex b/lib/outstanding/list.ex index c3f6804..af8d103 100644 --- a/lib/outstanding/list.ex +++ b/lib/outstanding/list.ex @@ -40,10 +40,12 @@ defoutstanding expected :: List, actual :: Any do # expected longer than actual, cannot resolve outstanding true -> padded_actual = actual ++ List.duplicate(nil, Enum.count(expected) - Enum.count(actual)) + expected |> Enum.zip(padded_actual) |> Enum.map(&Outstanding.outstanding(elem(&1, 0), elem(&1, 1))) end + _ -> expected end diff --git a/lib/outstanding/map_set.ex b/lib/outstanding/map_set.ex index 5dfe98b..fc320fa 100644 --- a/lib/outstanding/map_set.ex +++ b/lib/outstanding/map_set.ex @@ -5,11 +5,13 @@ defoutstanding expected :: MapSet, actual :: Any do MapSet -> # difference filters on non-equal, not nil outstanding ms_difference = MapSet.difference(expected, actual) + expected |> Enum.filter(&MapSet.member?(ms_difference, &1)) |> MapSet.new() |> Outstand.suppress() + _ -> expected - end + end end diff --git a/lib/outstanding/naive_date_time.ex b/lib/outstanding/naive_date_time.ex index 0084e8c..eadb94a 100644 --- a/lib/outstanding/naive_date_time.ex +++ b/lib/outstanding/naive_date_time.ex @@ -7,6 +7,7 @@ defoutstanding expected :: NaiveDateTime, actual :: Any do case NaiveDateTime.compare(expected, actual) do :eq -> nil + _ -> expected end diff --git a/lib/outstanding/range.ex b/lib/outstanding/range.ex index 6cbbb4d..081882e 100644 --- a/lib/outstanding/range.ex +++ b/lib/outstanding/range.ex @@ -7,12 +7,14 @@ defoutstanding expected :: Range, actual :: Any do ^expected -> nil _ -> expected end + Integer -> - if (actual in expected) do + if actual in expected do nil else expected end + _ -> expected end diff --git a/lib/outstanding/time.ex b/lib/outstanding/time.ex index 65354b3..43f8209 100644 --- a/lib/outstanding/time.ex +++ b/lib/outstanding/time.ex @@ -7,6 +7,7 @@ defoutstanding expected :: Time, actual :: Any do case Time.compare(expected, actual) do :eq -> nil + _ -> expected end diff --git a/lib/outstanding/tuple.ex b/lib/outstanding/tuple.ex index e2f86c7..43b02b4 100644 --- a/lib/outstanding/tuple.ex +++ b/lib/outstanding/tuple.ex @@ -13,7 +13,8 @@ defoutstanding expected :: Tuple, actual :: Any do Enum.zip(Tuple.to_list(expected), Tuple.to_list(actual)) |> Enum.filter(&Outstanding.outstanding(elem(&1, 0), elem(&1, 1))) |> Enum.unzip() - if (outstanding == []) do + + if outstanding == [] do nil else expected @@ -21,6 +22,7 @@ defoutstanding expected :: Tuple, actual :: Any do else expected end + _ -> expected end diff --git a/mix.exs b/mix.exs index 88b4a50..fb656f1 100644 --- a/mix.exs +++ b/mix.exs @@ -1,31 +1,43 @@ defmodule Outstanding.MixProject do use Mix.Project - def project do + @name :outstanding + @version "0.2.1" + @description "Elixir protocol calculating outstanding from expected and actual" + @github_url "https://github.com/diffo-dev/outstanding" + + def project() do [ - app: :outstanding, - version: "0.2.0", + app: @name, + version: @version, + name: @name, + description: @description, elixir: "~> 1.18", consolidate_protocols: Mix.env() != :test, start_permanent: Mix.env() == :prod, - deps: deps(), + package: package(), # ex_doc - name: "Outstanding", - source_url: "https://github.com/diffo-dev/outstanding", + source_url: @github_url, homepage_url: "https://diffo.dev/diffo/outstanding", - docs: [main: "readme", extras: ["README.md"]], + elixirc_paths: elixirc_paths(Mix.env()), # hex.pm stuff - description: "Elixir protocol calculating outstanding from expected and actual", - package: [ - name: "outstanding", - licenses: ["MIT"], - files: ["lib", "mix.exs", "README*", "VERSION*"], - maintainers: ["Matt Beanland"], - links: %{ - "GitHub" => "https://github.com/diffo-dev/outstanding", - "Author's home page" => "https://www.diffo.dev" - } - ] + deps: deps(), + docs: &docs/0 + ] + end + + defp elixirc_paths(_), do: ["lib"] + + defp package do + [ + name: @name, + licenses: ["MIT"], + files: ~w(lib .formatter.exs mix.exs README* LICENSE* + CHANGELOG* documentation), + links: %{ + "GitHub" => @github_url, + "Author's home page" => "https://www.diffo.dev" + } ] end @@ -39,7 +51,25 @@ defmodule Outstanding.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:ex_doc, "~> 0.37", only: :dev, runtime: false} + {:ex_doc, "~> 0.37", only: :dev, runtime: false}, + {:ex_check, "~> 0.12", only: [:dev, :test]}, + {:git_ops, "~> 2.7", only: [:dev], runtime: false}, + {:credo, ">= 0.0.0", only: [:dev, :test], runtime: false}, + {:dialyxir, ">= 0.0.0", only: [:dev, :test], runtime: false} + ] + end + + def docs() do + [ + homepage_url: @github_url, + source_url: @github_url, + source_ref: "v#{@version}", + main: "readme", + logo: "logos/diffo.jpg", + extras: [ + "README.md": [title: "Guide"], + "LICENSE.md": [title: "License"] + ] ] end end diff --git a/mix.lock b/mix.lock index f317d52..e55adb4 100644 --- a/mix.lock +++ b/mix.lock @@ -1,6 +1,15 @@ %{ + "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, + "credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"}, + "dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"}, "earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"}, + "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, + "ex_check": {:hex, :ex_check, "0.16.0", "07615bef493c5b8d12d5119de3914274277299c6483989e52b0f6b8358a26b5f", [:mix], [], "hexpm", "4d809b72a18d405514dda4809257d8e665ae7cf37a7aee3be6b74a34dec310f5"}, "ex_doc": {:hex, :ex_doc, "0.38.1", "bae0a0bd5b5925b1caef4987e3470902d072d03347114ffe03a55dbe206dd4c2", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "754636236d191b895e1e4de2ebb504c057fe1995fdfdd92e9d75c4b05633008b"}, + "file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"}, + "git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"}, + "git_ops": {:hex, :git_ops, "2.7.2", "2d3c164a8bcaf13f129ab339e8e9f0a99c80ffa8f85dd0b344d7515275236dbc", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:igniter, ">= 0.5.27 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "1dcd68b3f5bcd0999d69274cd21e74e652a90452e683b54d490fa5b26152945f"}, + "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, "makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"}, diff --git a/outstanding.livemd b/outstanding.livemd index 6040a62..4723155 100644 --- a/outstanding.livemd +++ b/outstanding.livemd @@ -1,7 +1,7 @@ # Outstanding Elixir Protocol ```elixir -Mix.install([{:outstanding, "~> 0.2.0"}], consolidate_protocols: false) +Mix.install([{:outstanding, "~> 0.2.1"}], consolidate_protocols: false) ``` ## Overview diff --git a/test/atom_test.exs b/test/atom_test.exs index c113b17..2055895 100644 --- a/test/atom_test.exs +++ b/test/atom_test.exs @@ -11,14 +11,14 @@ defmodule Outstanding.AtomTest do gen_result_outstanding_test("value result", :a, :b, :a) gen_result_outstanding_test("value result, nil", :a, nil, :a) - #explicit_nil using atom rather than function + # explicit_nil using atom rather than function gen_something_outstanding_test("explicit_nil value outstanding", :explicit_nil, true) gen_something_outstanding_test("explicit_nil value outstanding, regular nil", :explicit_nil, nil) gen_nothing_outstanding_test("explicit_nil realized", :explicit_nil, :explicit_nil) gen_result_outstanding_test("explicit_nil value result", :explicit_nil, true, :explicit_nil) gen_result_outstanding_test("explicit_nil value result, regular nil", :explicit_nil, nil, :explicit_nil) - #no_value atom + # no_value atom gen_nothing_outstanding_test("no value realized", :no_value, :no_value) gen_nothing_outstanding_test("no value realized by nil", :no_value, nil) end diff --git a/test/date_test.exs b/test/date_test.exs index 7441ecc..374a344 100644 --- a/test/date_test.exs +++ b/test/date_test.exs @@ -3,7 +3,7 @@ defmodule Outstanding.DateTest do use Outstand @now DateTime.utc_now() |> DateTime.to_naive() - @future DateTime.utc_now() |> DateTime.add(1, :day)|> DateTime.to_date() + @future DateTime.utc_now() |> DateTime.add(1, :day) |> DateTime.to_date() @past DateTime.utc_now() |> DateTime.add(-1, :day) |> DateTime.to_date() gen_something_outstanding_test("value outstanding, future", @now, @future) diff --git a/test/duration_test.exs b/test/duration_test.exs index 675dfd2..5c96feb 100644 --- a/test/duration_test.exs +++ b/test/duration_test.exs @@ -2,6 +2,7 @@ defmodule Outstanding.DurationTest do use ExUnit.Case use Outstand + @year Duration.new!(year: 1) @hour Duration.new!(hour: 1) @minute Duration.new!(minute: 1) @sixty_seconds Duration.new!(second: 60) @@ -10,9 +11,11 @@ defmodule Outstanding.DurationTest do gen_something_outstanding_test("value outstanding, shorter", @minute, @second) gen_something_outstanding_test("value outstanding, longer", @minute, @hour) gen_something_outstanding_test("value outstanding, nil", @minute, nil) + gen_something_outstanding_test("value outstanding, large", @minute, @year) gen_nothing_outstanding_test("realized", @minute, @minute) gen_nothing_outstanding_test("realized, equivalent", @minute, @sixty_seconds) gen_result_outstanding_test("value result, shorter", @minute, @second, @minute) gen_result_outstanding_test("value result, longer", @minute, @hour, @minute) - gen_result_outstanding_test("value result, nil", @minute, nil, @minute) + gen_result_outstanding_test("value result, nil", @minute, nil, @minute) + gen_result_outstanding_test("value result, large", @minute, @year, @minute) end diff --git a/test/function_arity_1_test.exs b/test/function_arity_1_test.exs index f3802f3..c683725 100644 --- a/test/function_arity_1_test.exs +++ b/test/function_arity_1_test.exs @@ -77,11 +77,28 @@ defmodule Outstanding.ExpectedFunctionArity1Test do gen_something_outstanding_test("current_date_time value outstanding", &Outstand.current_date_time/1, ~U[2002-02-25 11:59:00.00Z]) gen_nothing_outstanding_test("current_date_time realized", &Outstand.current_date_time/1, DateTime.utc_now()) - gen_result_outstanding_test("current_date_time value result", &Outstand.current_date_time/1, "~U[2002-02-25 11:59:00.00Z]", :current_date_time) + + gen_result_outstanding_test( + "current_date_time value result", + &Outstand.current_date_time/1, + "~U[2002-02-25 11:59:00.00Z]", + :current_date_time + ) gen_something_outstanding_test("current_naive_date_time value outstanding", &Outstand.current_naive_date_time/1, ~N[2002-02-25 11:59:00]) - gen_nothing_outstanding_test("current_naive_date_time realized", &Outstand.current_naive_date_time/1, DateTime.utc_now() |> DateTime.to_naive()) - gen_result_outstanding_test("current_naive_date_time value result", &Outstand.current_naive_date_time/1, "~N[2002-02-25 11:59:00]", :current_naive_date_time) + + gen_nothing_outstanding_test( + "current_naive_date_time realized", + &Outstand.current_naive_date_time/1, + DateTime.utc_now() |> DateTime.to_naive() + ) + + gen_result_outstanding_test( + "current_naive_date_time value result", + &Outstand.current_naive_date_time/1, + "~N[2002-02-25 11:59:00]", + :current_naive_date_time + ) gen_something_outstanding_test("current_time value outstanding", &Outstand.current_time/1, ~T[11:59:00.000]) gen_nothing_outstanding_test("current_time realized", &Outstand.current_time/1, DateTime.utc_now() |> DateTime.to_time()) @@ -107,11 +124,23 @@ defmodule Outstanding.ExpectedFunctionArity1Test do gen_something_outstanding_test("future_date_time value outstanding", &Outstand.future_date_time/1, ~U[2002-02-25 11:59:00.00Z]) gen_nothing_outstanding_test("future_date_time realized", &Outstand.future_date_time/1, ~U[2102-02-25 11:59:00.00Z]) - gen_result_outstanding_test("future_date_time value result", &Outstand.future_date_time/1, "~U[2002-02-25 11:59:00.00Z]", :future_date_time) + + gen_result_outstanding_test( + "future_date_time value result", + &Outstand.future_date_time/1, + "~U[2002-02-25 11:59:00.00Z]", + :future_date_time + ) gen_something_outstanding_test("future_naive_date_time value outstanding", &Outstand.future_naive_date_time/1, ~N[2002-02-25 11:59:00]) gen_nothing_outstanding_test("future_naive_date_time realized", &Outstand.future_naive_date_time/1, ~N[2102-02-25 11:59:00]) - gen_result_outstanding_test("future_naive_date_time value result", &Outstand.future_naive_date_time/1, "~N[2002-02-25 11:59:00]", :future_naive_date_time) + + gen_result_outstanding_test( + "future_naive_date_time value result", + &Outstand.future_naive_date_time/1, + "~N[2002-02-25 11:59:00]", + :future_naive_date_time + ) gen_something_outstanding_test("future_time value outstanding", &Outstand.future_time/1, ~T[00:00:00.000]) gen_nothing_outstanding_test("future_time realized", &Outstand.future_time/1, ~T[23:59:59.999]) @@ -135,7 +164,13 @@ defmodule Outstanding.ExpectedFunctionArity1Test do gen_something_outstanding_test("past_naive_date_time value outstanding", &Outstand.past_naive_date_time/1, ~N[2102-02-25 11:59:00]) gen_nothing_outstanding_test("past_naive_date_time realized", &Outstand.past_naive_date_time/1, ~N[2002-02-25 11:59:00]) - gen_result_outstanding_test("past_naive_date_time value result", &Outstand.past_naive_date_time/1, "~N[2102-02-25 11:59:00]", :past_naive_date_time) + + gen_result_outstanding_test( + "past_naive_date_time value result", + &Outstand.past_naive_date_time/1, + "~N[2102-02-25 11:59:00]", + :past_naive_date_time + ) gen_something_outstanding_test("past_time value outstanding", &Outstand.past_time/1, ~T[23:59:59.999]) gen_nothing_outstanding_test("past_time realized", &Outstand.past_time/1, ~T[00:00:00.000]) diff --git a/test/function_arity_2_test.exs b/test/function_arity_2_test.exs index 645afc3..277d1ae 100644 --- a/test/function_arity_2_test.exs +++ b/test/function_arity_2_test.exs @@ -33,23 +33,113 @@ defmodule Outstanding.ExpectedFunctionArity2Test do gen_something_outstanding_test("greater_than value outstanding", {&Outstand.greater_than/2, %Duration{hour: 2}}, %Duration{hour: 1}) gen_something_outstanding_test("greater_than value outstanding, equal", {&Outstand.greater_than/2, %Duration{hour: 2}}, %Duration{hour: 2}) gen_nothing_outstanding_test("greater_than value realized", {&Outstand.greater_than/2, %Duration{hour: 2}}, %Duration{minute: 121}) - gen_result_outstanding_test("greater_than value result", {&Outstand.greater_than/2, %Duration{hour: 2}}, %Duration{hour: 2}, :greater_than) - gen_result_outstanding_test("greater_than value result, equal", {&Outstand.greater_than/2, %Duration{hour: 2}}, %Duration{hour: 2}, :greater_than) - - gen_something_outstanding_test("bounded_by value outstanding, low", {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 30}) - gen_something_outstanding_test("bounded_by value outstanding, high", {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{hour: 2}) - gen_nothing_outstanding_test("bounded_by value realized", {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 70}) - gen_nothing_outstanding_test("bounded_by value realized, lower_bound", {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 60}) - gen_nothing_outstanding_test("bounded_by value realized, upper_bound", {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 90}) - gen_result_outstanding_test("bounded_by value result, low", {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 30}, :bounded_by) - gen_result_outstanding_test("bounded_by value result, high", {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{hour: 2}, :bounded_by) - - gen_something_outstanding_test("unbounded_by value outstanding", {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 70}) - gen_something_outstanding_test("unbounded_by value outstanding, lower bound", {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 60}) - gen_something_outstanding_test("unbounded_by value outstanding, high bound", {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 90}) - gen_nothing_outstanding_test("unbounded_by value realized, low", {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 30}) - gen_nothing_outstanding_test("unbounded_by value realized, high", {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 100}) - gen_result_outstanding_test("unbounded_by value result", {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 70}, :unbounded_by) - gen_result_outstanding_test("unbounded_by value result, lower bound", {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 60}, :unbounded_by) - gen_result_outstanding_test("unbounded_by value result, high bound", {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, %Duration{minute: 90}, :unbounded_by) + + gen_result_outstanding_test( + "greater_than value result", + {&Outstand.greater_than/2, %Duration{hour: 2}}, + %Duration{hour: 2}, + :greater_than + ) + + gen_result_outstanding_test( + "greater_than value result, equal", + {&Outstand.greater_than/2, %Duration{hour: 2}}, + %Duration{hour: 2}, + :greater_than + ) + + gen_something_outstanding_test( + "bounded_by value outstanding, low", + {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 30} + ) + + gen_something_outstanding_test( + "bounded_by value outstanding, high", + {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{hour: 2} + ) + + gen_nothing_outstanding_test( + "bounded_by value realized", + {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 70} + ) + + gen_nothing_outstanding_test( + "bounded_by value realized, lower_bound", + {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 60} + ) + + gen_nothing_outstanding_test( + "bounded_by value realized, upper_bound", + {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 90} + ) + + gen_result_outstanding_test( + "bounded_by value result, low", + {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 30}, + :bounded_by + ) + + gen_result_outstanding_test( + "bounded_by value result, high", + {&Outstand.bounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{hour: 2}, + :bounded_by + ) + + gen_something_outstanding_test( + "unbounded_by value outstanding", + {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 70} + ) + + gen_something_outstanding_test( + "unbounded_by value outstanding, lower bound", + {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 60} + ) + + gen_something_outstanding_test( + "unbounded_by value outstanding, high bound", + {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 90} + ) + + gen_nothing_outstanding_test( + "unbounded_by value realized, low", + {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 30} + ) + + gen_nothing_outstanding_test( + "unbounded_by value realized, high", + {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 100} + ) + + gen_result_outstanding_test( + "unbounded_by value result", + {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 70}, + :unbounded_by + ) + + gen_result_outstanding_test( + "unbounded_by value result, lower bound", + {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 60}, + :unbounded_by + ) + + gen_result_outstanding_test( + "unbounded_by value result, high bound", + {&Outstand.unbounded_by/2, [%Duration{hour: 1}, %Duration{minute: 90}]}, + %Duration{minute: 90}, + :unbounded_by + ) end diff --git a/test/keyword_of_map_test.exs b/test/keyword_of_map_test.exs index b860dc8..35bdb31 100644 --- a/test/keyword_of_map_test.exs +++ b/test/keyword_of_map_test.exs @@ -2,15 +2,25 @@ defmodule Outstanding.KeywordOfMapTest do use ExUnit.Case use Outstand - gen_something_outstanding_test("key outstanding", [x: %{a: "a"}, y: %{b: "b"}], [x: %{a: "a"}, z: %{b: "b"}]) - gen_something_outstanding_test("value outstanding", [x: %{a: "a"}, y: %{b: "b"}], [x: %{b: "b"}, y: %{b: "b"}]) - gen_something_outstanding_test("nil value outstanding", [x: &Outstand.explicit_nil/1, y: %{b: "b"}], [x: %{b: "b"}, y: %{b: "b"}]) - gen_something_outstanding_test("falsy value outstanding", [x: false, y: %{b: "b"}], [x: %{b: "b"}, y: %{b: "b"}]) - gen_nothing_outstanding_test("realized", [x: %{a: "a"}, y: %{b: "b"}], [x: %{a: "a"}, y: %{b: "b"}]) - gen_nothing_outstanding_test("realized with extra item", [x: %{a: "a"}, y: %{b: "b"}], [x: %{a: "a"}, y: %{b: "b"}, z: %{b: "b"}]) - gen_nothing_outstanding_test("realized with extra item in child map", [x: %{a: "a"}, y: %{b: "b"}], [x: %{a: "a"}, y: %{b: "b"}, z: %{b: "b", c: "c"}]) - gen_result_outstanding_test("key result", [x: %{a: "a"}, y: %{b: "b"}], [x: %{a: "a"}, z: %{b: "b"}], [y: %{b: "b"}]) - gen_result_outstanding_test("value result", [x: %{a: "a"}, y: %{b: "b"}], [x: %{b: "b"}, y: %{b: "b"}], [x: %{a: "a"}]) - gen_result_outstanding_test("nil value result", [x: &Outstand.explicit_nil/1, y: %{b: "b"}], [x: %{b: "b"}, y: %{b: "b"}], [x: :explicit_nil]) - gen_result_outstanding_test("falsy value result", [x: false, y: %{b: "b"}], [x: %{b: "b"}, y: %{b: "b"}], [x: false]) + gen_something_outstanding_test("key outstanding", [x: %{a: "a"}, y: %{b: "b"}], x: %{a: "a"}, z: %{b: "b"}) + gen_something_outstanding_test("value outstanding", [x: %{a: "a"}, y: %{b: "b"}], x: %{b: "b"}, y: %{b: "b"}) + gen_something_outstanding_test("nil value outstanding", [x: &Outstand.explicit_nil/1, y: %{b: "b"}], x: %{b: "b"}, y: %{b: "b"}) + gen_something_outstanding_test("falsy value outstanding", [x: false, y: %{b: "b"}], x: %{b: "b"}, y: %{b: "b"}) + gen_nothing_outstanding_test("realized", [x: %{a: "a"}, y: %{b: "b"}], x: %{a: "a"}, y: %{b: "b"}) + gen_nothing_outstanding_test("realized with extra item", [x: %{a: "a"}, y: %{b: "b"}], x: %{a: "a"}, y: %{b: "b"}, z: %{b: "b"}) + + gen_nothing_outstanding_test("realized with extra item in child map", [x: %{a: "a"}, y: %{b: "b"}], + x: %{a: "a"}, + y: %{b: "b"}, + z: %{b: "b", c: "c"} + ) + + gen_result_outstanding_test("key result", [x: %{a: "a"}, y: %{b: "b"}], [x: %{a: "a"}, z: %{b: "b"}], y: %{b: "b"}) + gen_result_outstanding_test("value result", [x: %{a: "a"}, y: %{b: "b"}], [x: %{b: "b"}, y: %{b: "b"}], x: %{a: "a"}) + + gen_result_outstanding_test("nil value result", [x: &Outstand.explicit_nil/1, y: %{b: "b"}], [x: %{b: "b"}, y: %{b: "b"}], + x: :explicit_nil + ) + + gen_result_outstanding_test("falsy value result", [x: false, y: %{b: "b"}], [x: %{b: "b"}, y: %{b: "b"}], x: false) end diff --git a/test/keyword_test.exs b/test/keyword_test.exs index 7ab3c66..40bc3f1 100644 --- a/test/keyword_test.exs +++ b/test/keyword_test.exs @@ -2,19 +2,19 @@ defmodule Outstanding.KeywordTest do use ExUnit.Case use Outstand - gen_something_outstanding_test("key outstanding", [a: :a, b: :b], [a: :a, c: :c]) - gen_something_outstanding_test("value outstanding", [a: :a, b: :b], [a: :a, b: :a]) - gen_something_outstanding_test("explicit nil value outstanding", [a: &Outstand.explicit_nil/1, b: :b], [a: :a, b: :b]) - gen_something_outstanding_test("falsy value outstanding", [a: false, b: :b], [a: :a, b: :b]) - gen_something_outstanding_test("no value outstanding", [a: :no_value, b: :b], [a: :a, b: :b]) - gen_nothing_outstanding_test("realized", [a: :a, b: :b], [a: :a, b: :b]) - gen_nothing_outstanding_test("nil realized, any value", [a: nil, b: :b], [a: :a, b: :b]) - gen_nothing_outstanding_test("nil realized, nil value", [a: nil, b: :b], [a: nil, b: :b]) - gen_nothing_outstanding_test("no value realized, nil value", [a: :no_value, b: :b], [a: nil, b: :b]) - gen_nothing_outstanding_test("no value realized, no key", [a: :no_value, b: :b], [b: :b]) - gen_result_outstanding_test("key result", [a: :a, b: :b], [a: :a, c: :c], [b: :b]) - gen_result_outstanding_test("value result", [a: :a, b: :b], [a: :a, b: :a], [b: :b]) - gen_result_outstanding_test("explicit nil value result", [a: &Outstand.explicit_nil/1, b: :b], [a: :a, b: :b], [a: :explicit_nil]) - gen_result_outstanding_test("falsy value result", [a: false, b: :b], [a: :a, b: :b], [a: false]) - gen_result_outstanding_test("no value result", [a: :no_value, b: :b], [a: :a, b: :b], [a: :no_value]) + gen_something_outstanding_test("key outstanding", [a: :a, b: :b], a: :a, c: :c) + gen_something_outstanding_test("value outstanding", [a: :a, b: :b], a: :a, b: :a) + gen_something_outstanding_test("explicit nil value outstanding", [a: &Outstand.explicit_nil/1, b: :b], a: :a, b: :b) + gen_something_outstanding_test("falsy value outstanding", [a: false, b: :b], a: :a, b: :b) + gen_something_outstanding_test("no value outstanding", [a: :no_value, b: :b], a: :a, b: :b) + gen_nothing_outstanding_test("realized", [a: :a, b: :b], a: :a, b: :b) + gen_nothing_outstanding_test("nil realized, any value", [a: nil, b: :b], a: :a, b: :b) + gen_nothing_outstanding_test("nil realized, nil value", [a: nil, b: :b], a: nil, b: :b) + gen_nothing_outstanding_test("no value realized, nil value", [a: :no_value, b: :b], a: nil, b: :b) + gen_nothing_outstanding_test("no value realized, no key", [a: :no_value, b: :b], b: :b) + gen_result_outstanding_test("key result", [a: :a, b: :b], [a: :a, c: :c], b: :b) + gen_result_outstanding_test("value result", [a: :a, b: :b], [a: :a, b: :a], b: :b) + gen_result_outstanding_test("explicit nil value result", [a: &Outstand.explicit_nil/1, b: :b], [a: :a, b: :b], a: :explicit_nil) + gen_result_outstanding_test("falsy value result", [a: false, b: :b], [a: :a, b: :b], a: false) + gen_result_outstanding_test("no value result", [a: :no_value, b: :b], [a: :a, b: :b], a: :no_value) end diff --git a/test/list_test.exs b/test/list_test.exs index 03b52bb..95cd050 100644 --- a/test/list_test.exs +++ b/test/list_test.exs @@ -2,7 +2,6 @@ defmodule Outstanding.ListTest do use ExUnit.Case use Outstand - gen_something_outstanding_test("element outstanding", [:a, :b], [:b, :c]) gen_something_outstanding_test("order outstanding", [:a, :b], [:b, :a]) gen_something_outstanding_test("empty outstanding", [], [:a]) diff --git a/test/map_of_map_test.exs b/test/map_of_map_test.exs index 3843857..9f70fd8 100644 --- a/test/map_of_map_test.exs +++ b/test/map_of_map_test.exs @@ -6,7 +6,9 @@ defmodule Outstanding.MapOfMapTest do gen_something_outstanding_test("value outstanding", %{x: %{a: "a"}, y: %{b: "b"}}, %{x: %{b: "b"}, y: %{b: "b"}}) gen_nothing_outstanding_test("realized", %{x: %{a: "a"}, y: %{b: "b"}}, %{x: %{a: "a"}, y: %{b: "b"}}) gen_nothing_outstanding_test("realized with extra item", %{x: %{a: "a"}, y: %{b: "b"}}, %{x: %{a: "a"}, y: %{b: "b"}, z: %{b: "b"}}) + gen_nothing_outstanding_test("realized with extra item in child map", %{x: %{a: "a"}, y: %{b: "b"}}, %{x: %{a: "a"}, y: %{b: "b", c: "c"}}) + gen_result_outstanding_test("key result", %{x: %{a: "a"}, y: %{b: "b"}}, %{x: %{a: "a"}, z: %{b: "b"}}, %{y: %{b: "b"}}) - gen_result_outstanding_test("value result", %{x: %{a: "a"}, y: %{b: "b"}}, %{x: %{b: "b"}, y: %{b: "b"}}, %{x: %{a: "a"}}) + gen_result_outstanding_test("value result", %{x: %{a: "a"}, y: %{b: "b"}}, %{x: %{b: "b"}, y: %{b: "b"}}, %{x: %{a: "a"}}) end diff --git a/test/map_test.exs b/test/map_test.exs index c01c668..7892a0f 100644 --- a/test/map_test.exs +++ b/test/map_test.exs @@ -5,17 +5,30 @@ 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 explicit nil value outstanding, no value", %{x: :a, y: &Outstand.explicit_nil/1}, %{x: :a, z: :b}) - gen_something_outstanding_test("key explicit nil value outstanding, not nil", %{x: :a, y: &Outstand.explicit_nil/1}, %{x: :a, y: :c, z: :b}) - gen_something_outstanding_test("value falsy outstanding", %{x: false, y: :b}, %{x: :b, y: :b}) - gen_something_outstanding_test("no value outstanding", %{x: :no_value, y: :b}, %{x: :b, y: :b}) + + gen_something_outstanding_test("key explicit nil value outstanding, not nil", %{x: :a, y: &Outstand.explicit_nil/1}, %{ + x: :a, + y: :c, + z: :b + }) + + gen_something_outstanding_test("value falsy outstanding", %{x: false, y: :b}, %{x: :b, y: :b}) + gen_something_outstanding_test("no value outstanding", %{x: :no_value, 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_nothing_outstanding_test("no value realized, nil value", %{x: :no_value, y: :b}, %{x: nil, y: :b}) gen_nothing_outstanding_test("no value realized, no key", %{x: :no_value, y: :b}, %{y: :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("key explicit nil result, no value", %{x: :a, y: &Outstand.explicit_nil/1}, %{x: :a, z: :b}, %{y: :explicit_nil}) - gen_result_outstanding_test("key explicit nil result, not nil", %{x: :a, y: &Outstand.explicit_nil/1}, %{x: :a, y: :c, z: :b}, %{y: :explicit_nil}) + + gen_result_outstanding_test("key explicit nil result, no value", %{x: :a, y: &Outstand.explicit_nil/1}, %{x: :a, z: :b}, %{ + y: :explicit_nil + }) + + gen_result_outstanding_test("key explicit nil result, not nil", %{x: :a, y: &Outstand.explicit_nil/1}, %{x: :a, y: :c, z: :b}, %{ + y: :explicit_nil + }) + gen_result_outstanding_test("value falsy result", %{x: false, y: :b}, %{x: :b, y: :b}, %{x: false}) - gen_result_outstanding_test("no value result", %{x: :no_value, y: :b}, %{x: :b, y: :b}, %{x: :no_value}) + gen_result_outstanding_test("no value result", %{x: :no_value, y: :b}, %{x: :b, y: :b}, %{x: :no_value}) end diff --git a/test/naive_date_time_test.exs b/test/naive_date_time_test.exs index 341f457..571288f 100644 --- a/test/naive_date_time_test.exs +++ b/test/naive_date_time_test.exs @@ -3,7 +3,7 @@ defmodule Outstanding.NaiveDateTimeTest do use Outstand @now DateTime.utc_now() |> DateTime.to_naive() - @future DateTime.utc_now() |> DateTime.add(1, :day)|> DateTime.to_naive() + @future DateTime.utc_now() |> DateTime.add(1, :day) |> DateTime.to_naive() @past DateTime.utc_now() |> DateTime.add(-1, :day) |> DateTime.to_naive() gen_something_outstanding_test("value outstanding, future", @now, @future) diff --git a/test/struct_test.exs b/test/struct_test.exs index da8de5c..0b1020f 100644 --- a/test/struct_test.exs +++ b/test/struct_test.exs @@ -14,13 +14,16 @@ defmodule Outstanding.StructTest do case {expected, actual} do {nil, nil} -> nil + {_, ^expected} -> nil + {%name{}, %name{}} -> expected |> Map.from_struct() |> Outstanding.outstanding(Map.from_struct(actual)) |> Outstand.map_to_struct(name) + {_, _} -> # not an exact match so default to outstanding expected diff --git a/test/time_test.exs b/test/time_test.exs index f4aa13a..bc022a4 100644 --- a/test/time_test.exs +++ b/test/time_test.exs @@ -3,7 +3,7 @@ defmodule Outstanding.TimeTest do use Outstand @now DateTime.utc_now() |> DateTime.to_time() - @future DateTime.utc_now() |> DateTime.add(1, :hour)|> DateTime.to_time() + @future DateTime.utc_now() |> DateTime.add(1, :hour) |> DateTime.to_time() @past DateTime.utc_now() |> DateTime.add(-1, :hour) |> DateTime.to_time() gen_something_outstanding_test("value outstanding, future", @now, @future)