Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Actual Tests
# this will let warnings slip through but I don't wanna replicate all that magic
# right now
run: MIX_ENV=test mix coveralls.github || mix test --failed
run: MIX_ENV=test mix coveralls.github --warnings-as-errors || mix test --failed
# Apparently the one with `!` can't go without the fancy expression syntax
if: ${{ !matrix.lint }}
# warnings as errors is a form of linting!
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ You can check out [a benchmark and its results](https://github.com/PragTob/deep_

The TLDR; is this: In the sample it is about 30 times slower than `Map.merge/2` - however, less than twice as slow as calling `Map.merge/3` with simple overriding behaviour (same behaviour as `Map.merge/2`). This is because `Map.merge/2` is highly optimized, but we need to do much more than the `Map.merge/3` sample in the benchmark so I think it's a very passable result. We're still talking about a couple of μs.

## Development

The tests emit type warnings right now on elixir 1.20+.
These tests are actively exercising behavior with unmatching types, so... kinda expected.

## Considered feature-complete

Unless you come with great feature ideas of course ;) So if you come here and there are no recent commits, don't worry - there are no known bugs or whatever. It's a small little library that does its job.
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"credo": {:hex, :credo, "1.7.18", "5c5596bf7aedf9c8c227f13272ac499fe8eae6237bd326f2f07dfc173786f042", [: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", "a189d164685fd945809e862fe76a7420c4398fa288d76257662aecb909d6b3e5"},
"credo": {:hex, :credo, "1.7.19", "cc52129665fc7c15143d47838fda0f9cd6dac9ceced7bf4da6f85fcbfe64b12a", [: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", "2d8bc95d5a7bb99dd2613621d4f08c6a3575c3fd4b62e6a2b48a100352a557b8"},
"dialyxir": {:hex, :dialyxir, "1.4.7", "dda948fcee52962e4b6c5b4b16b2d8fa7d50d8645bbae8b8685c3f9ecb7f5f4d", [:mix], [{:erlex, ">= 0.2.8", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b34527202e6eb8cee198efec110996c25c5898f43a4094df157f8d28f27d9efe"},
"earmark": {:hex, :earmark, "1.4.46", "8c7287bd3137e99d26ae4643e5b7ef2129a260e3dcf41f251750cb4563c8fb81", [:mix], [], "hexpm", "798d86db3d79964e759ddc0c077d5eb254968ed426399fbf5a62de2b5ff8910a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
Expand Down
35 changes: 23 additions & 12 deletions test/deep_merge_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ defmodule DeepMergeTest do
doctest DeepMerge
import DeepMerge

# Elixir 1.20 introduced stricter type checking that emits warnings when
# intentionally incompatible types are passed, so we skip those tests there.
# Errors are omitted on compilation already, so we need to never compile them.
@skip_incompatible_type_tests Version.match?(System.version(), ">= 1.20.0")

test "with different keyword list & list combinations" do
assert deep_merge([a: [b: []], f: 5], a: [b: [c: 2]]) == [f: 5, a: [b: [c: 2]]]

Expand Down Expand Up @@ -87,11 +92,13 @@ defmodule DeepMergeTest do
assert deep_merge([b: 2], %{a: 1}) == %{a: 1}
end

test "errors out with incompatible types" do
assert_incompatible(fn -> deep_merge(%{a: 1}, 2) end)
assert_incompatible(fn -> deep_merge(2, %{b: 2}) end)
assert_incompatible(fn -> deep_merge(1, 2) end)
assert_incompatible(fn -> deep_merge(:atom, :other_atom) end)
if not @skip_incompatible_type_tests do
test "errors out with incompatible types" do
assert_incompatible(fn -> deep_merge(%{a: 1}, 2) end)
assert_incompatible(fn -> deep_merge(2, %{b: 2}) end)
assert_incompatible(fn -> deep_merge(1, 2) end)
assert_incompatible(fn -> deep_merge(:atom, :other_atom) end)
end
end
end

Expand Down Expand Up @@ -138,15 +145,19 @@ defmodule DeepMergeTest do
assert deep_merge([b: 2], %{a: 1}, number_adder()) == %{a: 1}
end

test "errors out with incompatible types" do
assert_incompatible(fn -> deep_merge(%{a: 1}, 2, number_adder()) end)
assert_incompatible(fn -> deep_merge(2, %{b: 2}, number_adder()) end)
assert_incompatible(fn -> deep_merge(1, 2, number_adder()) end)
assert_incompatible(fn -> deep_merge(:atom, :other_atom, number_adder()) end)
if not @skip_incompatible_type_tests do
test "errors out with incompatible types" do
assert_incompatible(fn -> deep_merge(%{a: 1}, 2, number_adder()) end)
assert_incompatible(fn -> deep_merge(2, %{b: 2}, number_adder()) end)
assert_incompatible(fn -> deep_merge(1, 2, number_adder()) end)
assert_incompatible(fn -> deep_merge(:atom, :other_atom, number_adder()) end)
end
end
end

defp assert_incompatible(function) do
assert_raise FunctionClauseError, function
if not @skip_incompatible_type_tests do
defp assert_incompatible(function) do
assert_raise FunctionClauseError, function
end
end
end
Loading